Home Linux BasicsHow to Install and Configure mod_fcgid in Apache

How to Install and Configure mod_fcgid in Apache

by SupportPRO Admin

mod_fcgid is a high-performance Apache module designed to improve the execution of CGI applications. It was introduced as a binary-compatible replacement for FastCGI while providing better control over process management and resource usage.

Unlike traditional CGI modules such as mod_cgi or mod_cgid, mod_fcgid keeps application processes running in the background, allowing them to handle multiple requests efficiently without restarting for every connection.

Why Use mod_fcgid?

mod_fcgid offers several advantages:

  • Improved performance compared to CGI
  • Better process spawning control
  • Reduced server load
  • Faster handling of concurrent requests
  • Optimized memory usage

Installing mod_fcgid

Step 1: Install Apache Components

On Red Hat or CentOS systems, install Apache with the threaded MPM Worker module to reduce memory consumption:

yum install apache2-mpm-worker libapache2-mod-fcgid

Step 2: Enable the fcgid Module

Enable the Apache fcgid module:

a2enmod fcgid

Step 3: Install PHP CGI Packages

Install PHP CGI and required extensions if they are not already available:

yum install php5-cgi php5-curl php5-gd php5-mysql

Configuring mod_fcgid

To configure mod_fcgid, create a new configuration file.

Step 1: Create Configuration File

Create the file:

/etc/apache2/conf.d/php-fcgid.conf

Add the following configuration:

AddHandler fcgid-script .fcgi .php
DefaultInitEnv PHPRC "/etc/php5/cgi"
FCGIWrapper /usr/bin/php-cgi .phpMaxRequestsPerProcess 1000
MaxProcessCount 10
IPCCommTimeout 240
IdleTimeout 240ServerLimit 500
StartServers 3
MinSpareThreads 3
MaxSpareThreads 10
ThreadsPerChild 10
MaxClients 300
MaxRequestsPerChild 1000

Configuration for High-Traffic Servers

For servers with higher CPU and memory resources, use optimized settings:

AddHandler fcgid-script .fcgi .php
DefaultInitEnv PHPRC "/etc/php5/cgi"
FCGIWrapper /usr/bin/php-cgi .phpMaxRequestsPerProcess 1500
MaxProcessCount 45
IPCCommTimeout 240
IdleTimeout 240ServerLimit 2048
ThreadLimit 100
StartServers 10
MinSpareThreads 30
MaxSpareThreads 100
ThreadsPerChild 64
MaxClients 2048
MaxRequestsPerChild 5000

Step 2: Enable ExecCGI in Virtual Hosts

Add ExecCGI to the Apache virtual host configuration:

Order Allow,Deny
Allow from All
AllowOverride All
Options MultiViews Indexes Includes FollowSymLinks ExecCGI

This allows PHP and fcgid scripts to execute correctly.

Step 3: Restart Apache

After completing the configuration, restart Apache:

service httpd restart

mod_fcgid should now be active and serving PHP requests efficiently.

Conclusion

mod_fcgid improves Apache performance by keeping CGI processes persistent and efficiently handling multiple requests. Proper configuration ensures better scalability, reduced resource consumption, and improved response times for PHP applications.

If you require help, contact SupportPRO Server Admin

Partner with SupportPRO for 24/7 proactive cloud support that keeps your business secure, scalable, and ahead of the curve.

Contact Us today!
guy server checkup

You may also like

Leave a Comment