How to install and configure Lighttpd web server on Ubuntu 20.04 LTS

Learn the steps for installing Lighttpd web server as well as configuring PHP CGI / FPM on Ubuntu 20.04 or 18.04 LTS server running on local machine or cloud hosting.

The Lighttpd web server is one of the best alternatives available to the popular Apache. It is lightweight and can easily be confirmed to deliver static or dynamic content over HTTP and HTTPS. It is not only secure, but also consumes less resources than other web servers. We can use it with PHP with support for FastCGI, SCGI, Auth, Output-Compression, URL-Rewriting and many more. Also, it can be used with Python and other scripting languages ​​or converted to a proxy server through extensions. It is known for its light weight and its ability to handle up to 10,000 parallel connections on a single server.

Here in this guide, we will walk you through the steps to install Lighttpd web server on Ubuntu 20.04 or 18.04 LTS, including how to configure it with PHP and PHP-FPM.

Install Lighttpd web server with PHP-FPM on Ubuntu 20.04 LT

What we need to follow this tutorial is the Ubuntu server, a non-root user with sudo internet access and connection.

1. Update and upgrade the server

Run the update and upgrade system packages commands to ensure that all available packages are up to date. Also, this will force the system to rebuild the repository cache, which will help it grab the latest packages available for installation later in this tutorial.

sudo apt update
sudo apt upgrade

2. Install the Lighttpd web server

To install Lighttpd server on Ubuntu 20.04 or 18.04 LTS Linux, we don’t need any third party repositories, just use the command below, and everything we need to use this web server will be on your desktop or your server.

sudo apt-get install lighttpd

3. Start, activate and check the status of the Lighttpd server

  • Once the installation is complete, start the Lighttpd web server on your Linux server using the command below:
sudo systemctl start lighttpd
  • To make sure it starts automatically with system boot, enable it to do so using the command below
sudo systemctl enable lighttpd
  • Finally, check the status to confirm that everything is working fine
sudo systemctl status lighttpd
  • To check the web server version, you can use this command:
lighttpd -version
  • In case you want to stop or restart it, use these syntaxes:
sudo systemctl restart lighttpd
sudo systemctl stop lighttpd

Check the status of the lighttpd web server

4. Test Lighttpd in a web browser

Before configuring PHP modules for Lighttpd, make sure the web server is running and opening perfectly in navigation. Therefore, open the browser on your local computer or if you are using the CLI server, then on another system. To do this, type the IP address of your system where you installed the web server: http://ip-address

5. Install PHP

On Ubuntu 18.04 LTS, by default, the PHP version you can install is PHP 7.2 while on Ubuntu 20.04 LTS comes with the latest version which is PHP 7.4.3.

(Optional step) If any of you want the latest PHP version on Ubuntu 18.04 LTS, add the following PPA, if not, skip this step:

sudo add-apt-repository ppa:ondrej/php

sudo apt update

Here we are going to install PHP along with other extensions that we would need when setting up different PHP based CMS or web applications. So, on your respective Ubuntu server, run the following command:

sudo apt-get install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip apache2-

In the above command, when installing the above PHP packages, Apache will be installed automatically, so you will need to remove it. Therefore, to stop the system from installing apache2 as a dependency, we used a hyphen at the end of its package name.

6. Activate the FastCGI and FastCGI-PHP modules

Now everything is done, just one last thing before confirming that our PHP works fine with Lighttpd and enables FastCGI extensions.

sudo lighty-enable-mod fastcgi fastcgi-php

Reload the service to apply the changes

sudo service lighttpd force-reload

7. Testing Lighttpd with the PHP Info File

Let’s check if the PHP works correctly with Lighttpd or note. For this, we will create a PHP Info file that will reveal all the information about installed PHP, the web server and activate modules or extensions.

sudo nano /var/www/html/info.php

Type or copy the code below to paste into the created file:

Now save it by pressing Ctrl + X, type Yes, and hit the Enter key.

Now in the browser type: http://server-ip-address/info.php

To note: To replace Server IP address text with the IP address of your server.

The above will display the PHP information:

install PHP CGI and FPM for Lighttpd Check php installation with Lighttpd

If you run the Lighttpd service status command again, this time you will get something like below:

[email protected]:/usr/bin$ systemctl status lighttpd
● lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-09-19 00:06:16 PDT; 8min ago
Process: 43142 ExecStartPre=/usr/sbin/lighttpd -tt -f /etc/lighttpd/lighttpd.conf (code=exited, status=0/>
Main PID: 43160 (lighttpd)
Tasks: 6 (limit: 4624)
Memory: 12.9M
CGroup: /system.slice/lighttpd.service
├─43160 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
├─43163 /usr/bin/php-cgi
├─43164 /usr/bin/php-cgi
├─43165 /usr/bin/php-cgi
├─43166 /usr/bin/php-cgi
└─43167 /usr/bin/php-cgi

Sep 19 00:06:16 ubuntu systemd[1]: Starting Lighttpd Daemon...
Sep 19 00:06:16 ubuntu systemd[1]: Started Lighttpd Daemon.
lines 1-17/17 (END)

So in this way we can install and configure Lighttpd with PHP CGI / FPM. If you want to go further to find out how to install the WordPress content management system on it, check out our tutorial.


Source link

Comments are closed.