在 Debian 上搭建的 LAMP(Linux + Apache + MySQL/MariaDB + PHP)环境,如果感觉慢,可以从系统层、Apache、PHP、数据库、缓存几个方向来提速。下面给你一套实用、可落地的优化方案。
apt update && apt upgrade -y
确保系统补丁和驱动是最新的。
systemctl list-unit-files --type=service | grep enabled
关闭用不到的服务(如 postfix、cups 等)。
如果是云服务器或虚拟机,尽量使用 SSD 磁盘。
查看当前 MPM:
apache2ctl -V | grep MPM
推荐:
preforkevent(推荐)启用 event:
a2dismod mpm_prefork
a2enmod mpm_event
systemctl restart apache2
编辑:
/etc/apache2/mods-enabled/mpm_event.conf
示例(2G–4G 内存):
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
</IfModule>
/etc/apache2/apache2.conf
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
a2dismod status autoindex cgi
减少内存占用。
apt install php-fpm
a2enmod proxy_fcgi setenvif
a2enconf php-fpm
systemctl restart apache2
编辑:
/etc/php/*/fpm/php.ini
关键参数:
memory_limit = 128M
max_execution_time = 30
opcache.enable=1
apt install php-opcache
php.ini:
opcache.enable=1
opcache.memory_consumption=128
opcache.revalidate_freq=60
apt install mariadb-server
编辑:
/etc/mysql/mariadb.conf.d/50-server.cnf
示例(2G 内存):
innodb_buffer_pool_size = 512M
innodb_log_file_size = 64M
query_cache_type = 1
query_cache_size = 32M
重启:
systemctl restart mariadb
SHOW PROCESSLIST;
或用 mysqldumpslow。
WP Super Cache / W3 Total Cacheapt install redis-server
PHP:
apt install php-redis
a2enmod deflate
如果你愿意,可以告诉我:
我可以给你一套精准配置文件。