ispCP: fixing 500 server errors
by Andrei Dumitrache on Jun.22, 2009, under Programming
In a previous article I told you about a free web based control panel for managing a web hosting company. Today I am going to tell you how to fix the most common error that occurs while running ispCP: ”500 Server Error”.
Disclaimer: Apply these settings at your own risk! I strongly suggest backing up your apache and ispcp configuration files before following the directions stated in this article.
There are several causes for this error. In most cases, this happens when your Apache web server tries to serve certain PHP scripts and fails because of a malfunction of the components required to execute the PHP scripts. When you install ispCP, it automatically configures your Apache web server to run the PHP interpreter via FCGID or FastCGI (it is recommanded that you leave it run via FCGID). When a request for PHP script is received, Apache links itself to a FCGID process. If no such processes are running, it creates one and links to it. After that, it commands FCGID to run PHP and execute the web script. So basically, the scheme of things is this:
User Request for PHP script -> Apache ->FCGID -> PHP: script.php.
It is important to know that, once created, a FCGID process will not terminate after it serves the first script. It remains started and will handle future requests from Apache, even multiple requests at the same time. It will eventually terminate after a number of served requests or after a defined time. Also, multilple FCGID processes can be started, each serving multiple requests. These numbers can be configured.
Cause of the error
One cause for this error is the improper configuration of FCGID which exists or fails before PHP finished parsing the requested web script. The Apache web server then returns the error 500, also known as Internal Server Error.
There is generally a 40 second limit for which an FCGID process will execute a particular PHP script. After that time passes, even if PHP has not finished its job, the process will terminate causing the error in Apache. This happens when PHP tries to parse a web script that takes longer to execute. No matter what execution limit you set in php.ini, if it’s larger then 40 seconds, it will be ignored.
My approach to this problem
I will explain how to fix this issue for websites that are already added in your ispCP panel. In the end, I will explain how to apply to correct settings to future websites that you will add.
First, you can find FCGID related settings in multiple configuration files but not all settings are applyed. PHP generally does its process management internally and ignores your FCGID settings. It does that badly. With the default configuration, you may experience some other problems such as too many FCGID processes that forget to “die” and sapp your memory. You need to disable PHP’s internal process management.
Step 1 – disable PHP’s FCGI process management
Go to /var/www/fcgi/yourdomain.com/
Edit the file php5-fcgi-starter and comment (prefix with #) the setting that have _FCGI_ in their names.
Note that all settings are individual for each domain. All configurations that are treated in this article are local. To apply these settings to all your future web sites you will have to edit ispCP’s template files that are used to generate the configuration files for every domain.
Step 2 – Global FCGI settings from Apache
All Apache related settings are ussually found at /etc/apache2
/etc/apache2/mods-enabled contains links to the configuration files of the modules that will be loaded by Apache. All the configuration files linked from this directory will be parsed but that doesn’t mean that all settings will be applyed. Like I said, the settings are individual for each VirtualHost (for each domain that you add) .
Edit /etc/apache2/mods-enabled/fcgid_ispcp.conf and set higher timeouts. Here is a page that explains these settings.
Configure this file according to your needs. Here’s how my file looks like:
<IfModule mod_fcgid.c>
AddHandler fcgid-script .php .php5
SocketPath /var/lib/apache2/fcgid/sock
IPCConnectTimeout 900
IdleTimeout 600
IdleScanInterval 120
ProcessLifeTime 900
MaxProcessCount 200
DefaultMinClassProcessCount 1
DefaultMaxClassProcessCount 10
IPCCommTimeout 900
BusyTimeout 300
BusyScanInterval 320
ErrorScanInterval 3
MaxRequestsPerProcess 500
ZombieScanInterval 3
</IfModule>
Now, the problem: These settings will be parsed but will not apply to your web sites (yourdomain.com) because these are defined as VirtualHost’s and global settings are ignored in these directives.
Step 3 – Force Apache to apply the above settings
The file /etc/apache2/sites-available/ispcp.conf contains all the VirtualHosts (domains) defined by ispCP. To apply the global FCGID settings to yourdomain.com, you must edit this file.
Open it and search
# httpd [yourdomain.com] dmn entry BEGIN
This is where the VirtualHost directive for yourdomain.com begins. Within this VirtualHost, search
<IfModule mod_fcgid.c>
August 8th, 2009 on 7:28 pm
“Edit the file php5-fcgi-starter and comment (prefix with #) the setting that have _FCGI_ in their names”
If you use this configuration and remove “PHP_FCGI_CHILDREN” from starter script, it will also produce an error 500 every 500 requests.
August 25th, 2009 on 7:56 pm
Great Tutorial …
Helped a lot!!!
Thanks for that!
August 25th, 2009 on 8:57 pm
Hey,
I’m glad it helped you. I struggled with this problem for weeks before I find out what was wrong.
September 29th, 2009 on 11:29 pm
Although the files were in different places and I used different method to solve it, this finally helped me to eliminate this problem after lots and lots of searching,
I’m using Centos 5.3 and ispCp 1.0.2.
Thanks a lot!
October 6th, 2009 on 12:54 pm
Great Tutorial!!!!
Helped a lot!!!
January 13th, 2010 on 12:55 pm
Thanks !! Great Tutorial …
Helped a lot!!
March 28th, 2010 on 12:24 am
Thanks! helped to solve some other problems, too!
April 22nd, 2010 on 4:00 pm
Also try to set
PHP_FCGI_CHILDREN=10
I suppose scaninterval shouldn’t be less than the count of children