guanguans.github.io
guanguans.github.io copied to clipboard
Docker 的 LNMP 一键安装开发环境与 PHP 非侵入式监控平台 xhgui 的安装使用
Docker 的 LNMP 一键安装开发环境与 PHP 非侵入式监控平台 xhgui 的安装使用
安装之前请确保安装了以下软件
- Docker
- Docker-compose
- Git
- Composer
安装 dnmp-plus
$ git clone https://github.com/guanguans/dnmp-plus.git --recursive
$ cd dnmp-plus
$ cp env.sample .env
$ cp docker-compose-sample.yml docker-compose.yml
$ docker-compose up

默认 web 根目录 www/localhost/
,浏览器访问 http://localhost
安装使用 xhgui
安装
$ cd www/xhgui-branch
$ composer install
修改 xhgui-branch 配置文件 www/xhgui-branch/config/config.default.php
<?php
return array(
...
'debug' => true, // 改为true,便于调试
'mode' => 'development',
...
'extension' => 'tideways', // 改为支持 PHP7 的 tideways
...
'save.handler' => 'mongodb',
'db.host' => 'mongodb://mongo:27017', // 127.0.0.1 改为 mongo
...
);
hosts 文件中增加
127.0.0.1 xhgui.test
浏览器访问 http://xhgui.test

安装一个 laravel 项目作为要性能追踪及分析的项目使用示例
$ cd www/
$ composer create-project laravel/laravel
$ ./artisan make:auth
配置 laravel 的 nginx 配置
$ cd conf/conf.d/
$ cp laravel.conf.sample laravel.conf
修改 laravel.conf 为
...
location ~ \.php$ {
fastcgi_pass php72:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 在执行主程序之前运行我们指定的PHP脚本
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhgui-branch/external/header.php";
}
...
hosts 文件中增加
127.0.0.1 laravel.test
重启 nginx
$ docker-compose restart nginx
浏览器访问 http://laravel.test, 再访问 http://xhgui.test,愉快的查看 laravel 项目的性能追踪及分析吧

能加一个php7.1 7.3吗
@SummerMagic 可以加的,我抽个时间加下。
@all-contributors please add @SummerMagic for ideas
[RuntimeException] Could not scan for classes inside "/home/vagrant/code/xhgui-branch/vendor/phpunit/phpunit/PHPUnit/" which does not appear to be a file nor a folder
这个好像是composer 有问题
@SummerMagic 更新下 composer 版本试试,运行 composer install --no-dev
试试。我这边测试是没问题的。
mongo提示No suitable servers found (serverSelectionTryOnce set): [connection timeout calling ismaster on 'mongo:27017'],重构完也没用 一直restarting
@ConserveLee
- 把 docker cpu、内存等值提高一些,重启 mongo 服务试试。
- 把 mongo 的镜像、容器、挂载目录、网络等都移除干净再次重新构建。可借助可视化工具移除,如vscode 的 docker 插件或者 kitematic。