Debian 上 Apache 报错的原因非常多,不能一概而论,需要看具体的错误信息和场景。下面我按最常见的情况给你一个系统性的排查清单,你可以对照看看属于哪一种。
sudo systemctl status apache2
sudo journalctl -u apache2
sudo tail -n 50 /var/log/apache2/error.log
Address already in usePermission deniedCould not open configuration fileAH00558Failed to start The Apache HTTP Server错误示例
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
原因
解决
sudo netstat -tulpn | grep ':80'
关掉占用程序或改端口:
sudo nano /etc/apache2/ports.conf
错误示例
AH00526: Syntax error on line XX of /etc/apache2/sites-enabled/xxx.conf
解决
sudo apache2ctl configtest
根据提示修配置文件。
错误示例
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
解决
sudo a2enmod rewrite
sudo systemctl restart apache2
错误示例
(13)Permission denied: access to / denied
原因
/var/www 权限不对解决
sudo chown -R www-data:www-data /var/www
sudo chmod -R 755 /var/www
sudo a2dissite xxx
sudo a2dismod xxx
php module not found500 Internal Server Error解决
sudo apt install libapache2-mod-php
sudo a2enmod php
sudo systemctl restart apache2
你可以依次执行:
sudo apache2ctl configtest
sudo systemctl restart apache2
sudo tail -n 20 /var/log/apache2/error.log
你可以把完整报错信息贴出来,例如:
systemctl status apache2 输出/var/log/apache2/error.log 报错我可以直接告诉你是哪一步错了、怎么修。