HomeBlogUbuntu 10.04, suPHP, and phpMyAdmin

my random thoughts

take 'em or leave 'em

Ubuntu 10.04, suPHP, and phpMyAdmin

HomePrintE-mailPdf

I've recently setup an Ubuntu server that uses suPHP.  I wanted to also use phpMyAdmin but found that there were some issues with getting it to work with phpMyAdmin.  I found some work arounds while Googleing but nothing definitive.  So this is how I did it.

The first problem I ran across was that suPHP would not allow phpMyAdmin to run because Ubuntu installs it into /usr/share/phpmyadmin rather than the default web document root /var/www.  So suPHP would return the error " File "/usr/share/phpmyadmin/index.php" is not in document root of Vhost "/var/www."  Some got around this by simply installing phpMyAdmin manually in /var/www but I'd rather let Ubuntu handle it.  (suPHP would not allow symlinks either).

The easiest way to get around this would be to tell suPHP to ignore that security restriction by editing /etc/suphp/suphp.conf and change

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

to

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=false

But that screamed "SECURITY BREACH" to me so that was not an option. 

So, what I did was make phpMyAdmin its own virtual host. 

Edit Apache's phpMyAdmin config file:

sudo pico /etc/apache2/conf.d/phpmyadmin.conf

At the beginning of this file add:

<VirtualHost *:80> 

ServerAdmin webmaster@localhost 
DocumentRoot /usr/share/phpmyadmin

At the end of the file, add

</VirtualHost>

Save by holding down the Control key and hit the o key.  Then ctrl-x to exit.

Then, tell suPHP that /usr/share/phpmyadmin is okay:

sudo pico /etc/apache2/mods-available/suphp.conf

Add the following  before "</IfModule>":

<Directory /usr/share/phpmyadmin>

               suPHP_Engine on

</Directory>

And in /etc/suphp/suphp.conf, add phpmyadmin's directory to an allowed docroot:

;Path all scripts have to be in

docroot=/var/www:${HOME}/public_html:/usr/share/phpmyadmin

Now, after browsing to http://mysite.com/phpmyadmin, I got a 500 Internal Error message.  Searching the logs, I found this message:

UID of script "/usr/share/phpmyadmin/index.php" is smaller than min_uid

Two issues.  One is that the Ubuntu's phpMyAdmin install is owned by root.  Easy fix:

sudo chown -R www-data:www-data /usr/share/phpmyadmin

But, still get the same error.  So the second reason is that suPHP is configured to have a minimum UID of 100.  www-data's UID is 33.  So, edit suPHP's config to change the minimum to 33.

sudo pico /etc/suphp/suphp.conf

Change:

; Minimum UID
min_uid=100

; Minimum GID
min_gid=100

to:

; Minimum UID
min_uid=33

; Minimum GID
min_gid=33

Make sure you change the min_gid as well or else suPHP will still reject phpMyAdmin.  I guess this could be a potential security issue as well but less of a one than letting web scripts have free rein outside their designated directories.

Now we have suPHP and phpMyAdmin working together! 

 




Gravatar
zbyte (01.04.2012 (05:44:55))
Checkout this alternative approach, where you leave php5 enabled for /usr/share, and run suphp otherwise. I think it's a simpler approach: http://serverfault.com/a/211942/65036
Gravatar
Ben (15.12.2011 (15:27:55))
An improvement upon my previous comment. This version will prevent Apache errors if the suphp module is not loaded. Such errors might include:

"Invalid command 'suPHP_Engine', perhaps misspelled or defined by a module not included in the server configuration"

Here's the snippet (you may need to change your paths accordingly):

Alias /phpmyadmin /usr/share/phpmyadmin


suPHP_Engine Off
AddHandler php5-script .php



This way, suphp can be enabled/disabled without throwing errors when Apache loads its configuration files.
Gravatar
Ben (15.12.2011 (15:12:01))
There is a simple means by which to exempt directories from suPHP restrictions altogether:

Alias /phpmyadmin /usr/share/phpmyadmin

suPHP_Engine Off
AddHandler php5-script .php
Gravatar
Caju (13.12.2011 (11:25:04))
Hello all, googling about this issue, I could found two possibilities:

1) the one described in this post;
2) enable php5 and suphp but restrict php5 to only directory /usr/share. This is done editing the file /etc/apache2/mods-available/php5.conf, removing all content and adding:



AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps



So, all php files will be handled by suphp but files residing in /usr/share will be handled by php5.

What approach is more safety? Is there some performance issue with each one of these?

Kind regards,
Caju
Gravatar
cordoval (17.10.2011 (21:16:02))
solved it by chown it again upgrade had issued new files owned probably by root

thanks
Gravatar
cordoval (17.10.2011 (21:01:10))
upgraded to latest ubuntu days ago and it is not working anymore ,any ideas, please email me
Gravatar
daniel (19.09.2011 (15:33:05))
very helpfully article , thanks
Gravatar
Alan Hartless (16.05.2011 (21:37:39))
Quote :
Won't this break every time apt-get upgrade decides to give you a new phpmyadmin version?


Shouldn't unless it overwrites your config file. Usually Ubuntu will tell you before it does such things and give you the option to view, merge, overwrite, etc config files.
Gravatar
Hunter Cook (16.05.2011 (17:13:45))
Won't this break every time apt-get upgrade decides to give you a new phpmyadmin version?
Gravatar
Alan Hartless (15.03.2011 (04:31:50))
@Luis - sounds like a permission issue. Are you getting any errors in your error_log?

Page 1 of 2

Smileys

:confused::cool::cry::laugh::lol::normal::blush::rolleyes::sad::shocked::sick::sleeping::smile::surprised::tongue::unsure::whistle::wink:

 1000 Characters left