We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install the LLMP stack (Linux, Lighttpd, MySQL and PHP) on Ubuntu 12.04

Posted Jul 2, 2013 32.7k views MySQL PHP Ubuntu

About Lighttpd

Lighttpd is an open source web server that powers numerous websites in the world that focuses on increased performance and a light memory footprint. Together with the very popular MySQL database server and the PHP server side dynamic scripting language, Lighttpd is a strong alternative to the more resource intensive, but otherwise very powerful, LAMP stack.

This tutorial will show you how to install Lighttpd, PHP and MySQL in order to quickly get you up and running with your cloud server. For this, it assumes that you are already running an Ubuntu VPS with root privileges. To find out more information about what this means, you can consult this tutorial explaining how to get started.

Installing Lighttpd

You can install Lighttpd by running the following command:

sudo aptitude install lighttpd

Now if you point your browser to your IP address, you should already see the cloud server's document root folder or, if you add index.lighttpd.html after it, you should see the Lighttpd default welcome page:

On this page, you'll also get some additional information about where some of the more useful Lighttpd configuration stuff is, such as CGI scripts, log files, etc. If you are used to Apache, you'll be glad to know that the default cloud server's document root is also in /var/www (with a default directory index set to index.html) and the configuration files can be found in /etc/lighttpd.

The main configuration file for Lighttpd is /etc/lighttpd/lighttpd.conf. If you open it, you will see some important directives:

nano /etc/lighttpd/lighttpd.conf

Under the following block you can see the modules loaded by Lighttpd:

server.modules = (
#       "mod_rewrite",

Here you can specify other modules you want loaded by the VPS. But be careful as the order in which they are loaded is important. Review this readme page for more information.

Below, you can configure the default document root for the cloud server (if /var/www is not good for you), the server user and group that will operate Lighttpd, the index files and other settings.

Installing PHP

Lighttpd requires the PHP FastCGI in order to set up PHP. Additionally, you need to also install the php-mysql package in order to be able to work with MySQL. To install both of them, run the following command:

sudo aptitude install php5-cgi php5-mysql

To have PHP interact with the VPS, enable the module using the following two commands:

sudo lighttpd-enable-mod fastcgi
sudo lighttpd-enable-mod fastcgi-php

Similar to Apache, these commands will create a symlink (like a shortcut) from the /etc/lighttpd/conf-enabled/ folder files to the /etc/lighttpd/conf-available/ folder files.

Now you can go ahead and reload Lighttpd for the changes to take effect:

sudo service lighttpd force-reload

Like always, to test if php is working, create an empty php file and call the phpinfo() function from it. Create the file:

nano /var/www/info.php

And paste the following code:

<?php phpinfo(); ?>

Save, exit the file and point to it in the browser. You should get all the information about the PHP installed on your VPS, its modules etc. You should also see that the php-mysql module is installed so you are ready to proceed with installing MySQL itself.

Installing MySQL

Finally, install the MySQL database server; run the following command:

sudo aptitude install mysql-server

You will be then asked to provide a password for the MySQL root user. Activate it with the following command:

sudo mysql_install_db

Then run the secure installation script:

sudo /usr/bin/mysql_secure_installation

Provide the root user password you've just set (or leave empty if you have not set one) and then you will be asked if you want to change that password. Feel free to choose No and continue.

After this, it's recommended to choose Yes to the following questions as they deal with removing some test databases and users and most importantly, removing privileges over your databases for anonymous users.

And then you are done! You can start using your new LLMP based web server.

Article Submitted by: Danny


Creative Commons License