温馨提示×

centos lamp怎么查日志

小樊
40
2026-09-15 09:56:06
栏目: 智能运维

CentOS + LAMP(Linux + Apache + MySQL/MariaDB + PHP) 环境下,常见日志位置和查看方式如下:


一、Apache 日志

1. 默认日志路径(CentOS 常用)

/var/log/httpd/

常见文件:

  • 访问日志:access_log
  • 错误日志:error_log

2. 查看方式

# 实时查看错误日志
tail -f /var/log/httpd/error_log

# 查看最近 100 行
tail -n 100 /var/log/httpd/error_log

# 搜索关键字
grep "error" /var/log/httpd/error_log

二、PHP 日志

1. 查看 PHP 错误日志位置

php --ini

php -i | grep error_log

常见路径:

/var/log/php-fpm/error.log
/var/log/php_errors.log

2. 若使用 PHP-FPM

tail -f /var/log/php-fpm/error.log

三、MySQL / MariaDB 日志

1. 错误日志

/var/log/mysqld.log
# 或
/var/log/mariadb/mariadb.log

查看:

tail -f /var/log/mysqld.log

2. 查看慢查询日志(若开启)

SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'slow_query_log_file';

四、系统日志(通用)

# 系统日志
tail -f /var/log/messages

# 使用 journalctl(CentOS 7+)
journalctl -u httpd
journalctl -u mariadb
journalctl -u php-fpm

五、常用排错命令总结

# 查看 Apache 是否报错
tail -f /var/log/httpd/error_log

# 查看 PHP 错误
tail -f /var/log/php-fpm/error.log

# 查看数据库错误
tail -f /var/log/mysqld.log

# 综合查看系统日志
journalctl -xe

如果你能说明 具体是哪种问题(网站打不开 / 500错误 / 数据库连接失败等),我可以帮你精准定位该看哪个日志。

0