installing suphp on virtualmin

One thing I don’t like about virtualmin is the absence of suphp. After a few modifications, I managed to integrade it and make it the default php handler for new virtual hosts. This howto is based on centOS 5.5 32bit and virtualmin 3.83 gpl, you may have to change some things if you’re on another linux distribution such as paths or update manager commands, but the procedure will be more or less the same.

 

First you’ll need to install some things required for suphp installation

yum install gcc-c++ gcc httpd-devel

Download and install suphp

wget http://suphp.org/download/suphp-0.7.1.tar.gz
tar -xzvf suphp-0.7.1.tar.gz
cd suphp-0.7.1
./configure --prefix=/usr --sysconfdir=/etc --with-apxs=/usr/sbin/apxs  --with-apache-user=apache --with-setid-mode=paranoid  --with-apr=/usr/bin/apr-1-config
make
make install

create the configuration file for suphp

cp suphp.conf.example /etc/suphp.conf

and modify it to suit your needs

vi /etc/suphp.conf

mine looks like this (if you’re not sure about what to change, just copy – paste this)

[global]
;Path to logfile
logfile=/var/log/httpd/suphp.log
;Loglevel
loglevel=info
;User Apache is running as
webserver_user=apache
;Path all scripts have to be in
docroot=/home
;Path to chroot() to before executing script
;chroot=/mychroot
; Security options
allow_file_group_writeable=true
allow_file_others_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false
;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true
;Send minor error messages to browser
errors_to_browser=false
;PATH environment variable
env_path=/bin:/usr/bin
;Umask to set, specify in octal notation
umask=0022
; Minimum UID
min_uid=100
; Minimum GID
min_gid=100
[handlers]
;Handler for php-scripts
x-httpd-suphp="php:/usr/bin/php-cgi"
;Handler for CGI-scripts
x-suphp-cgi="execute:!self"

add the suphp module to apache

vi /etc/httpd/conf.d/suphp.conf

and insert

LoadModule suphp_module modules/mod_suphp.so

If you want to change existing virtual hosts php handler to suphp then you’ll have to edit apache configuration file

vi /etc/httpd/conf/httpd.conf

go to the end of the file where virtual hosts are being configured and insert the following for each vhost

(of course you’ll have to replace user_for_the_vhost & group_for_the_vhost with the linux user&group the site is running under)

<IfModule mod_suphp.c>
suPHP_Engine on
suPHP_UserGroup user_for_the_vhost group_for_the_vhost
AddHandler x-httpd-suphp .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-suphp
</IfModule>

If you were using FCGId, you’ll have to delete (or comment) the following lines from each virtual host

#AddHandler fcgid-script .php
#AddHandler fcgid-script .php5
#FCGIWrapper /home/example/fcgi-bin/php5.fcgi .php
#FCGIWrapper /home/example/fcgi-bin/php5.fcgi .php5

To have suphp as the default php handler for new vhosts

  • login to virtualmin web-interface
  • go to system settings -> server templates and edit your default template (if you haven’t created one, the default is named “Default settings”)
  • Choose “Apache website” from “edit template section”, in the upper left hand corner
  • insert the following in “Directives and settings for new websites”, right under “DocumentRoot ${HOME}/public_html”
<IfModule mod_suphp.c>
suPHP_Engine on
suPHP_UserGroup ${USER} ${GROUP}
AddHandler x-httpd-suphp .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-suphp
</IfModule>

to look like this

scroll down and change the “Default PHP execution mode” to “Apache mod_php (run as Apache’s user)”, click Save and restart apache

service httpd restart

Test your sites and you’re done. If you’re having problems have a look at suphp log file at /var/log/httpd/suphp.log

  1. Why not FastCGI?

    Does it less secure? or are you running many low-traffic sites?

  2. Thanks so much for this. You totally saved my day. I’m in the same situation. I run a ton of lower traffic wordpress and drupal sites and just set up a couple new VPS servers using Virtualmin/Webmin.

    Mod_php is less than ideal for me because of permissions issues with WordPress maintenance and stuff, and FastCGI is way too RAM intensive for my needs.

    Everything worked perfect except for 2 snags I ran into which might be helpful to anyone else reading this:

    1. I could only get it to work if I put the Addhandler part down lower in the virtual host section like this:

    Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
    allow from all
    AllowOverride All
    
    suPHP_Engine on
    suPHP_UserGroup user user
    AddHandler x-httpd-suphp .php .php3 .php4 .php5
    suPHP_AddHandler x-httpd-suphp

    That’s where the previous FCGI info was. If I put it up right underneath the document root line, it wouldn’t work at all.

    Once I did that it worked like a charm.

    2. Phpmyadmin quit working after this. I didn’t dig in too deep to figure out why, because I kind of like the Virtualmin MYSQL manager now anyway. Phpmyadmin was just more familiar to me…but not a big deal at all.

    Cheers and thanks again for posting this!

  3. Miguel Granados

    Hi, do you know if using suPHP i could use different versions of PHP in diferent servers in Virtualmin? Thanks a lot.

    • Hi, Miguel

      It’s been a while since I’ve used virtualmin, but as far as I can remember you won’t have any problem using different versions of PHP in different vhosts

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.