How to Install Lighttpd on Ubuntu 18.04

In this article, we will show you how to install Lighttpd web server on an Ubuntu 18.04 VPS with PHP and MariaDB support. Lighttpd is a free, open-source, secure, and standards-compliant web server designed for high-performance environments. Compared to other alternative web-servers, Lighttpd consumes very few resources and capable of serving large loads. It is commonly used for high traffic sites like YouTube.

Let’s begin with the installation.

Prerequisites

  • For the purposes of this tutorial, we will use one of our Ubuntu 18.04 Cloud VPSes.
  • Full SSH root access (our servers come with root access included) or a user with sudo privileges is also required.

Step 1: Connect via SSH and Update the OS

Connect to your server via SSH as the root user using the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

Remember to replace “IP_ADDRESS” and “PORT_NUMBER” with your server’s respective IP address and SSH port number (the default is 22).

Before starting with the installation, you will need to update your OS packages to their latest versions. It’s easy to do, and it won’t take more than a few minutes.

You can do this by running the following command:

apt-get update 
apt-get upgrade

Once the updates are completed, we can move on to the next step.

Step 2: Install Lighttpd

Lighttpd is available within Ubuntu’s default software repositories – this makes installing Lighttpd as simple as installing a package. So, run the following command to install Lighttpd web server:

apt-get install lighttpd

Once the Lighttpd packages have been installed, we can start and enable the service to automatically start at boot.

systemctl start lighttpd
systemctl enable lighttpd

To check the status of the service run the following command:

systemctl status lighttpd

Output:

● lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-07-17 05:42:39 UTC; 38s ago
Main PID: 12965 (lighttpd)
Tasks: 1 (limit: 1114)
CGroup: /system.slice/lighttpd.service
└─12965 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

Jul 17 05:42:39 ubuntu1804 systemd[1]: Starting Lighttpd Daemon...
Jul 17 05:42:39 ubuntu1804 systemd[1]: Started Lighttpd Daemon.

Open your favorite web browser and enter your server’s IP Address. It will be redirected to the default Lighttpd web page.

You’re technically finished with installing Lighttpd, however the next steps are very beneficial to maximizing the potential of your web server.

Step 3: Install MariaDB

If you need MariaDB database support with your Lighttpd web server, we can easily install the MariaDB database server using the following command:

apt-get install mariadb-server

Once the installation has been completed, we can start the service and enable it to start on server boot with the following commands:

systemctl start mariadb
systemctl enable mariadb

We can then check the status of the service by running the following command:

systemctl status mariadb

If everything is fine, the service should already be started, and you should get the following output:

● mariadb.service - MariaDB 10.1.40 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-07-17 05:47:57 UTC; 50s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 14829 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 27 (limit: 1114)
CGroup: /system.slice/mariadb.service
└─14829 /usr/sbin/mysqld

Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: information_schema
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: mysql
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: performance_schema
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: Phase 6/7: Checking and upgrading tables
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: Processing databases
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: information_schema
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: performance_schema
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14866]: OK
Jul 17 05:48:00 ubuntu1804 /etc/mysql/debian-start[14938]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

Step 4: Install PHP 7.2 and PHP Extensions

To install PHP along with all of its necessary extensions, run the following command:

apt-get install php7.2 php7.2-fpm php7.2-mysql php7.2-cli php7.2-curl php7.2-xml php7.2-mbstring php7.2-gd

Once PHP 7.2 has been installed, we need to enable PHP-FPM and FastCGI for Lighttpd.

Open the file /etc/php/7.2/fpm/pool.d/www.conf using your preferred text editor:

nano /etc/php/7.2/fpm/pool.d/www.conf

Find the following line:

listen = /run/php/php7.2-fpm.sock

Replace it with

listen = 127.0.0.1:9000

Save and close the file.

Open the FastCGI configuration file /etc/lighttpd/conf-available/15-fastcgi-php.conf using your preferred text editor:

nano /etc/lighttpd/conf-available/15-fastcgi-php.conf

Find the following lines:

"bin-path" => "/usr/bin/php-cgi",
"socket" => "/var/run/lighttpd/php.socket",

Then replace those values with

"host" => "127.0.0.1",
"port" => "9000",

Save and close the file.

Then, enable the FastCGI and FastCGI-PHP modules with the following commands:

lighty-enable-mod fastcgi
lighty-enable-mod fastcgi-php

Restart Lighttpd and PHP7.2-FPM to apply all the configuration changes:

service lighttpd force-reload
systemctl restart php7.2-fpm

That’s all there is to it – in this tutorial, we learned how to install Lighttpd on an Ubuntu 18.04 Cloud VPS, as well as how to enable MariaDB, PHP and PHP-FPM with FastCGI support in Lighttpd.


We trust that our article today successfully demonstrated how to install Lighttpd on Ubuntu 18.04 in a straightforward and effective manner.

We would now like to hear from you. Is there a detail you think we overlooked or a step you are unsure about that needs further clarification?

Do you have suggestions for other guides or topics you’d like us to explore?

Please feel free to share your thoughts in the comment section below.”

3 thoughts on “How to Install Lighttpd on Ubuntu 18.04”

  1. Please provide lighttpd.conf file examples (that actually work + with entire file contents)
    It’s especially difficult to make lighttpd to handle C compile cgi programs.
    The lighttpd is very sensitive to each character and a text file is quite difficult to configure for the different configurations necessary to make lighttpd work. If you forget a single character or the editor accidentally adds one that’s barely visible, it’s difficult to find

    Reply

Leave a Comment