在 CentOS 的 LAMP 环境(Linux + Apache + MySQL/MariaDB + PHP)中,查看日志主要集中在 Apache、MySQL/MariaDB、PHP 以及 系统日志。下面给你一份常用、实用的查看方法。
/var/log/httpd/access_log # 访问日志
/var/log/httpd/error_log # 错误日志
如果是编译安装,路径可能不同,可在 Apache 配置中查看:
grep -i "log" /etc/httpd/conf/httpd.conf
tail -f /var/log/httpd/error_log
tail -n 100 /var/log/httpd/access_log
grep "500" /var/log/httpd/error_log
mysql -u root -p -e "SHOW VARIABLES LIKE 'log_error';"
常见路径:
/var/log/mysqld.log
/var/log/mariadb/mariadb.log
tail -f /var/log/mysqld.log
SET GLOBAL slow_query_log = 'ON';
SHOW VARIABLES LIKE 'slow_query_log_file';
php -i | grep error_log
或查看 php.ini:
grep error_log /etc/php.ini
/var/log/php-fpm/error.log
/var/log/php_errors.log
tail -f /var/log/php-fpm/error.log
journalctl -xe
查看 Apache:
journalctl -u httpd
查看 MySQL:
journalctl -u mysqld
/var/log/messages
/var/log/secure
# 实时看 Apache 错误
tail -f /var/log/httpd/error_log
# 实时看 PHP 错误
tail -f /var/log/php-fpm/error.log
# 看系统级别报错
journalctl -xe
| 问题现象 | 优先看 |
|---|---|
| 网站 500 | Apache error_log + PHP 日志 |
| 网站打不开 | httpd 是否运行 + error_log |
| 数据库连不上 | mysqld.log |
| 权限问题 | error_log + /var/log/messages |
如果你愿意,可以告诉我:
我可以给你更精确的日志查看和排查命令。