Lighttpd (pronounced ”lighty”) is open-source, free, and high-speed webserver. Lighttpd is optimized for a speed-critical environment. It is secure, flexible, and needs low memory which makes that popular among other web servers. Its small size is 1MB and has low CPU and RAM usage. Using Lighttpd, you are allowed to host web applications written in other programming languages using FastCGI, SCGI, and CGI interfaces. Lighttpd is under the BSD license and supports TLS/SSL using OpenSSL. Join us with the Tutorial Installing Lighttpd with PHP, MariaDB, and free SSL on Debian 10. To buy your own Linux VPS, check the perfect packages of Eldernode and purchase one.
Table of Contents
How to Install Lighttpd with PHP, MariaDB, and free SSL on Debian 10
To let this tutorial work better, please consider the below Prerequisites:
A non-root user with sudo privileges.
To set up, follow our Initial Setup with Debian 10.
Note: In this guide, the domain name is assumed as ”example.com”. For your case, remember to replace example.com in all fill names and configuration settings with your own domain name.
Install Lighttpd with PHP, MariaDB, and free SSL on Debian 10
If you are looking for a solution to get rid of load problems on your server, Lighttpd could be n ideal choice. It supports using chroot and mod_rewrite. Let’s get started by updating your system. Use the commands below to do this. Restart your server to let the changes apply when you are finished.
apt-get update -y
apt-get upgrade -y
How to install Lighttpd
Since Lighttpd is available in the Debian 10 default repository, run the following command to install it.
apt-get install lighttpd -y
You can start the Lighttpd service when the installation is completed. To enable it to start after system reboot, type:
systemctl start lighttpd
systemctl enable lighttpd
Also, you can check the status of Lighttpd by running the command below:
systemctl status lighttpd
How to install MariaDB server
Use the following command to install the MariaDB server.
apt-get install mariadb-server mariadb-client -y
You should secure the MariaDB after completing the installation. To secure it, type:
mysql_secure_installation
How to install PHP and PHP-FPM
In this step, you will install PHP, PHP-FPM, and FastCGI to your system. Since Debian 10 ships with PHP version 7.3 by default. Use the command below to install:
apt-get install php php-cgi php-fpm php-mysql -y
When you are ensured of installing the packages, edit the pho.ini file, and set cgi.fix_pathinfo to 1 by running the following command:
nano /etc/php/7.3/fpm/php.ini
Then, change the following line:
cgi.fix_pathinfo=1
Now, you can save and close the file.
PHP point to the UNIX socket /var/run/php/php7.3-fpm.sock by default. At this point, you should configure the PHP-FPM pool to set PHP listens to the TCP socket. Do this by editing /etc/php/7.3/fpm/pool.d/www.conf file:
nano /etc/php/7.3/fpm/pool.d/www.conf
Then, find the line below:
listen = /run/php/php7.3-fpm.sock
Now, replace it with the following line:
listen = 127.0.0.1:9000
Once, you have done the above steps, dave and close the file. To restart the PHP-FPM service to apply the configuration changes, type:
systemctl restart php7.3-fpm
Now you can modify the 15-fastcgi-php.conf file using the command below:
nano /etc/lighttpd/conf-available/15-fastcgi-php.conf
Again, find the following lines:
"bin-path" => "/usr/bin/php-cgi", "socket" => "/var/run/lighttpd/php.socket",
To replace them with the below ones:
"host" => "127.0.0.1", "port" => "9000",
Now, you can save and close the file when all is done successfully. To enable FastCGI and FastCHI-PHP module, run:
lighty-enable-mod fastcgi lighty-enable-mod fastcgi-php
Then, to apply the changes you have made, restart the Lighttpd by:
systemctl restart lighttpd
How to create a Lighttpd Virtual host
To create a new virtual host file to test PHP with Lighttpd, type:
nano /etc/lighttpd/conf-available/example.com.conf
And, add the lines below:
$HTTP["host"] == "www.example.com" { server.document-root = "/var/www/html/" server.errorlog = "/var/log/lighttpd/example.com-error.log" }
Now, you can save and close the file. Use the command below to enable the Virtual host.
ln -s /etc/lighttpd/conf-available/example.com.conf /etc/lighttpd/conf-enabled/
Then, create a sample index.php file in the Lighttpd document root directory with the command below:
nano /var/www/html/index.php
Add the following line:
<?php phpinfo(); ?>
Save and close the file. Run the following command to change the ownership of the Lighttpd document root directory to www-data.
chown -R www-data:www-data /var/www/html/
And finally, to restart the Lighttpd service type the below command. It will apply the configuration changes:
systemctl restart lighttpd
How to secure Lighttpd with Let’s Encrypt free SSL
To finish this step, you need to install the Certbot tool first to secure your web server with Let’s Encrypt. Since the latest version of Certbot is not available in the Debian 10 default repository, you need to add the Certbot repository. Run the following command to do this:
apt-get install software-properties-common add-apt-repository ppa:certbot/certbot
Then, you should update the repository and install Certbot. So, type:
apt-get update -y apt-get install certbot -y
At this point, you need to create a Let’s Encrypt certification with the command below:
certbot certonly --webroot -w /var/www/html/ -d www.example.com
Next, you will be asked to provide your email address and accept the term of license as shown below:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator webroot, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y
Next, you will see the below output when downloading the certificates is finished successfully.
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2019-12-06. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
It is time to combine both the certificate and private key in one file. So, run:
cat /etc/letsencrypt/live/example.com/cert.pem /etc/letsencrypt/live/example.com/privkey.pem > /etc/letsencrypt/live/example.com/web.pem
Since you need to edit the Lihghttpd virtual host file and define the Let’s Encrypt SSL certificate path. Use the following command to do this:
nano /etc/lighttpd/conf-enabled/example.com.conf
Now you can save and close the file when you are finished. Again, you should restart the Lighttpd service to apply the configuration changes:
systemctl restart lighttpd
How to access Lighttpd web interface
Till this step, Lighttpd is installed and configured with PHP and PHP-FPM support. So, let’s test it now. Open your web browser and type the URL https://www.example.com. Then, you will be redirected to the following page:
That’s that! In this way, you make sure that PHP is working well with FastCGI.
Conclusion
In this article, you read the Tutorial Installing Lighttpd with PHP, MariaDB, and free SSL on Debian 10. If you have carefully passed the steps of this guide, you can now enjoy hosting your own web server.