在Debian系统下进行PHP安全设置,可以参考以下步骤和建议:
sudo apt update && sudo apt upgrade
display_errors = Off
expose_php = Off
register_globals = Off
open_basedir
:open_basedir = /var/www
allow_url_fopen = Off
allow_url_include = Off
wget http://download.suhosin.org/suhosin-0.9.37.1.tar.gz
tar zxvf suhosin-0.9.37.1.tar.gz
cd suhosin-0.9.37.1
phpize
./configure --with-php-config=/usr/local/bin/php-config
make
make install
在php.ini
中添加:extension=suhosin.so
cp /etc/php/8.2/fpm/pool.d/www.conf{,_bak}
sed -i 's/^listen = .*/listen = 0.0.0.0:9000/' /etc/php/8.2/fpm/pool.d/www.conf
sudo systemctl restart php8.2-fpm.service
ufw
或iptables
限制入站和出站流量,仅允许必要的端口(如HTTP、HTTPS和SSH):sudo ufw enable
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 22/tcp
sudo ufw reload
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart sshd
Logwatch
或Fail2ban
自动监控并报告系统活动。通过上述步骤,可以显著提高Debian系统下PHP应用的安全性。建议定期审查和更新安全设置,以应对不断变化的安全威胁。