96SEO 2025-10-31 16:06 0
保持系统和PHP为最新版本是平安基础,可及时修复已知漏洞。施行以下命令更新系统及PHP:

sudo apt update && sudo apt upgrade -y
sudo apt install php php-cli php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip -y通过修改php.ini文件调整关键参数,降低平安风险。
disable_functions = eval,exec,passthru,shell_exec,system,curl_exec,parse_ini_file,show_sourceupload_max_filesize = 2M
post_max_size = 8M
file_uploads = Onopen_basedir = /var/www/html/:/tmp/_secure = On
Cookie_httponly = On
Cookie_samesite = Strict
_maxlifetime = 1440确保系统和所有软件包都是最新的,以防止已知的漏洞。
ServerTokens Prod
ServerSignature Offsudo a2enmod security2
sudo a2enmod evasive2
sudo systemctl restart apache2通过Let’s Encrypt获取免费SSL证书,启用HTTPS:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d确保Web目录及文件权限合理,避免未授权访问:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
sudo find /var/www/html -type f -exec chmod 644 {} \;OPcache可缓存编译后的PHP脚本,减少服务器负载,一边降低源代码泄露风险。在中启用:
zend_extension=opcache.so
opcache_consumption=128
opcache_strings_buffer=8
opcache_accelerated_files=4000
opcache_freq=60先说说你需要编辑PHP的配置文件php.ini。
使用工具扫描代码漏洞, 监控访问日志与错误日志,及时发现异常行为。
通过以上步骤, 你可以有效地设置Ubuntu下的PHP平安配置,提高网站的平安性。请定期检查和更新配置,以确保网站的平安。
Demand feedback