在Ubuntu系统中使用PHP时,确保网站的安全性至关重要。以下是一些关键步骤和最佳实践,可以帮助你提高PHP应用程序的安全性:
sudo apt update && sudo apt upgrade
display_errors = Off
log_errors = On
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_WARNING
error_log = /var/log/php_errors.log
disable_functions = eval, exec, system, passthru, shell_exec, popen, curl, fsockopen, file_get_contents, mkdir, rmdir, rename, unlink, chmod, chown, chgrp, date, time, localtime, gmtime, isset, empty, is_array, is_object, is_resource, is_string, is_int, is_float, is_bool, is_callable, assert
location /(uploads)/.*\.(php|php5|jsp)$ {
deny all;
}
open_basedir
,限制PHP脚本只能访问特定目录。open_basedir = /var/www/html:/tmp
safe_mode = Off
Options -Indexes
ServerTokens Prod
ServerSignature Off
sudo chown -R www-data:www-data /path/to/your/php/project
sudo chmod -R 755 /path/to/your/php/project
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
sudo apt update
sudo apt upgrade php*
通过上述措施,可以显著提高Ubuntu系统中PHP应用的安全性,减少潜在的安全风险。[1,2,4,5,6,7,8,9,10,11,12,13,14,15]