解决Ubuntu下PHP错误可按以下步骤操作:
查看错误信息
tail -f /var/log/apache2/error.log(Apache)或tail -f /var/log/nginx/error.log(Nginx)实时查看错误日志。ini_set('display_errors', 1); error_reporting(E_ALL);。分析常见错误类型
www-data),使用sudo chown -R www-data:www-data /path/to/project和sudo chmod -R 755 /path/to/project设置。php -m查看已安装扩展,缺失时用sudo apt-get install php-扩展名安装,如sudo apt-get install php-mysql。检查配置文件
php.ini路径:php --ini,检查error_log、display_errors等配置是否正确。/etc/apache2/mods-enabled/dir.conf,Nginx检查配置文件中的PHP模块加载。重启服务
sudo systemctl restart apache2sudo systemctl restart nginx和sudo systemctl restart php7.x-fpm(x为版本号)。进一步调试
error_log()函数记录详细错误信息。关键命令总结:
tail -f /var/log/apache2/error.log(Apache)或tail -f /var/log/nginx/error.log(Nginx)。sudo apt-get install php-扩展名。sudo systemctl restart apache2或sudo systemctl restart nginx。