How to Install Lighttpd on CentOS 7

In this tutorial, we will show you how to install Lighttpd on a Centos 7 VPS as well as set up MariaDB and PHP.

Lighttpd is a secure, open-source, fast, flexible and more optimized web server. Lighttpd has a high-speed infrastructure that allows for better performance with the same hardware when compared to other alternative web-servers. Lighttpd supports the FastCGI, SCGI and CGI interfaces and allows web applications that are written in any programming language to be used with the server.

Lighttpd’s FastCGI can be configured to support PHP with opcode caches and also has received attention within the Perl, Python, and Ruby communities.

Let’s get started with the installation.

Prerequisites

  • For the purposes of this tutorial, we will use a Centos 7 VPS.
  • Full SSH root access or a user with sudo privileges is also required.

Step 1: Connect via SSH and Update

Connect to your server via SSH as the root user using the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

Remember to replace “IP_ADDRESS” and “PORT_NUMBER” with your server’s respective IP address and SSH port number.

Before starting with the installation, you will need to update your system packages to their latest versions. It’s easy to do, and it won’t take more than a few minutes.

You can do this by running the following command:

sudo yum update

Once the updates are completed, we can move on to the next step.

Step 2: Install Lighttpd

Before installing Lighttpd we need to enable the EPEL repository on our system and update our software packages once again using the following commands:

yum -y install epel-release
yum -y update

Once the EPEL repository has been enabled, we can install the Lighttpd web server by running the following command:

yum install lighttpd

Once the Lighttpd packages have been installed, we can start and enable the service to automatically start at boot.

systemctl start lighttpd
systemctl enable lighttpd

To check the status of the service run the following command:

systemctl status lighttpd

If everything is fine you should get the following output:

● lighttpd.service - Lightning Fast Webserver With Light System Requirements
       Loaded: loaded (/usr/lib/systemd/system/lighttpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Tue 2019-07-02 12:52:11 CDT; 2s ago
 Main PID: 11445 (lighttpd)
      CGroup: /system.slice/lighttpd.service
       └─11445 /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf

If you see any network errors in the status, open the /etc/lighttpd/lighttpd.conf configuration file and change the line that says server.use-ipv6 from enable to disable.

Now, we need to restart the Lighttpd web server and everything should work fine.

systemctl restart lighttpd

Next, you can open your favorite web browser and enter your server’s IP Address. It will load the default Lighttpd web page.

The default document root for Lighttpd is /var/www/lighttpd/ and the main configuration file is at /etc/lighttpd/lighttpd.conf.

Step 3: Installing MariaDB support for Lighttpd

If you need database support with your Lighttpd setup, this step can be very useful.

We can install the MariaDB database server using the following commands:

yum -y install mariadb mariadb-server

Once the installation has been completed, we can start and enable the service with these following commands:

systemctl start mariadb.service
systemctl enable mariadb.service

We can then check the status of the service by running the following command:

systemctl status mariadb.service

If everything is fine you should get the following output:

● mariadb.service - MariaDB database server
       Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
       Active: active (running) since Tue 2019-07-02 11:44:39 CDT; 1h 29min ago
   Main PID: 776 (mysqld_safe)
      CGroup: /system.slice/mariadb.service
     ├─ 776 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
      └─1076 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql

We can connect to the MariaDB command line with the following command:

mysql -u root -p

If you logged in successfully, you will get the following output:

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.60-MariaDB MariaDB Server

We have successfully installed and connected to the MariaDB database server. You can type ‘exit’ to exit the interface.

Step 4: Installing PHP and PHP-FPM with FastCGI

To install PHP along with all of its necessary extensions, run the following command:

yum -y install php php-mysqlnd php-pdo php-gd php-mbstring

Once PHP has been installed we can enable PHP-FPM and FastCGI support for Lighttpd by running the following command:

yum -y install php-fpm lighttpd-fastcgi

Next, open the following file /etc/php-fpm.d/www.conf using your preferred text editor. For our tutorial, we’ll be using ‘nano’:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
nano /etc/php-fpm.d/www.conf

Once the file is open, change the next two lines:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;    will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd

Now, we can start PHP-FPM service and enable it to start automatically at boot with the following commands:

systemctl start php-fpm.service
systemctl enable php-fpm.service

To check the status of the service, run this:

systemctl status php-fpm.service

You should get the following output:

● php-fpm.service - The PHP FastCGI Process Manager
       Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
       Active: active (running) since Tue 2019-07-02 13:30:09 CDT; 10s ago
  Main PID: 11571 (php-fpm)
       Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
       CGroup: /system.slice/php-fpm.service

That’s all there is to it – in this tutorial, we learned how to install Lighttpd on Centos 7, as well as how to enable MariaDB, PHP and PHP-FPM with FastCGI in Lighttpd.

Of course, you don’t have to install Lighttpd on CentOS 7 if you use one of our CentOS VPS Hosting Services, in which case you can simply ask our expert Linux admins to install and set up Lighttpd on CentOS 7 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to install Lighttpd on CentOS 7,  please share it with your friends on the social networks using the share shortcuts below, or simply leave a comment down in the comments section. Thanks.

Leave a Comment