Book
- Apache - DNS settings
- Apache - SSL certificates
- Apache - Configuration files
- Apache - Virtual host template
- Apache - Authorization
- Apache - Localized error pages
- Apache - Single sign-on
- Apache - Automatic proxy configuration
- Apache - Installing SSL certificate in browsers
- Apache - Web applications
- Apache - User wiki
- Apache - Intrusion protection
- Apache - External resources
- Apache - Optimization
- Squid setup
Installing Apache2 and PHP5 using mod_fcgid
All this time I used to use Apache with prefork method (apache2-mpm-prefork) combined with PHP5 module (libapache2-mod-php5). Until the day my web server choking out of resources because lots of users accessing. Apache with PHP module consumes a lot of memory because each request is handled by one process.
When I was googling, I found that Apache2 using worker is more efficient and less resource consuming because one process can handle many request (by using multithreading).
But heck, when I tried to install apache2-mpm-worker, my Ubuntu start whining about wanting to uninstall my libapache2-mod-php5. I found out that PHP5 module is not compatible with multithreading version of Apache. It only want the prefork version.
I was googling again, and I find that with worker version of Apache, PHP must be used in CGI form. Dang! I have bad experience with GCI version of PHP. But things have changed, now there is FCGI that much better handling CGI applications. Also by using this version of PHP, Apache will be less loaded because it will only handles static elements (html pages, images, css, etc). All PHP requests will be handled by PHP itself.
$ sudo apt-get install apache2-mpm-worker libapache2-mod-fcgid
And then we turn on the FCGI module:
$ sudo a2enmod fcgid
PHP5 Installation
Then we install PHP5 packages. These are what I used to have in my web servers. You can add or remove the packages you want:
$ sudo apt-get install php5-cgi php5-curl php5-gd php5-ldap php5-mysql php5-mysqli php5-sqlite php5-xsl
Apache Configuration
Now you edit the file /etc/apache2/sites-available/default, and then put these text below on the part after "NameVirtualHost" and before <Virtualhost>:
<Directory /var/www>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
</Directory>
And then put ExecCGI to each <Directory>.
Example:
Options ExecCGI Indexes
Now you can just restart your new Apache:
$ sudo /etc/init.d/apache2 force-reload
You can test it out by using phpinfo().
The above was about Ubuntu. And what files need to be changed on CentOS5?
- /etc/sysconfig/httpd -- uncomment "HTTPD=/usr/sbin/httpd.worker"
- /etc/httpd/conf.d/swtune.conf (or conf/htttpd.conf) -- revise performance settings in the <IfModule worker.c> section
- /etc/httpd/conf.d/php.conf -- make sure it's off
- /etc/httpd/conf.d/fcgid.conf -- just check it's presence
- /etc/httpd/vhosts/pre.ini (or the above file) -- revise FastCGI parameters
- /etc/httpd/vhosts/drupal.inc and /etc/httpd/vhosts/bt-ssl.inc -- comment out "Include vhosts/php.inc", uncomment "AddHandler fcgi-script .php", enable "Options +ExecCGI"
.....
Related Links
- Apache prefork vs. worker (richard camel)
- apache tuning question: prefork.c vs worker.c (linux questions)
- How to replace apache prefork to apache worker on Centos 5?
- Configuration trouble: PHP through mod_fcgid on CentOS 5.3 (serverfault)
- How to setup Apache2 with mod_fcgid and PHP5 on CentOS 5.2 (howtoforge)
- mod_fcgid manual
- Apache 2 and FastCGI
- Apache module mod_fastcgi
- Building mod_fastcgi on RHEL5
- HowTo: FastCGI with a PHP APC Opcode Cache
- How to share APC cache between several PHP processes when running under FastCGI?
- PHP bug 11988: share cache between FAST CGI processes
- Default installation layouts for Apache HTTPD on various distributions
Attachments

- Visit Apache prefork vs. worker (richard camel)
- Visit apache tuning question: prefork.c vs worker.c (linux questions)
- Visit How to replace apache prefork to apache worker on Centos 5?
- Visit Configuration trouble: PHP through mod_fcgid on CentOS 5.3 (serverfault)
- Visit How to setup Apache2 with mod_fcgid and PHP5 on CentOS 5.2 (howtoforge)
- Visit mod_fcgid manual
- Visit Apache 2 and FastCGI
- Visit Apache module mod_fastcgi
- Visit Building mod_fastcgi on RHEL5
- Visit HowTo: FastCGI with a PHP APC Opcode Cache
- Visit How to share APC cache between several PHP processes when running under FastCGI?
- Visit PHP bug 11988: share cache between FAST CGI processes
- Visit Default installation layouts for Apache HTTPD on various distributions

Comments
Post new comment