Very slow TTFB or White pages (error 500?)

First of all thanks for Virtualmin GPL, I have been using cPanel for years, and never thought that a better, free alternative existed.

Anyway, I’m using Virtualmin on Debian 8, on an OVH Cloud RAM-1 VPS which has 6GB Ram and a single cpu core.

From a clean, fresh install without any modifications or additions by me.

I’m hosting around 15 sites, most are Joomla based with only few static pages (so almost zero load), some are plain HTML, and one is a Joomla based news site, which has might cause some load, still nothing intense (a 100MB SQL database, and few hundred visits per day, caching enabled).

While usually the time to first byte is super fast, some times without any obvious reason it takes more than 20 seconds. Also, sometimes when editing articles in Joomla I get a blank page (probably error 500, but not configured to be displayed?)

Only messages I found on apaches error.log are:

(lots of times) PHP Warning: Module ‘mcrypt’ already loaded in Unknown on line 0
(very rarely) [Tue Feb 28 03:16:33.423908 2017] [fcgid:warn] [pid 17904] mod_fcgid: process 18461 graceful kill fail, sending SIGKILL

Any ideas?

PHP Warning: Module ‘mcrypt’ already loaded in Unknown on line 0

It means you have loading in more than one file. Check virtualserver and global (main) php.ini files for the line containing and comment out that line (or lines if more than one). Then restart Apache.

[fcgid:warn] [pid 17904] mod_fcgid: process 18461 graceful kill fail, sending SIGKILL

This error shows when your script was running more than allowed and then the server kill the process. This is more complicated how to solve. It could be low settings with fcgid, server running out of memory or cpu (oversold server), bad coding, wrong MySQL configuration or all combined. I would start with fcgid configuration especially numbers set with FcgidBusyTimeout, FcgidProcessLifeTime and FcgidIOTimeout.

Just remember that increasing this values will not help if the problem is somewhere else (like bad coding) and could be short term solution but in the long run can bring so many problems to even put your server down.

Not sure if this is same with every distro but Virtualmin during the installation could set some fcgid values inside httpd.conf file. If this is your case my advice is to remove them from httpd.conf and set them within fcgid module. Why Virtualmin is doing this i dont know, but i notice this was (still is?) the case with Centos 7. Not saying that is wrong but it complicates things when is no need to be complicated, e.g. settings instead to be set inside the module are displaced all over the place and makes it easier to make mistakes during editing.

For TTFB is even more complicated because factors what can affect are so many, from hardware used (HDD vs SSD), Apache and MySQL caching (enabled / disabled, and what settings), DNS (local or 3rd party), CDN quality (if used), settings with Apache and MySQL, what storage engine for MySQL (InnoDB, Myisam…) and so on. Could be even slow because of other two problems you mentioned. Its really hard to pinpoint the problem without deeper analysis of your server and reports from several testing tools.

For example if you check my post for GTmetrix pictures and compare with new results it is clear how changing several settings can and will affect your website:

New GTmetrix 1

New GTmetrix 1

My TTFB from 0.7-0.9 seconds dropped to 0.4-0.5 (sometimes 0.6) seconds. The differences are not big but its like making a mosaic, one damaged piece by himself isnt a problem but when you combine more of them the final picture will look bad.

Thanks for the suggestions.

I solved it by increasing MaxRequestWorkers in /etc/apache2/mods-enabled/mpm_prefork.conf

Seems there are more visits than what I thought, and that the server had a quite conservative setting, even if it can handle much more.

Thats correct. Apache default settings are usually good for a blog about cat or dog with few visits per day but actually they are pretty bad and useless, even the one changed during Virtualmin installation (e.g. when you need to select memory amount).