Using suPHP on my web server to run Joomla
Last Updated on Tuesday, 09 March 2010 15:55 Written by Joe Aldeguer Friday, 30 January 2009 22:09
| Article Index |
|---|
| Using suPHP on my web server to run Joomla |
| Page 2 Packages to install |
| Page 3 Compiling suPHP |
| Page 4 Enabling mod_suphp.so |
| Page 5 Restart apache2 |
| All Pages |
Have you ever experienced some hair pulling moments working with Joomla regarding permission errors? If you answered yes, read on.

Just like you, I have had my share of frustrating problems installing extensions where it would fail to install unless I change the permissions of the document root folder. If I don't make the permission changes this is what I get instead I get the error message "Warning Failed to move file." Failed to move what, huh???
Another one, uploading an image using the built-in wysiwig editor then finding out later I can't edit the image since I no longer have ownership of the file but instead my web server has claimed ownership of the file (www-data.) This wouldn't be much of a problem if it was just my site. I could always chown/chmod the directory to fix the issue. But when your managing multiple Joomla sites, having to listen to users bitch and complain that they can't install nor upload files is enough to make any sysadmin go postal! Fortunately, there is a more civil way to address the problem.
Well, using my most reliable IT consultant Google search, I found the solution I was looking for. This is how I got suPHP to work on a newly installed Debian Etch server. I will install suPHP using two methods the first method will be compiled from source. The second method will use Debian Etch packages. (The advantage from compiling from source you'll get newer releases. On the other hand it is easier to do updates using Debian packages.)
Disclaimer: There are no guarantees this will work for you. Created for author's personal use.
FYI: I had problems trying to make suPHP work on Debian Lenny using the setup below. I have tried other ways to make it work but all failed. If you where able to make it work on Debian Lenny I'd be happy to hear about it. I decided to use mpm-itk to achieve the same results on Debian Lenny using this how-to.
After completing the Debian Etch install I will proceed to install Virtualmin using the install script. Then I'll install some needed software before installing suPHP thereafter.
Note: Words in italics will be typed at shell prompt. The following module is not installed and shouldn't be libapache2-mod-php5.
Packages to install:
run apt-get update
apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev linux-kernel-headers lynx m4 make ncftp nmap openssl perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++Some of the above packages may have already been installed by Virtualmin's install script. It doesn't hurt to just run it again. APT will know what has or has not been installed and will act accordingly.
Disable the Apache php5 module.
a2dismod php5
/etc/init.d/apache2 restart
First method:
Install apache2-prefork-dev needed by suPHP. Other required packages will be installed as well.
apt-get install apache2-prefork-dev
I'll check to see if I now have apxs2 installed which is required when compiling suPHP. I am installing suPHP as a DSO.
whereis apxs2
will return /usr/bin/apxs2 (This is where Debian puts apxs2 after installing apache2-prefork-dev.)
Get the latest version of suPHP.
Into /usr/local/src.
cd /usr/local/src
wget http://www.suphp.org/download/suphp-0.7.0.tar.gz
tar -xzvf suphp-current-version
cd suphp-current-version
Compiling suPHP.
./configure --prefix=/usr --sysconfdir=/etc --with-apache-user=www-data --with-setid-mode=paranoid --with-apxs=/usr/bin/apxs2
Hit [Enter]
make
make install
While still in the directory /usr/local/src/suphp-current-version.
cd doc/
cp suphp.conf.example /etc/suphp.conf
vi /etc/suphp.conf
I changed the umask setting from 0077 to 0022, which will match Joomla's recommended permission settings. Files should be 644 and directories are 755.
| [global] ;Path to logfile logfile=/var/log/suphp.log ;Loglevel loglevel=info ;User Apache is running as webserver_user=www-data ;Path all scripts have to be in docroot=/ ;Path to chroot() to before executing script ;chroot=/mychroot ; Security options allow_file_group_writeable=false allow_file_others_writeable=false allow_directory_group_writeable=false 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-php=php:/usr/bin/php5-cgi ;Handler for CGI-scripts x-suphp-cgi="execute:!self" |
vi /etc/apache2/httpd.conf
LoadModule suphp_module /usr/lib/apache2/modules/mod_suphp.so
|
Second Method: apt-get install libapache2-mod-suphp suphp-common The Debian package puts suphp.conf in /etc/suphp/suphp.conf Logfiles are located in /var/log/suphp/suphp.log (The current Debian package uses --with-setid-mode="owner". Which means there is no need to add suPHP_UserGroup into the Apache directive for each virtual host.) Contents of /etc/suphp.conf from the first install method could also be used for the second method. |
Going into /etc/apache2/sites-available.
I'm going to edit my apache2 virtual host configuration which was automatically created for me by Virtualmin. I will add the part which suPHP needs to function properly on my virtual web site.
vi example.com.conf (adding the part high lighted in blue.) Replacing example example with your user and group name.
Add this into the Apache directive if you installed suPHP from source:
| suPHP_Engine on suPHP_UserGroup example example AddHandler x-httpd-php .php .php3 .php4 .php5 suPHP_AddHandler x-httpd-php |
Add this into the Apache directive if you installed suPHP using the Debian package:
| suPHP_Engine on AddHandler x-httpd-php .php .php3 .php4 .php5 suPHP_AddHandler x-httpd-php |
Adding it into Virtualmin server template saves me from having to put it in by hand each time I create a virtual host. (Make sure to use correct usage of suPHP_UserGroup depending on what method was used to install suPHP.)
restart apache.
/etc/init.d/apache2 restart
A good tutorial to use for testing if suPHP has been installed and working correctly.
http://www.wbitt.com/my-howtos/49-suphp-for-apache-the-painless-way.html
Checking the logs to check for errors. If there are no errors logs will show the script
is running using the UID of my user account.
Other packages I like to install:
apt-get install php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl unixodbc unixodbc-dev unixodbc-bin php5-odbc (some of these may already have been installed earlier by virtualmin's install script.)
When asked about Maildir support answer yes.

With suPHP enabled for my virtual host there is no longer a need to lessen the permissions on folders or files. Installing extensions no longer fails now that the script is running as my user account not that of the web server.
Things to keep in mind after moving a Joomla web site which was originally running on a web server not setup to use suPHP into a web server setup to use suPHP. The document root of the Joomla site needs to have 755 for all folders and 644 for files otherwise you will get errors such as this.
Internal error message:
If something is not working check suPHP's logs. If you have used the suphp.conf from this website the location will be /var/log/suphp.log. If using the Debian package setup it will be in /var/log/suphp/suphp.log. Looking at the logs will provide clues to diagnose why it fails to work.
Note: The location to change the php.ini values is now at: /etc/php5/cgi/php.ini.
Once again Joomla is no longer like a love hate relationship, thanks to suPHP creator Sebastian Marsching!
References:
http://www.suphp.org/Documentation.html
http://www.howtoforge.com/apache2_suphp_php4_php5
http://www.debian-administration.org/articles/84
http://www.wbitt.com/index.php/howtos/34-howtos/49-suphp-for-apache--the-painless-way

















COMMENTS: (Abusing this comment form with spam would be the most effective way to have your IP, network or country blocked!)
Perfect! Can't say thanks enough. :)
I couldn't get along with IPConfig 3 and so thought I'd come back over here and give Virtualmin a go instead. I just finished installing on a fresh Debian 4 a couple of hours ago after following your guide on another article here. Went great, no problems at all (thanks to the Spamassassin enabling trick).
In case yo haven't tried ISPC 3, I can tell you that Virtualmin is a *world* apart in both function and usage. Chalk and cheese, really.
So next, I'm preparing to do follow the guide above.
Thanks for these guides, they are great. Really helpful. I'm new to Linux (on servers at least) and so am trying to get things set up with the right tools from the beginning, to save having to change loads of things further down the line. These guides are making it a lot easier.
:)
That is really good to hear I am able to offer some help! I have always wanted to share what I have learned from other folks who were kind enough to share their knowledge online.
Have fun using Virtualmin GPL, it really has made managing websites enjoyable!
I’m new at this – just got a new dedicated server – and I’m having this stupid file dir permission and I found your article..
I need to install the suphp and from what I read I have the php5 mod installed as well..
What is the best Method to do.. As I read 1 its seems good to do..
Little confused on this.. on when I get to the 2nd method – Is what in the blue just for it.. then the 1st method continues after the stuff in the blew box?
Thanks for your help
Again I’m a linux newbee.. what is the best program to use to edit it I got Putty
Rick
I use putty too to connect to my Linux server. Once I am connected I use vi to do file edits. If you're not use to using vi you can use Webmin's file manager to edit configuration files. I suggest installing Webmin if you're new to Linux since this will allow you to control your server via a web interface. Search my website for Webmin I have it covered as well. Make sure to use my suggestions to increase Webmin's security.
Which version of Linux are you using? I have only covered using suPHP on Debian 4.0 Linux called Etch. If you are using Debian Etch you have to make sure you have the following installed first:
apt-get install apache2-prefork-dev
apt-get install libapache2-mod-suphp suphp-common
Then just copy the contents of my /etc/suphp.conf to yours.
After that copy these lines into your virtual host configuration:
suPHP_Engine on
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php
Then restart your web server
/etc/init.d/apache2 restart
Unfortunately this tutorial fails to work with Debian Lenny. But there is another solution which is much easier to implement achieving the same result as suPHP.
I have it covered here: http://joealdeguer.com/technology-proj ects/34-web-hosting/86-using-apache2-itk-mpm-on-deb ian-lenny.html
Welcome to Linux!