I have gotten suphp installed on a cpanel server. I have used it just on one server for testing so far, so my experience with this is limited. I don't gaurantee it will work for you!
suphp is an alternative to phpsuexec. It is an Apache module that lets PHP scripts run as the owner of the script, instead of the web server. This offers many security and usability enhancements to the world of PHP web serving. Mainly, when users create and modify files in their directory with PHP scripts, they don't need to make those files world-writable! One drawback is that the suphp binary is setuid root, so an exploit for it could possibly allow an attacker to run arbitrary commands as root.
I welcome all feedback. Please let me know if it works or doesn't work for you.
Part 1 - Build a new PHP
We have to build a new PHP binary in "CGI" mode. The currently installed PHP in cpanel is set to run as an Apache module. suphp must call up a php binary that is compiled to run in CGI mode.
cd /usr/src
Download PHP 4.3.3 source archive:
wget http://us4.php.net/get/php-4.3.3.tar.bz2/f....php.net/mirror
Extract:
bzcat php-4.3.3.tar.bz2 | tar xvf -
cd php-4.3.3
configure php, you can use your own options here but make sure you use a unique prefix:
./configure --with-xml --enable-bcmath --enable-calendar --enable-ftp --enable-magic-quotes --with-mysql --with-pear --enable-sockets --enable-track-vars --enable-versioning --with-zlib --with-gd --with-gettext --prefix=/standalonephp
make
make install
We should now be able to test to make sure the binary is built and in CGI mode:
/standalonephp/bin/php -v
You should see:
PHP 4.3.3 (cgi) (built: Oct 20 2003 00:33:13)
Copyright © 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright © 1998-2003 Zend Technologies
If you see (cli) instead of (cgi), then you messed up
Note that the PHP we just built is self-contained in the directory /standalonephp , so it shouldn't conflict with the PHP already installed for cpanel. Also, if you customize your php.ini, put it in /standalonephp/lib
Part 2 - Build suphp
cd /usr/src
wget http://www.suphp.org/download/suphp-0.3.1.tar.gz
tar xvfz suphp-0.3.1.tar.gz
cd suphp-0.3.1
chmod +x ./configure
./configure --with-php=/standalonephp/bin/php --with-apache-user=nobody
make
make install
suphp should now be built. For your reference, the default log file for it is /var/log/httpd/suphp_log. This can be changed as a configure option.
Part 3 - Configure Apache
We will now configure Apache to use suphp instead of the already installed php module.
cd /usr/local/apache/conf
make a backup copy of your httpd.conf
cp httpd.conf httpd.conf-beforesuphp
use vi or pico or emacs or whatever you prefer to open httpd.conf
search for LoadModule and comment out:
#LoadModule php4_module libexec/libphp4.so
add
LoadModule suphp_module libexec/mod_suphp.so
if it is not already added for you
comment out:
#AddModule mod_php4.c
add:
AddModule mod_suphp.c
if it is not already added for you
add:
suPHP_Engine on
then search for AddHandler and comment out:
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php .php4
#AddType application/x-httpd-php .php3
#AddType application/x-httpd-php-source .phps
#AddType application/x-httpd-php .phtml
add this line:
AddHandler x-httpd-php .php
save and exit.
restart apache:
/etc/rc.d/init.d/httpd restart
Now, test out some PHP scripts. Let me know how it works for you. I would like to know if anyone notices a speed decrease (or increase?).