Tutorial

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

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

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

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:

http://198.199.50.50/index.lighttpd.html

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_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
#       "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

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
8 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Still Have same problem on every Server I setup . How make web site I add running and point to my server . It’s about DNS resolving it’s bit confuse what setting Have to change on my domain registrar I already tried A record to point to my VPS server IP but it’s shown Default Lighttpd page While I add files to /var/www/domain.com/html/index.html noting changed but if I point on the browser to http://VPS_IP_Address/domain.com/html/ It show me the webpage I uploaded this is my site uploaded files directory /var/www/domain.com/html/index.html What Should I add after to make Lighttpd load current files and recognize where is my domains files it is .

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
January 28, 2014

@shashank.madarapu: Try running the following command—does that fix it?<pre>sudo apt-get update</pre>

sudo aptitude install php5-cgi php5-mysql is giving some 404 not found on mirror.digitalocean.com error

There is an open project LLMP(http://llmp.org), especially for VPS, the source is at https://github.com/jiangge/llmp . hope you guys like it.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 8, 2013

@ruslan.tarakanov This article uses php5-cgi in the “Installing PHP” section. You don’t have to install php5-fpm if you have php5-cgi installed.

What about php-frm?

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 7, 2013

@linuxtechjason info.php is owned by root, delete (rm) both files and other users should be able to write.

After running:

nano /var/www/info.php

And editing the new file to show the phpinfo, it wouldn’t save saying I didn’t have the privileges. I redid the file this time using sudo and it worked.

I thought that it was odd that it didn’t let me create the file considering that it’s the /var/www directory so I ran a ‘ls -a’ on it and got:

total 8 -rw-r–r-- 1 root root 3562 Jul 6 22:08 index.lighttpd.html -rw-r–r-- 1 root root 20 Jul 6 22:16 info.php

Should this area be writeable by non-root users or not?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.