This article is from VPS Media
This article will explain how to install and configure lighthttpd with PHP5 and MySQL. lighthttd is a web server designed to be fast, secure, flexible and standards-complient while being optimized for speed-critical environments.
Its low memory footprint, light CPU load and speed make it the perfect web server for an environment such as a 384MB VPS. lighthttpd supports the FastCGI interface, which we will use to enable PHP5 support. This article assumes you have already updated your system with the latest fixes and DO NOT have a web server, such as Apache, already installed on your VPS. We will be installing all required applications with the apt-get utility in Debian.
Install MySQL
We begin by installing MySQL 5.0:
# apt-get install mysql-server mysql-client
This should install and start up the MySQL server. Let’s give the MySQL root account a password, such as:
# mysqladmin -u root password yourpassword
Now we have to check on which address MySQL is listening with netstat:
# netstat -tap | grep mysql
The output should look similair to this:
tcp 0 0 localhost:mysql *:* LISTEN 1695/mysqld
Which means MySQL is listening on localhost only. But lets say you see output such as:
tcp 0 0 *:mysql *:* LISTEN 1695/mysqld
That means anyone can access your database and modify data, so you should set a password for your hostname. For example:
# mysqladmin -h server1.domain.com -u root password yourpassword
Replacing sever1.domain.com with your domain name.
Install lighthttpd
We can install lighthttpd with apt-get, like this:
# apt-get install lighttpd
After installation finishes, open your web browser and type in your VPS’ IP and you should see the placeholder page. Lighttpd’s default document root is /var/www on Debian, and the configuration file is /etc/lighttpd/lighttpd.conf.
Install PHP5
PHP works on lighthttpd using the FastCGI interface. Debian provides a FastCGI-enabled PHP5 package, which we can install like this:
# apt-get install php5-cgi
To enable PHP5 in lighttpd, we must modify two files (/etc/php5/cgi/php.ini & /etc/lighttpd/lighttpd.conf). First we open /etc/php5/cgi/php.ini:
# nano /etc/php5/cgi/php.ini
Add the following line right at the end of the file:
cgi.fix_pathinfo = 1
Then we open /etc/lighttpd/lighttpd.conf and add “mod_fastcgi”, to the server.modules stanza:
# nano /etc/lighttpd/lighttpd.conf
server.modules = (
“mod_access”,
“mod_alias”,
“mod_accesslog”,
“mod_fastcgi”,
# ”mod_rewrite”,
# ”mod_redirect”,
# ”mod_status”,
# ”mod_evhost”,
# ”mod_compress”,
# ”mod_usertrack”,
# ”mod_rrdtool”,
# ”mod_webdav”,
# ”mod_expire”,
# ”mod_flv_streaming”,
# ”mod_evasive”
)
and then right at the end of the file, we add the following stanza:
fastcgi.server = ( “.php” => ((
“bin-path” => “/usr/bin/php5-cgi”,
“socket” => “/tmp/php.socket”
)))
Next, we restart lighthttpd:
# /etc/init.d/lighttpd restart
Testing Your Installation
The document root of the default web site is /var/www. To test if PHP was installed properly, create a test.php file in your web folder, as such:
# nano /var/www/phpinfo.php
Place the following code inside:
Now point your browser to http://ip.address/phpinfo.php and you should see your PHP configuration. As you can see on the Server API line, PHP5 is working through FastCGI. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don’t have MySQL support in PHP5 yet.
Enable MySQL Support in PHP5
To get MySQL working with PHP5 all we have to do is install the php5-mysql package.
# apt-get install php5-mysql
Now restart lighthttpd:
# /etc/init.d/lighttpd restart
Reload the phpinfo.php file in your web browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module. That’s about it, congratulations on installing MySQL/lighthttpd/PHP5 on your VPS!