suPHP Setup on CentOS 6.x
Reading around online and having set up mod suPHP on CentOS myself it seems there are a lot of issues that pop up. Mainly, some users are missing dependencies, get newer and different errors each time, and so forth. Everyone, it seems, is involved in a never-ending dispenser of errors that must be solved.
So far the easiest way to setup suPHP on CentOS 6 has been the following and this should be a quick one. This was done on CentOS 6.5 64-bit.
- Add RPM Forge repository.
32-bit: rpm -ivH http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm 64-bit: rpm -ivH http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
- Disable RPMForge by default (if you leave things like this enabled, it will break your system).
# sed -i 's/enabled = 1/enabled = 0/g' /etc/yum.repos.d/rpmforge.repo
- Install mod_suphp via yum:
# yum install mod_suphp -y --enablerepo=rpmforge
- !! Important !!: Correct the PHP Handler:
# sed -i 's/x-httpd-php=php:\/usr\/bin\/php/x-httpd-php=\"php:\/usr\/bin\/php-cgi\"/g' /etc/suphp.conf
If you do not perform the above (replace "x-httpd-php=php:/usr/bin/php" with "x-httpd-php="php:/usr/bin/php-cgi"") you will get the similar issues to the following errors:
[error] [client] SecurityException in Application.cpp:511: Unknown Interpreter: php [error] [client] Premature end of script headers: index.php
- Make sure to set PHP to load via fastCGI and NOT the normal "Apache 2.0 Handler". You can see this via a PHPINFO page.
# yum install mod_fastcgi --enablerepo=rpmforge -y
- Shut off the normal Apache handler for PHP files. This will be in your /etc/httpd/conf.d/php.conf:
16 #<FilesMatch \.php$> 17 # SetHandler application/x-httpd-php 18 #</FilesMatch>
- Example vhost config (/etc/httpd/conf.d/example.com.conf
<VirtualHost ip-address:80> NameVirtualHost example.com ServerName example.com ServerAlias www.example.com ServerAdmin firstname.lastname@example.org DocumentRoot /path/to/web/document/root ErrorLog /var/log/httpd/example.com-error_log CustomLog /var/log/httpd/example.com-access_log combined DirectoryIndex index.php index.html suPHP_Engine on suPHP_UserGroup user group AddHandler x-httpd-php .php suPHP_AddHandler x-httpd-php php_admin_value open_basedir "/path/to/web/root:/usr/lib/php:/usr/local/lib/php:/var/lib/php/session:/tmp" <Directory /> AllowOverride All </Directory> </VirtualHost>
- Things to Consider and Edit
- Vhost Configuration: Set the IP Address
- Vhost Configuration: Set the server address (web domain)
- Vhost Configuration: Set the document root
- Vhost Configuration: Set the document root for the open_basedir
- Vhost Configuration: Set the user and group. In systems like RHEL / CentOS, these are usually the same.
You should be able to restart Apache now and not have any issues.
If, however, you do have issues please let me know so I can spin up some more machines and give it another whirl.