CloudLinux - CloudLinux Blog - Perfecting FastCGI settings for Shared Hosting
CloudLinux OS Blog

Perfecting FastCGI settings for Shared Hosting

There are plethora of articles on how to optimize FastCGI setup. Yet, all of them talk about settings for a single site. The situation is much different in shared hosting, where there are hundreds of sites running. Understanding & optimizing mod_fcgid settings can make a difference between fast and stable PHP hosting and frequent 503 & 500 errors. Unlike suPHP that executes new PHP process for each request, FCGID starts a bunch of processes per customer, and re-uses them for each PHP request.

mod_fcgid is an option in majority of hosting control panels, yet most of the control panels don't alter default settings. And the default settings in mod_fcgid are made for a single site. You can find more info on mod_fcgid settings here:
http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

When setting up mod_fcgid, you should care about several configuration options:

  • FcgidMinProcessesPerClass -- should always be 0
    "PerClass" means per user in shared hosting, and 0 means that there might be no processes for a particular user, if that user is not active.

  • FcgidMaxProcessesPerClass -- default 100, this means that a single customer can have 100 php requests served at the same time. Which in turn means there will be 100 PHP processes just for that user. This is way to high for shared hosting. I would recommend values anywhere from 8 to 20. Note: if more requests comes in at the same time, they will be queued, and not rejected.

  • FcgidMaxProcesses -- this is the total number of processes FCGID will start, for all users. That is what will prevent OOM issues. The more RAM you have, the higher you can set the value.
    If you set this value too low, you will get 500 errors, as FCGID will not be able to create new processes to serve requests. This value also depends on the size of PHP processes (which in turn depends on extensions that you have enabled for PHP) as the larger the process the faster you will him OOM. You can try playing with following numbers depending on your RAM: 8GB -- about 150, 16GB -- 300.

    Also, make sure you monitor apache error logs. If you see "can't apply process slot for error" -- it means you are hitting FcgidMaxProcesses

  • FcgidIdleTimeout -- default 300, number of seconds process would stay idle until it gets killed. The higher the number, the lower CPU usage, and the higher the chance of hitting FcgidMaxProcesses limit (as processes live longer). I would recommend putting it at 60 at first.

  • FcgidIdleScanInterval -- this should be adjusted as well, to about a half of what FcgidIdleTimeout is set.

  • FcgidProcessLifeTime: default - 1 hour, should be -- anywhere from 120 seconds to 300 seconds (double idle time). It is there to make sure that processes do get killed after some time, if they are not busy (even for short periods of time). The shorter idle timeout/process life time, the less chance that you will hit FcgidMaxProcesses limit, but the more load you will put on the system.

Most values can be same from server to server, but you might want to change FcgidMaxProcesses depending on the amount of RAM you have. Example FCGID settings for shared hosts:

FcgidMinProcessesPerClass 0
FcgidMaxProcessesPerClass 8
FcgidMaxProcesses 150
FcgidIdleTimeout 60
FcgidProcessLifeTime 120
FcgidIdleScanInterval 30 

CageFS 3.2 Beta 2
lve0.8.58 kernel and NFS issue
 

Comments 6

Guest - Haris on Thursday, 30 June 2016 04:00

Hello, thanks for the article but it is incomplete and there is no link for the rest

Hello, thanks for the article but it is incomplete and there is no link for the rest
WisiKlo WisiKlo on Thursday, 30 June 2016 14:53

This is the full text. There is nothing more to the tunning. We would recommend using mod_lsapi instead of mod_fcgid anyway.

This is the full text. There is nothing more to the tunning. We would recommend using mod_lsapi instead of mod_fcgid anyway.
Guest - Eduardo on Saturday, 29 October 2016 15:45

Hi Igor, I have mod_lsapi but I see my server more slow. How I can config mod_lsapi for shared Hosting Service (actuall around 100-200 websites in WordPress and PrestaShop). My server have Centos 7.2 Cloudlinux, MariaDB, 16GB ram, single Xeon E3 1230 8 cores 3.2 ghz. Thanks !!

Hi Igor, I have mod_lsapi but I see my server more slow. How I can config mod_lsapi for shared Hosting Service (actuall around 100-200 websites in WordPress and PrestaShop). My server have Centos 7.2 Cloudlinux, MariaDB, 16GB ram, single Xeon E3 1230 8 cores 3.2 ghz. Thanks !!
WisiKlo WisiKlo on Saturday, 29 October 2016 21:04

I would recommend contacting our support. mod_lsapi should outperform mod_fcgid.

I would recommend contacting our support. mod_lsapi should outperform mod_fcgid.
Guest - olidev on Wednesday, 07 March 2018 11:30

Instead of trying to manually configure fastcgi service on a server for php apps, it is better to use managed servers where these services doesn't require to be installed or configured manually, like Cloudways PHP web hosting. The servers you launch using this platform has php-fpm preconfigured.

Instead of trying to manually configure fastcgi service on a server for php apps, it is better to use managed servers where these services doesn't require to be installed or configured manually, like Cloudways PHP web hosting. The servers you launch using this platform has php-fpm preconfigured.
Guest - vov on Saturday, 26 October 2019 20:51
Already Registered? Login Here
Guest
Thursday, 09 April 2020

Captcha Image