DebianDebian Based

How To Install Lighttpd on Debian 12

Install Lighttpd on Debian 12

In this tutorial, we will show you how to install Lighttpd on Debian 12. In the realm of web servers, efficiency and performance are paramount. Whether you’re a seasoned developer or a newbie, having a fast and reliable web server is crucial. Lighttpd, often fondly referred to as “lighty,” is an open-source web server that has earned its reputation for being swift, resource-efficient, and easy to configure.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Lighttpd web server on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Lighttpd.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Lighttpd on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing Dependencies.

Make sure you have the necessary packages installed, such as ‘wget’ for downloading files and ‘build-essential’ for compiling source code:

sudo apt install wget build-essential

Step 3. Installing Lighttpd on Debian 12.

Now download the latest stable release Lighttpd from the official page using wget command:

wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.72.tar.gz

Extract the tarball you just downloaded:

tar -xzvf lighttpd-1.4.72.tar.gz

Change to the extracted directory:

cd lighttpd-1.4.72

Configure the installation:

./configure

Compile and install Lighttpd:

make
sudo make install

Verify the installation to ensure everything went smoothly:

lighttpd -v

Step 4. Lighttpd Configuration.

Now that Lighttpd is installed, it’s time to configure it to serve your websites. Let’s go through the necessary steps:

Start by creating a configuration file in the ‘/etc/lighttpd/‘ directory. You can use a text editor like Nano or Vim. Here’s an example using Nano:

sudo nano /etc/lighttpd/lighttpd.conf

Inside the configuration file, you can set up server modules and define various settings. For example, to configure a basic Lighttpd server, you can add the following lines:

server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
)
server.document-root = "/var/www/html"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"

Before proceeding, it’s crucial to verify your configuration to avoid potential issues down the road:

lighttpd -t -f /etc/lighttpd/lighttpd.conf

With your configuration in place and verified, start the Lighttpd service:

sudo systemctl start lighttpd
sudo systemctl enable lighttpd

Step 5. Configuration PHP 8 on Lighttpd.

Before proceeding, make sure you have PHP 8 installed on your server. You can typically install it using the package manager for your operating system.

Lighttpd communicates with PHP via FastCGI, so you need to enable the FastCGI module and configure it to work with PHP:

  1. Enable the FastCGI module: Check if the FastCGI module is already enabled in your Lighttpd configuration file. Typically, the configuration file is located at /etc/lighttpd/lighttpd.conf. Look for the following line:

server.modules += ( "mod_fastcgi" )
  1. Configure FastCGI for PHP: Add a configuration block for FastCGI to your Lighttpd configuration file. This block defines how Lighttpd communicates with PHP:
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php/php8.0-fpm.sock", # Path to the PHP-FPM socket
"broken-scriptfilename" => "enable"
))
)

Replace /var/run/php/php8.0-fpm.sock with the correct path to your PHP-FPM socket. You can find this information in your PHP-FPM configuration file, typically located at /etc/php/8.0/fpm/pool.d/www.conf.

After making changes to your Lighttpd and PHP configurations, restart both services for the changes to take effect:

sudo systemctl restart lighttpd
sudo systemctl restart php8.0-fpm

To verify that PHP 8 is correctly configured with Lighttpd, create a simple PHP test file in your web server’s document root. For example, create a file named test.php with the following content:

<?php
phpinfo();
?>

Save this file in your document root (e.g., /var/www/html/test.php) and then access it through a web browser by navigating to http://your_server_ip/test.php. You should see a PHP information page displaying details about your PHP configuration.

Congratulations! You have successfully installed Lighttpd. Thanks for using this tutorial to install the latest version of Lighttpd web server on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Lighttpd website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button