These days, I am finding it harder and harder to justify mod_php as the default behavior of an apache webserver over the advantages of mod_suphp. A lot of this has to do with my clients and their everyday needs, but I’ve become a pretty strong proponent of mod_suphp as the default for a server and only enabling mod_php if required.
It’s actually pretty easy to do, surprisingly. suPHP used to be a process that involved sacrificing chickens in the midnight hours to get to work correctly. Now? All it takes is the below. I’ve included instructions for centos and ubuntu both.
yum install mod_suphp
mv /etc/httpd/conf.d/php.conf /root/saved.conf/
Obviously the path /root/saved.conf/ can be wherever you want to put the original php.conf file. I suggest saving it somewhere in case you need it in the future to specifically enable mod_php for a site. Then you need to modify the file /etc/httpd/conf.d/mod_suphp.conf to look like:
# This is the Apache server configuration file providing suPHP support..
# It contains the configuration directives to instruct the server how to
# serve php pages while switching to the user context before rendering.
LoadModule suphp_module modules/mod_suphp.so
### Uncomment to activate mod_suphp
AddHandler x-httpd-php .php .php3 .php4 .php5
# This option tells mod_suphp if a PHP-script requested on this server (or
# VirtualHost) should be run with the PHP-interpreter or returned to the
# browser “as it is”.
# This option tells mod_suphp which path to pass on to the PHP-interpreter
# (by setting the PHPRC environment variable).
# Do *NOT* refer to a file but to the directory the file resists in.
# E.g.: If you want to use “/path/to/server/config/php.ini”, use “suPHP_Config
# If you don’t use this option, PHP will use its compiled in default path.
and then modify /etc/suphp.conf to change this line:
Restart apache and then check a phpinfo page. You should see that the Server API line now reads: “CGI/FastCGI”.
Ubuntu was actually much easier, surprisingly:
aptitude install libapache2-mod-suphp
Restart apache and check your phpinfo page.
To be honest, given the way web applications function these days, I’m truly surprised that this hasn’t become default behavior for php at this point…that they have not absorbed the suphp project into their own work. Until that day comes, that’s all that is required to start running with your own suphp install.
Edit: Also, I’ve not tested this on RHEL, but given the way fedora/centos/RHEL works, you should be able to follow these instructions for that OS as well.