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.
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.
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.
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:
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.
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:
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.
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:
Then run the secure installation script:
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.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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 .
@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.
@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?
@linuxtechjason info.php is owned by root, delete (rm) both files and other users should be able to write.
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?