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.
Requirements
- 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.
Install Lighttpd
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[1]: Starting Lighttpd Daemon...
Oct 01 05:05:34 ubuntu2004 systemd[1]: Started Lighttpd Daemon
Lighttpd all configuration files are available inside /etc/lighttpd directory. You can list them with the following command:
tree /etc/lighttpd/
You should get the following output:
/etc/lighttpd/
├── conf-available
│ ├── 05-auth.conf
│ ├── 05-setenv.conf
│ ├── 10-accesslog.conf
│ ├── 10-cgi.conf
│ ├── 10-dir-listing.conf
│ ├── 10-evasive.conf
│ ├── 10-evhost.conf
│ ├── 10-expire.conf
│ ├── 10-fastcgi.conf
│ ├── 10-flv-streaming.conf
│ ├── 10-no-www.conf
│ ├── 10-proxy.conf
│ ├── 10-rewrite.conf
│ ├── 10-rrdtool.conf
│ ├── 10-simple-vhost.conf
│ ├── 10-sockproxy.conf
│ ├── 10-ssi.conf
│ ├── 10-ssl.conf
│ ├── 10-status.conf
│ ├── 10-userdir.conf
│ ├── 10-usertrack.conf
│ ├── 11-extforward.conf
│ ├── 15-fastcgi-php.conf
│ ├── 90-debian-doc.conf
│ ├── 90-javascript-alias.conf
│ ├── 99-unconfigured.conf
│ └── README
├── conf-enabled
│ ├── 10-fastcgi.conf -> ../conf-available/10-fastcgi.conf
│ ├── 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf
│ └── 90-javascript-alias.conf -> ../conf-available/90-javascript-alias.conf
└── lighttpd.conf
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:
lighty-enable-mod fastcgi
lighty-enable-mod fastcgi-php
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.
nano /var/www/html/info.php
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.
Conclusion
Congratulations! you have successfully installed Lighttpd web server with PHP and MySQL support. You can now host your own application with Lighttpd web server.