0

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.

Max Cruer
  • 1
  • 1
  • You may check the code of the PHP file. It may sleep or loop or waiting something before timeout. En short, it may not be due to the mod_php. Is the CPU on the server high ? – Dom Mar 06 '21 at 19:12
  • @Dom, The code in the PHP file is very simple, it only reads 50 items from the DB and outputs some HTML, as I said, it takes around ~200ms. The CPU usage is not high. – Max Cruer Mar 06 '21 at 19:14
  • Is your DB server the same installation in your Apache2 test and stand-alone PHP test? – Tero Kilkanen Mar 07 '21 at 07:03
  • @TeroKilkanen, yes the DB, Apache and PHP are all installed on the same server. When I run the PHP script on the command-line it runs in 200ms, but when through Apache it takes 1.5sec. Why? – Max Cruer Mar 07 '21 at 07:11
  • I won't recommend mod_php these days, it's not secure as it runs under same user as httpd process. Check php-fpm. – Jiri B Mar 07 '21 at 08:40

0 Answers0