Setting up a LLMP Stack (Linux, Lighttpd, MySQL, PHP5) on Ubuntu 8.10
I have wanted to switch from Apache to Lighttpd for my web server for quite a while. In this article I am going to go over my installation of Lighttpd, MySQL with phpmyadmin, and PHP5 on Ubuntu 8.10. In a future article I will go over setting up my sites to run on Lighttpd. I am running a 256mb ‘slice’ from Slicehost. For the basic setup of my slice I followed Slicehost’s Ubuntu Intrepid Setup Tutorial.
1. Install Lighttpd
After you installed Lighttpd open up your web browser and point it to your IP address. You should see the Lighttpd placeholder page.
2. Install MySQL & phpmyadmin
During the MySQL you will be asked to set your MySQL root password. You may also be asked during the phpmyadmin install what web server you want phpmyadmin to use. Select Lighttpd.
3. Install PHP5 with MySQL Support
4. Setting up Lighttpd & PHP
PHP is not enabled by default in Lighttpd, so we need to set that up now. We are going to edit the php.ini file.
and add the following line to the end of the file:
Now we need to enable the fastcgi module in Lighttpd. While we are here we are going to enable Lighttpd’s mod_rewrite since we are going to use that later.
Look for the line “server.modules”. Remove the “#” from the line “mod_rewrite”, and on a new line add “mod_fastcgi”,. It should look something like this:
server.modules = ( "mod_access", "mod_alias", "mod_accesslog", "mod_compress", "mod_fastcgi", "mod_rewrite", # "mod_redirect", # "mod_evhost", # "mod_usertrack", # "mod_rrdtool", # "mod_webdav", # "mod_expire", # "mod_flv_streaming", # "mod_evasive" )
Before closing the file we need to add one more thing to it. At the end of the file add the following:
fastcgi.server = ( ".php" => (( "bin-path" => "/usr/bin/php5-cgi", "socket" => "/tmp/php.socket", "max-procs" => 1, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "4", "PHP_FCGI_MAX_REQUESTS" => "1000" ), )))
Adding this to the lighttpd.conf file does two things. The first is it tells Lighttpd how to handle the PHP requests, and the second is it controls how many FastCGI processes are running to handle the PHP requests. We now need to restart Lighttpd for these settings to take effect.
5. Testing everything out
Now lets test your setup and make sure that it worked.
Create a file, info.php so that we can test our install and make sure that everything works.
Add the following lines of code:
Now pull up our new page: http://192.168.1.101/info.php in your browser. You should see that you are running PHP5 using FastCGI by looking at the “Server API” line. If you scroll down you will also see that MySQL is supported.
That is it.. Your LLMP install is now complete! Stay tuned for more articles on how to setup your websites using Lighttpd as your web server. Because MySQL does not come optimized, please follow the MySQL part of the tutorial on Configuring a lightweight Apache / MySQL install on Debian/Ubuntu.