Learn Devops tools online from the blog. Devops Institute Ahmedabad.

Install Lighttpd, PHP and MySQL on Ubuntu

Sometimes you don’t want Apache for your web server whatever your reasons might be. There are other options like Nginx and Lighttpd, today I’ll setup Lighttpd along with PHP (via FastCGI) and MySQL.

Assuming you have a clean Ubuntu 10.10 system running go into the terminal and issue the following commands to install aptitude and Lighttpd:
$ sudo apt-get update
$ sudo apt-get install aptitude
$ sudo aptitude install lighttpd

Verify that Lighttpd is running: http://localhost/ You should see a default placeholder webpage.


Installing MySQL:
$ sudo aptitude install mysql-server mysql-client

Note: During the MySQL installation you will be prompted to set the root password.
Installing PHP (and some commonly used libraries – modify as needed):
 
$ sudo aptitude install php5-cgi php5-dev php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ps php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-xsl php5-common php5-mysql

In order to get Lighttpd and PHP working together you need to modify this file: /etc/php5/cgi/php.ini
$ sudo pico /etc/php5/cgi/php.ini

Inside the file look for the following line:
;cgi.fix_pathinfo=1

Change it to this:
cgi.fix_pathinfo=1
Save and exit the file.

Finally here are the last few commands to enable the PHP configuration and FastCGI module as well as reloading the Lighttpd web server:
$ sudo lighty-enable-mod fastcgi
$ sudo lighty-enable-mod fastcgi-php
$ sudo service lighttpd force-reload

We can test out PHP with a simple script (see below). However, there are a few things to note first:
1. The Lighttpd default document root (On Ubuntu 10.10) is located at: /var/www
2. The lighttpd.conf file (On Ubuntu 10.10) is located at: /etc/lighttpd/lighttpd.conf

Create a new file called info.php in the /var/www folder:
sudo pico /var/www/info.php

Add this code to the new file and then save and exit.
<?php
   phpinfo();
?>

Browse to http://localhost/info.php to examine all the PHP info.


Vishal.....

2 comments: