在 Debian 上调试 LAMP(Linux + Apache + MySQL/MariaDB + PHP)环境,通常要分层排查:系统 → Apache → PHP → 数据库 → 应用代码。下面给你一套实用调试思路。
systemctl status apache2
systemctl status mariadb # 或 mysql
启动/重启:
sudo systemctl restart apache2
sudo systemctl restart mariadb
sudo ufw status
确保 80 / 443 开放:
sudo ufw allow 80
sudo ufw allow 443
tail -f /var/log/apache2/error.log
访问页面时观察是否有:
ls /etc/apache2/sites-enabled/
测试配置:
apache2ctl configtest
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
a2enmod php8.2 # 根据实际版本
systemctl restart apache2
php -v
测试 PHP 是否生效(在 /var/www/html 下):
<?php phpinfo(); ?>
访问 http://服务器IP/info.php
编辑:
sudo nano /etc/php/8.2/apache2/php.ini
确保:
display_errors = On
error_reporting = E_ALL
log_errors = On
重启 Apache:
sudo systemctl restart apache2
tail -f /var/log/apache2/error.log
mysql -u root -p
若失败:
sudo mysql
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost';
FLUSH PRIVILEGES;
常见原因:
sudo apt install php-mysql
sudo systemctl restart apache2
如 WordPress / Laravel / 自建 PHP:
.env如果你愿意,可以告诉我:
我可以帮你精确定位问题。