Monday, November 23, 2009

suphp vs apache

SkyHi @ Monday, November 23, 2009
I'd seriously be looking for a new host who :
a) runs mod_SuPhp
b) has register globals disabled by default

Running php as apache ( or "nobody" ) means you end up having to open up world write permissions to be able to create files via php. If *any* website on the server has a security hole ( made worse by register globals being enabled ) then EVERY website that shares the same server is vulnerable.

When mod_SuPhp is enabled your website scripts run as your user ( ie/ mine run as "yabba" ), because of this you can disable world write and group write on every file/folder and still be able to create files via php. If another website on the same server has a security hole then only their site is compromised as user-A cannot create files in user-B's folders.


Using suexec and suphp enforce a different type of privilege separation than the default.

The default is to separate the user's permission from the web server. That is, the user owns the files, and he has to grant the web server permission to view and change them.

The suexec/suphp model is that the webserver (when running scripts) runs under the user's account, so the website has permission to do anything that the user has permission to do. To a certain degree, this removes the separation between the user and the webserver, but in exchange it enforces a DIFFERENT separation: that is, between the website of one user and the website of a different user on the same box.

By default, PHP always runs under Apache's user account, so one website's PHP scripts can access any files that another site's PHP scripts can. Therefore, if one account on the server gets hacked, the infection can spread to the others. SuPHP prevents this.

Neither suexec nor suphp will affect the way apache serves static content. All the old rules still apply. Instead, suexec and suphp change the account under which CGI and PHP (respectively) will run. Suexec makes CGI executable run under the owner's account, while SuPHP makes PHP scripts run under the owner's account.

Suexec and SuPHP aren't necessarily better. They're just different. They won't prevent a website from being hacked (and arguably might make the site easier to hack), but they will prevent a compromise on one site from spreading to all the others. To the site administrator, this isolation is arguably more important, which is why some shared hosting systems make suexec and suphp the default.

One extremely common "gotcha" is that SuPHP checks the ownership and permissions of a script before it runs, and will return a 500 error if the permissions aren't appropriate.

In particular:

  • The owner and group of the file must match the website owner (as setting in apache configuration)
  • The file must not be world-writable
  • The parent directory must not be world-writable