Ruby:simpleCov
PHP:xdebug
由于我是单独安装的apache2,之前并未考虑与PHP组成LAMP( Linux, Apache, MySQL, PHP),所以遇到一个坑就是:PHP Fatal error: Uncaught Error: Call to undefined function xdebug_start_code_coverage()
比如我有index.php
<?php
var_dump(xdebug_code_coverage_started());
xdebug_start_code_coverage();
var_dump(xdebug_code_coverage_started());
?>
- 命令行里一切正常:
$ php index.php
Cannot load Xdebug - it was already loaded
Cannot load Xdebug - it was already loaded
/var/www/html/PHPCodeCoverage/PHPCodeCoverage-master/test.php:2:
bool(false)
/var/www/html/PHPCodeCoverage/PHPCodeCoverage-master/test.php:6:
bool(true)
可以看到这个index.php运行正常
-
http访问就会报错
但是我要是通过apache,http访问index.php,就会出现PHP Fatal error: Uncaught Error: Call to undefined function xdebug_start_code_coverage()
通过apache日志/var/log/apache2/error.log,
image.png
怎么解决呢?
我们要注意,有两个php.ini,这里[https://askubuntu.com/questions/356968/find-the-correct-php-ini-file]
- /etc/php/7.4/cli/php.ini
-
/etc/php/7.4/apache2/php.ini
如果没有/etc/php/7.4/apache2/php.ini,我们需要执行
sudo apt install php libapache2-mod-php php-mysql
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04
然后们就会发现/etc/php/7.4/就会多出一个apache2文件夹,然后修改php.ini里的xdebug配置,与/etc/php/7.4/cli/php.ini一致
网友评论