首页 > 解决方案 > Apache+mod_php 太慢了

问题描述

我在使用 mod_php 设置 Apache 服务器时遇到问题。我有一个网站,其 index.php 页面在 ~200 毫秒内生成。但是 Apache 在大约 1.5 秒内提供它。为什么会出现这种放缓?

如果需要,我的/etc/apache2/ports.conf文件是:

Listen 80

<VirtualHost *:80>
    ServerName mysite.local
    ServerAlias www.mysite.local
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://localhost:9999/
    ProxyPassReverse / http://localhost:9999/
</VirtualHost>

我的文件/etc/apache2/sites-available/mysite.local.conf是:

Listen 9999
User max
Group max
<VirtualHost *:9999>
    ServerName 127.0.0.1:9999
    DocumentRoot /home/max/www/mysite.local/www/html/
    
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/max/www/mysite.local/www>
        Options FollowSymLinks
        AllowOverride All
        #Order allow,deny
        #Allow from all
        Require all granted
    </Directory>
        
    ErrorLog /home/max/www/mysite.local/logs/error.log
    LogLevel warn
    CustomLog /home/max/www/mysite.local/logs/access.log combined
</VirtualHost>

我的主要问题是为什么这么慢,如何让它更快?我已经测试过将 index.php 内容放入一个普通的 html 文件中,并且在大约 10 毫秒内提供服务。所以问题可能出在 mod_php 上?提前致谢。

标签: phpperformancevirtualhostapache2.4mod-php

解决方案


一个原因可能是 apache 在每个请求的根目录的每个目录中递归地检查 .htaccess 文件。apache 使用非常广泛,但速度不是很快,甚至没有优化。

我肯定会建议结合 php-fpm 的 nginx 服务器。配置非常简单,如果您熟悉 apache,使用 nginx 应该不会有问题。如何:https ://tecadmin.net/setup-nginx-php-fpm-on-ubuntu-20-04/


推荐阅读