在Ubuntu系统中,配置PHP-FPM错误页面需要编辑相应的配置文件。以下是配置PHP-FPM错误页面的步骤:
/etc/php/{版本号}/fpm/pool.d/www.conf
。例如,如果你使用的是PHP 7.4,那么文件路径应该是/etc/php/7.4/fpm/pool.d/www.conf
。使用文本编辑器打开该文件,如nano
或vim
:sudo nano /etc/php/7.4/fpm/pool.d/www.conf
www.conf
文件中,找到以下两行:catch_workers_output = yes
php_value[error_log] = /var/log/php-fpm/www-error.log
确保catch_workers_output
设置为yes
,这样PHP-FPM会将错误信息捕获到指定的日志文件中。同时,检查php_value[error_log]
设置,确保错误日志文件的路径正确。
/var/www/html
目录下创建一个名为error.html
的文件:sudo nano /var/www/html/error.html
在error.html
文件中,添加你想要显示的自定义错误信息。例如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error</title>
</head>
<body>
<h1>Oops! Something went wrong.</h1>
<p>We apologize for the inconvenience, but an error has occurred on our website.</p>
</body>
</html>
保存并关闭error.html
文件。
重启PHP-FPM服务以应用更改:
sudo systemctl restart php{版本号}-fpm
将{版本号}
替换为你的PHP版本。例如,对于PHP 7.4,命令应该是:
sudo systemctl restart php7.4-fpm
现在,当你的应用程序遇到错误时,将会显示你在error.html
文件中定义的自定义错误页面。