本案例环境如下:
CentOS Linux release 7.7.1908 (Core)
nginx version: nginx/1.17.5
PHP 7.2.7 (cli) (built: Oct 9 2018 15:09:36)
- nginx
安装前,新增用户组,用户,用于后续统一账户使用
groupadd www
useradd -g www www
在 CentOS 上,可直接使用 yum 来安装 Nginx
yum install nginx -y
扩展: 卸载用 yum remove nginx
查看安装位置
whereis nginx
Nginx 默认conf 与 web根目录:
vim /etc/nginx/nginx.conf
将user 修改为www

可以看到默认挂载了/etc/nginx/conf.d/*.conf;
下的其他conf文件------这个可以根据自己需要做调整,这里选择默认不做修改;

重载nginx配置:
nginx -t
nginx -s
启动nginx:
start nginx
浏览器访问:http://服务器IP/index.html

Tips:至此nginx启动成功
- php
- xdebug安装
查看php info信息:
php -i
打开网址:
https://xdebug.org/wizard
将php -i显示全部内容复制粘题至图示位置:

这里会显示安装信息:

按照提示若未installed,可按如下提示进行安装:

Tips:安装完成可将php -i信息重新检测。
- php-fpm配置
查看php-fpm安装位置:
whereis php-fpm
有可能搜不到,可按php默认安装位置去查看

修改下配置
vim /etc/php-fpm.d/www.conf
user = www
group = www
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660
启动fpm
systemctl start php-fpm
在nginx WEB路径下新建vim index.php
<?php
phpinfo();
?>
通过浏览器访问http://服务器IP/index.php显示php信息
Tips:至此可以正常通过nginx访问php文件。
3.phpcoverage配置
composer安装(php安装扩展使用)
wget https://getcomposer.org/composer.phar
chmod +x composer.phar
mv composer.phar /usr/local/bin/composer
下载:
https://github.com/lisijie/phpcoverage.git
cd phpcoverage
composer install
安装完后包含以下文件:

Tips:
此时需要修改nginx配置,使php项目访问时通过phpcoverage进行统计
修改nginx的server配置,增加fastcgi参数,为项目自动加载预处理文件。
fastcgi_param PHP_VALUE 'auto_prepend_file=你的文件路径/phpcoverage/prepend.php';
vim /etc/nginx/conf.d/default.conf
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE 'auto_prepend_file=/data/htdocs/php-test/www/phpcov erage/prepend.php';
include fastcgi_params;
}
nginx -t
nginx -s
nginx
这样再访问php项目时,phpcoverage目录data下会生成对应的.cov文件
生成HTML格式的详细报告(-vvv显示执行详情)
/phpcoverage/vendor/bin/phpcov merge --html="自定义位置/coverage_html" /data/htdocs/php-test/www/phpcoverage/data/ -vvv
至此生成对应的统计文件,即可浏览了

相关文档:
https://github.com/sebastianbergmann/phpcov
https://github.com/lisijie/phpcoverage
网友评论