Setting up Lighttpd, a lightweight web server, is straightforward. Here’s a step-by-step guide to help you install and configure it on a Linux-based system (like Ubuntu or CentOS).
sudo apt update
sudo apt install lighttpd
sudo yum install epel-release
sudo yum install lighttpd
Once the installation is complete, start the Lighttpd service and enable it to start at boot.
sudo systemctl start lighttpd
sudo systemctl enable lighttpd
If your system has a firewall enabled (like ufw
on Ubuntu or firewalld
on CentOS), you need to allow traffic on HTTP (port 80) or HTTPS (port 443).
sudo ufw allow 'WWW Full'
sudo ufw reload
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Now, check if Lighttpd is running by opening a web browser and visiting:
http://<your-server-ip>
You should see the Lighttpd default welcome page.
The main configuration file for Lighttpd is located at /etc/lighttpd/lighttpd.conf
. You can modify it to fit your needs.
For example, to configure the document root:
sudo nano /etc/lighttpd/lighttpd.conf
server.document-root = "/var/www/html"
sudo systemctl restart lighttpd
If you want to use PHP with Lighttpd, you can enable it as follows:
sudo apt install php-cgi
sudo apt install lighttpd-mod-fastcgi
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
sudo systemctl restart lighttpd
sudo yum install php-cli php-fpm
sudo nano /etc/lighttpd/conf.d/fastcgi.conf
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))
sudo systemctl restart lighttpd
Create a PHP test file to ensure PHP is working:
sudo nano /var/www/html/info.php
Add the following code:
<?php phpinfo(); ?>
Visit http://<your-server-ip>/info.php
in a browser to verify PHP is functioning correctly.