Share your love
Install and Configure Lighttpd on Ubuntu 22.04
This guide intends to teach you to Install and Configure Lighttpd Web Server on Ubuntu 22.04.
Lighttpd (pronounced “Lighty”) is high-performance web server software designed for speed, security, and flexibility. It can be an excellent option for environments with minimal resources, dynamic websites, or diverse applications.
It’s also suitable for both the Windows and Linux Operating Systems.
Steps To Install and Configure Lighttpd on Ubuntu 22.04
To install Lighttpd, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, follow our guide on Initial Server Setup with Ubuntu 22.04.
Now follow the steps below to complete this guide.
Set up Lighttpd Web Server on Ubuntu 22.04
Lighttpd packages are available in the default Ubuntu repository. First, update your local package index with the following command:
sudo apt update -y
Then, use the following command to install Lighttpd:
sudo apt install lighttpd -y
Manage Lighttpd Web Server
Start and enable your Lighttpd service to start on boot:
# sudo systemctl start lighttpd
# sudo systemctl enable lighttpd
Verify that Lighttpd is active and running on Ubuntu 22.04:
sudo systemctl status lighttpd
In your output you will see:
Output
● lighttpd.service - Lighttpd Daemon
Loaded: loaded (/lib/systemd/system/lighttpd.service; enabled; vendor pres>
Active: active (running) since Mon 2023-04-03 13:38:30 UTC; 24s ago
Main PID: 2492 (lighttpd)
Tasks: 1 (limit: 4575)
Memory: 972.0K
CPU: 358ms
CGroup: /system.slice/lighttpd.service
└─2492 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
...
To check which Lighttpd version is installed on your server, run the following command:
lighttpd -v
Output
lighttpd/1.4.63 (ssl) - a light and fast webserver
Install MariaDB support for Lighttpd on Ubuntu 22.04
At this point, you need to install the dependencies and required packages with the following command:
sudo apt install curl software-properties-common dirmngr ca-certificates apt-transport-https -y
You can import MariaDB by using the MariaDB bash script designed for Linux distributions such as Ubuntu that are supported, given they are long-term releases. To do this, run the following command:
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.11
Now update your local package index again:
sudo apt update
At this point, you can use the following command to install MariaDB on your server:
sudo apt install mariadb-server mariadb-client -y
Verify your MariaDB installation by checking its version:
mariadb --version
Output
mariadb Ver 15.1 Distrib 10.11.2-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Manage MariaDB Service
Now you need to start and enable your MariaDB service to start on boot with the following commands:
# sudo systemctl start mariadb
# sudo systemctl enable mariadb
Confirm that your MariaDB is active and running on Ubuntu 22.04:
sudo systemctl status mariadb
Output
● mariadb.service - MariaDB 10.11.2 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Mon 2023-04-03 13:42:39 UTC; 1min 1s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 9931 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 9 (limit: 4575)
Memory: 78.5M
CPU: 669ms
CGroup: /system.slice/mariadb.service
└─9931 /usr/sbin/mariadbd
...
MySQL Security Script
At this point that you have MariaDB installed on your server you need to secure your MariaDB by running a security script:
sudo mysql_secure_installation
Output
Enter current password for root (enter for none):
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Now you can use the command below to access your MariaDB shell on Ubuntu 22.04:
sudo mysql -u root -p
Output
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 39
Server version: 10.11.2-MariaDB-1:10.11.2+maria~ubu2204 mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Once you have finished, you can proceed to the next step.
Install PHP and PHP-FPM with FastCGI
To enable PHP-FPM with FastCGI support, first, you need to install PHP along with the necessary extensions for Lighttpd on Ubuntu 22.04.
sudo apt install php php-cgi php-cli php-fpm php-curl php-gd php-mysql php-mbstring zip unzip -y
Confirm your PHP installation by checking its version:
php --version
Output
PHP 8.1.2-1ubuntu2.11 (cli) (built: Feb 22 2023 22:56:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2-1ubuntu2.11, Copyright (c), by Zend Technologies
Enable PHP-FPM Module
To enable the PHP-FPM module, edit the following file with your favorite text editor. Here we use vi editor.
sudo vi /etc/php/*/fpm/pool.d/www.conf
In the file, Find the following line:
listen = /run/php/php*-fpm.sock
And change it to the line below:
listen = 127.0.0.1:9000
When you are done, save and close the file.
To list all loaded PHP Modules, run the following command :
php -m
Enable FastCGI Module
To enable the FastCGI module, open the following file with your favorite text editor, here we use vi:
sudo vi /etc/lighttpd/conf-available/15-fastcgi-php.conf
Find the following lines under the FastCGI.server:
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/run/lighttpd/php.socket",
Replace the lines with the following:
"host" => "127.0.0.1",
"port" => "9000",
When you are done, save and close the file.
Test Lighttpd Web Server
At this point, you can test your installation and configuration by creating a simple PHP info file to show the information about the PHP version installed, the web server running on our system, and the PHP extensions.
To do this, you can use the command below:
sudo vi /var/www/html/phpinfo.php
Add the following content to the file:
<?php
phpinfo();
?>
When you are done, save and close the file.
Next, you need to set the correct permission and ownership:
# sudo chown -R www-data:www-data /var/www/html/
# sudo chmod -R 755 /var/www/html/
Then, you need to edit the Lighttpd config file on Ubuntu 22.04 and add the module mod_fastcgi to your server configuration.
sudo vi /etc/lighttpd/lighttpd.conf
Add mod_fastcgi to the server.modules section:
server.modules = (
"mod_indexfile",
"mod_access",
"mod_alias",
"mod_redirect",
"mod_fastcgi",
)
Next, add the following contents just below the file above to configure fastcgi.server.
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))
Finally, restart Lighttpd to apply the changes:
sudo systemctl restart lighttpd
Now you can access your PHP Info page by typing your server’s IP address in your web browser followed by /phpinfo.php:
http://your-server-ip/phpinfo.php
You will see the following screen:
From there, you will see working information on PHP, PHP-FPM, and MySQL with lots of other modules that are already enabled.
For more information, you can visit the Lighttpd Documentation page.
Conclusion
At this point, you have learned to Install and Configure Lighttpd Web Server on Ubuntu 22.04.
Hope you enjoy it. You may be interested in these articles: