Avova - Web Design & More!

HowTo: Setup lighttpd with suPHP

by Mark Grenham, 01-Oct-2008

Overview

This HowTo decribes the steps involved in getting suPHP to work with lighttpd. suPHP is a tool for executing PHP scripts (and others) with the permissions of their owners. lighttpd (lighty) is a very fast, standards compliant web server with a low memory footprint.

While this HowTo is aimed specifically at Debian/Ubuntu based linux distributions, the configuration should apply to any distribution.

Installation

First install lighty and suPHP via apt or aptitude:-

$ apt-get install lighttpd suphp-common

The cgi version of php also needs to be installed:-

$ apt-get install php5-cgi

It's worth having a read through the suPHP configuration file (/etc/suphp/suphp.conf)

Next create the following configuration file (/etc/lighttpd/conf-available/10-suphp.conf) and add the following contents:-

# suPHP lighty config - by Mark Grenham
# 01-Oct-2008
#

# Enable setenv - required to create environment for suphp
server.modules += ( "mod_setenv" )

# Enable cgi
server.modules += ( "mod_cgi" )

# Set up suphp environment to handle php files
$HTTP["url"] =~ ".php$" {
setenv.add-environment = (
"SUPHP_HANDLER" => "x-httpd-php"
)
}

## Uncomment to enable suphp to handle other cgi scripts
#$HTTP["url"] =~ ".pl|.py|.cgi$" {
# setenv.add-environment = (
# "SUPHP_HANDLER" => "x-suphp-cgi"
# )
#}

# Assign suphp to handle php files
cgi.assign = (
## Uncomment the following if you want suphp to handle other cgi scripts
#".pl" => "/usr/lib/suphp/suphp",
#".py" => "/usr/lib/suphp/suphp",
#".cgi" => "/usr/lib/suphp/suphp",

".php" => "/usr/lib/suphp/suphp"
)

# END OF FILE


Next enable the module and restart lighty:-

$ lighty-enable-mod suphp
$ /etc/init.d/lighttpd restart

And you're done.

Notes

As mentioned above you can also have suPHP handle other cgi scripts. You can do this by uncommenting the commented out parts of the 10-suphp.conf file. Also ensure that you have the following in your /etc/suphp/suphp.conf file:-

;Handler for CGI-scripts
x-suphp-cgi=execute:!self