Apache+mod_php so slow

939 Views Asked by At

I have a problem setting up my Apache server with mod_php. I have a website whose index.php page is generated in ~200ms. But Apache serves it in about 1.5sec. Why is this slowdown taking place?

If needed, my /etc/apache2/ports.conf file is:

Listen 80

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

My file /etc/apache2/sites-available/mysite.local.conf is:

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>

My main question is why is this so slow and how can make it faster? I have tested putting the index.php content into a plain html file, and it is served in ~10ms. so the problem is probably with mod_php? Thanks in advance.

1

There are 1 best solutions below

1
On

A reason could be that apache checks for .htaccess files recursively within each directory of the root for each request. apache is used very widely but not very fast or even optimized.

I definitely would suggest an nginx server combined with php-fpm. The configuration is very straight forward and if you're familiar with apache, you should not have problems using nginx. How To: https://tecadmin.net/setup-nginx-php-fpm-on-ubuntu-20-04/