Lighttpd is a free, open-source, secure and fast web server optimized for high-performance environments. It is a very popular alternative to Nginx and Apache web server for Linux-based operating systems. It is light weight, very small in size and does not require a lot of memory and CPU. It supports FastCGI, mod_rewrite, chroot, OpenSSL and CGI interfaces. Lighttpd is a perfect web server for those who are suffering from load problems.
In this tutorial, we will learn how to install Lighttpd with PHP-FPM and MySQL on Ubuntu 20.04.
- A server running Ubuntu 20.04.
- A static IP address is configured in your server.
- A root password is configured in your server.
Update the System
Before starting, it is recommended to update your system packages to the latest version. You can update them with the following command:
apt-get update -y
Once all the packages are updated, you can proceed to the next step.
By default, Lighttpd is available in the Ubuntu 20.04 default repository. You can install it with the following command:
apt-get install lighttpd -y
Once the installation has been completed, you can verify the status of the Lighttpd with the following command:
systemctl status lighttpd
You should see the following output:
● lighttpd.service - Lighttpd Daemon Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-10-01 05:05:34 UTC; 5s ago Main PID: 1125 (lighttpd) Tasks: 1 (limit: 2353) Memory: 1.4M CGroup: /system.slice/lighttpd.service └─1125 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf Oct 01 05:05:34 ubuntu2004 systemd: Starting Lighttpd Daemon... Oct 01 05:05:34 ubuntu2004 systemd: Started Lighttpd Daemon
Lighttpd all configuration files are available inside /etc/lighttpd directory. You can list them with the following command:
You should get the following output:
Enable PHP and MySQL Support
By default, Lighttpd web server won’t be usable without PHP FastCGI support and MySQL support. So you will need to install necessary packages to enable the PHP and MySQL support.
You can install them with the following command:
apt-get install php php-cgi php-mysql mysql-server -y
Once all the packages are installed, enable the FastCGI module with the following command:
Next, reload the Lighttpd service to apply the configuration.
service lighttpd force-reload
Access Lighttpd Web Interface
Before accessing the Lighttpd web interface, you will need to create a sample info.php file in the default document root directory.
Add the following line:
<?php phpinfo(); ?>
Save and close the file when you are finished.
Now, open your web browser and access the info.php file using the URL http://your-server-ip/info.php. You should see the PHP page:
The above page clearly indicates that PHP and FastCGI support is enabled in the Lighttpd web server.
Congratulations! you have successfully installed Lighttpd web server with PHP and MySQL support. You can now host your own application with Lighttpd web server.