一、环境说明
PHP7.2
tideways 4.1.5 适用于php7以上
xhgui 可视化web界面
mongodb 3.6.3 存储监控的数据, 版本无太大要求
ubuntu18.04 系统无要求, 只是在此系统安装成功
看搭建完成的效果请拖到最后
一般出现问题都是在composer下载和版本不匹配的问题
二、安装mongodb
1. 安装mongodb, 怎么安装都行, 只要能安装成功就行
sudo apt update && sudo apt upgrade -y sudo apt install mongodb
2. 安装mongodb扩展
wget http://pecl.php.net/get/mongodb-1.4.0.tgz tar -zxvf mongodb-1.4.0.tgz cd mongodb-1.4.0 phpize #php-config的路径如果环境变化已经存在, 可以不写此选项 ./configure --with-php-config=你的php-config路径 make make install
三、安装tideways扩展
wget --no-check-certificate https://github.com/tideways/php-xhprof-extension/archive/v4.1.7.tar.gz tar zxvf v4.1.7.tar.gz cd php-xhprof-extension-4.1.7 phpize ./configure make make install
四、修改php配置文件,增加扩展
extension=tideways.so tideways.auto_prepend_library=0 extension=mongodb.so
五、下载xhgui可视化工具
1. 克隆项目到本地并安装
git clone https://github.com/yiqiang3344/xhgui-branch.git cd xhgui php install.php
2. 配置xhgui, 配置文件在 config/default_config.php, 其中将extension改成和作者一样的配置
<?php /** * Default configuration for Xhgui */ return array( 'debug' => false, 'mode' => 'development', /* * support extension: uprofiler, tideways_xhprof, tideways, xhprof * default: xhprof */ 'extension' => 'tideways', // Can be either mongodb or file. /* 'save.handler' => 'file', 'save.handler.filename' => dirname(__DIR__) . '/cache/' . 'xhgui.data.' . microtime(true) . '_' . substr(md5($url), 0, 6), */ 'save.handler' => 'mongodb', // Needed for file save handler. Beware of file locking. You can adujst this file path // to reduce locking problems (eg uniqid, time ...) //'save.handler.filename' => __DIR__.'/../data/xhgui_'.date('Ymd').'.dat', 'db.host' => 'mongodb://127.0.0.1:27017', 'db.db' => 'xhprof',
六、使用和部署xhgui
因为是非侵入的, 所以不用修改项目的代码, 有两种使用方式, 一种是直接在nginx上配置,另外一种是直接在项目的最开始的部分引入一个文件即可
nginx配置xhgui
server { listen 9090; server_name _; root /home/xhgui-branch/webroot; index index.php index.html index.htm; # access_log /usr/local/var/log/nginx/access.log; #error_log /usr/local/var/log/nginx/error.log; location / { try_files $uri $uri/ /index.php$is_args$query_string; } location ~ \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 添加 PHP_VALUE,告诉 PHP 程序在执行前要调用的服务 fastcgi_param PHP_VALUE "auto_prepend_file=/path/wwwroot/xhgui-branch/external/header.php"; include fastcgi_params; } }
2. 在项目中引入
<?php //重点是这句, 在项目中引入 require '/home/xhgui-branch/external/header.php'; /** * Laravel - A PHP Framework For Web Artisans * * @package Laravel * @author Taylor Otwell <taylor@laravel.com> */ define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our application. We just need to utilize it! We'll simply require it | into the script here so that we don't have to worry about manual | loading any of our classes later on. It feels great to relax. | */ require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send "index.php" 59L, 1871C
六、部署成功的效果图