First on the renderings:
Installation Environment
Centos、php7、MongoDB3、nginx
php extension
mongodb:http://pecl.php.net/package/mongodb
tideways_xhprof:https://github.com/tideways/php-xhprof-extension
Install MongoDB3
By default, my environment yum installed MongoDB2 version, xhgui requires version 3 and above.
Create MongoDB3 yum source
vim /etc/yum.repos.d/mongodb-org-3.4.repo
The content of the file is:
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
installation
yum install -y mongodb-org
Bad network time may be slightly longer
Start MongoDB
service mongod start
Increase index
$ mongo
> use xhprof
> db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
> db.results.ensureIndex( { 'profile.main().wt' : -1 } )
> db.results.ensureIndex( { 'profile.main().mu' : -1 } )
> db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
> db.results.ensureIndex( { 'meta.url' : 1 } )
If you need to adjust the default port or permissions and other information to search.
Install xgui Chinese version project
project address:
https://github.com/laynefyc/xhgui-branch
Download project code
git clone https://github.com/laynefyc/xhgui-branch.git
composer installation
cd xhgui-branch
composer install
Directory permissions
chmod -R 777 cache
nginx configuration
Configure the virtual host for the xhgui project, the following is my configuration, for reference only:
server {
listen 80;
server_name php.monitor.com;
root /your/project/path/xhgui-branch/webroot;
index index.html index.php;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log /log/path/php_monitor-access.log access;
error_log /log/path/php_monitor-error.log error;
}
Edit configuration file
vim /your/project/path/xhgui-branch/config/config.default.php
Adjust the following points:
...
'extension' => 'tideways_xhprof',
...
'profiler.enable' => function() {
if($_SERVER['SERVER_NAME'] == 'your.project.domain.com'){
// 100%采样,默认为1%
return rand(1, 100) === 42;
}else{
return False;
}
},
...
Fill in the mongodb connection information according to your own situation.
Configure items to be monitored
Adjust the nginx configuration of the monitoring project and add the following configuration:
fastcgi_param PHP_VALUE "auto_prepend_file=/your/project/path/xhgui-branch/external/header.php";
Restart nginx
nginx -s reload
During the initial visit, there may be no data due to the sampling frequency. You can temporarily increase the sampling frequency.