Debian 上搭建的 LAMP(Linux + Apache + MySQL/MariaDB + PHP) 出现卡顿,通常不是单一原因,而是多个环节叠加。下面按最常见 → 较少见给你系统排查思路。
默认配置是为小内存机器设计的,稍有点并发就卡。
表现:
检查:
htop
free -h
常见优化(示例,2G 内存):
# /etc/mysql/mariadb.conf.d/50-server.cnf
innodb_buffer_pool_size = 512M
max_connections = 100
query_cache_size = 0
改完重启:
systemctl restart mariadb
Debian 默认 Apache + mod_php 很容易卡。
问题:
解决(推荐): ✅ 改成 Apache + php-fpm
apt install php-fpm
a2dismod phpX.Y
a2enmod proxy_fcgi setenvif
a2enconf phpX.Y-fpm
systemctl restart apache2
Debian 小内存机器非常常见。
检查:
free -h
swapon --show
现象:
解决:
建议:
apt install php-opcache
df -h
Apache / MySQL 日志可能很大。
du -sh /var/log/*
尤其是:
iotop
netstat -ant | wc -l
或看 Apache 访问日志:
tail -f /var/log/apache2/access.log
htop
free -h
df -h
iotop
mysqladmin status
apachectl -M | grep php
你可以直接贴:
我可以直接给你一份可执行的优化方案。