How to Install Lighttpd With PHP5 And MySQL On Ubuntu 11.04

0

Lighttpd is an open-source web server more optimized for speed-critical environments than common products while remaining standards-compliant, secure and flexible.

Here i will explain you the installation of Lighttd with PHP and MySQL on Ubuntu 11.04. In this tutorial i have used hostname as server1.example.com with the IP address 192.168.0.10.

The first thing you need to do is to login as root. You can login as root in Ubuntu Linux by typing in the terminal:

 

raj@ubuntu$ sudo su

Installing MySQL 5:

First we will start the installation of MySQL.

root@ubuntu:/# apt-get install mysql-server mysql-client

You will be asked to provide a password for MySQL user “root“. The same password will be valid for the user root@localhost as well as [email protected] .

Installing Lighttpd:

Next is to install lighttpd. By default lighttpd is available in Ubuntu package. To install type the following command and Press Enter.

root@ubuntu:/# apt-get install lighttpd

Start lighttpd by issuing the command.

root@ubuntu:/# /etc/init.d/lighttpd start

Navigate your browser to http://192.168.0.10/index.lighttpd.html, and you should see the Lighttpd Placeholder page.

The default document root is /var/www/ on Ubuntu, and the configuration file is /etc/lighttpd/lighttpd.conf. Additional configurations are stored in files which are situated in the/etc/lighttpd/conf-available/ directory.

Installing PHP5:

Next is to install PHP 5 on Ubuntu with FastCGI. Ubuntu provides a FastCGI-enabled PHP5 package. We can install by issuing the following command.

root@ubuntu:/#  apt-get install php5-cgi

Configuring Lighttpd and PHP 5:

To enable PHP5 in Lighttpd, you will have to modify the configuration file /etc/php5/cgi/php.ini and uncomment the line cgi.fix_pathinfo=1:

root@ubuntu:/#  vi /etc/php5/cgi/php.ini 

[…]

 ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
 ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
 ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
 ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
 ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
 ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
 ; http://php.net/cgi.fix-pathinfo
 cgi.fix_pathinfo=1
 [...]

To enable the FastCGI configuration (which is stored in /etc/lighttpd/conf-available/10-fastcgi.conf), run the following command:

root@ubuntu:/# lighttpd-enable-mod fastcgi
root@ubuntu:/# lighttpd-enable-mod fastcgi-php

To reload the server for changes to take place, type in the terminal:

root@ubuntu:/#  /etc/init.d/lighttpd force-reload

Testing PHP:

For testing the PHP, Place one PHP file on to the default directory of the Apache.

In the terminal copy/paste the following line:

root@ubuntu:/# vi /var/www/info.php

This will open up a file called phpinfo.php.

 Copy/Paste this line into the info file:

<?php phpinfo(); ?>

 Save and close the file. use Esc + ;wq for saving the file.

 Now open you’re web browser and type the following into the web address:

http://192.168.0.10/info.php

The page look like below:

 

As you see in the screenshot, PHP5 is working fine, and it is working through FastCGI, as shown in theServer API line. If you scroll further down, you will see all modules  that are already enabled in PHP5. Now your web server is ready for working.

You might also like