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.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.