在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
文件中定義的自定義錯誤頁面。