26.1 C
Senior Writer and partner

How to install lighttpd on FreeBSD 12?

Hi, folks. Thanks for staying another day. In this post, you will learn how to install Lighttpd on FreeBSD 12. Of course, we will include PHP support. So let’s go for it.

Lighttpd is a “secure, fast, compatible and very flexible” web server optimized for high-performance environments. It consumes very few resources compared to other web servers and especially fast for running AJAX applications. It is also open source and uses a BSD license and works on UNIX-like systems, such as Linux or BSD.

Generally, Lighttpd is used in servers where maximum performance is needed even at the sacrifice of some features. Despite this, Lighttpd is always a good alternative to the popular Apache and Nginx.

Install Lighttpd on FreeBSD 12

For this tutorial, you need to have sudo enabled. For this, I recommend you to read our post about it:

- Advertisement -

How to enable sudo on FreeBSD 12?

Before starting with the tutorial, it is recommended to update the system completely, to do it, open a terminal emulator or connect to your server using SSH and write:

:~$ sudo pkg update

Now we can really get started with the tutorial.

1.- Install Lighttpd

Lighttpd is available from the official FreeBSD repositories. Therefore, the installation will not result in problems. So to install it, use the following command:

:~$ sudo pkg install lighttpd
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01    
Fetching packagesite.txz: 100%    6 MiB  53.0kB/s    02:02    
Processing entries: 100%
FreeBSD repository update completed. 31558 packages processed.
All repositories are up to date.
The following 4 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
lighttpd: 1.4.54
lua52: 5.2.4
libedit: 3.1.20191211,1
pcre: 8.43_2

Number of packages to be installed: 4

The process will require 10 MiB more space.
2 MiB to be downloaded.

Proceed with this action? [y/N]:

1.- Install Lighttpd on FreeBSD 12
1.- Install Lighttpd on FreeBSD 12

After entering the password, the download will start.

For now, we won’t start the Lighttpd service because there are some settings we have to make first.

2.- Install PHP on FreeBSD 12

Of course, if we install only Lighttpd we won’t be able to run any web application made with PHP. This brings a consequence that the functionality would decay. So let’s install it:

:~$ sudo pkg install php74 mod_php74 php74-mbstring php74-zlib php74-curl php74-gd php74-json

2.- Install PHP on FreeBSD 12
2.- Install PHP on FreeBSD 12

I took the opportunity to install some extra modules.

Now we have to make some modifications to PHP so that it can work without problems with Lighttpd.

First open the file /usr/local/etc/php-fpm.d/www.conf and make these changes.

Find the line:

listen =

And exchange it for this one:

listen = /var/run/php-fpm.sock

Then, locate the following lines and decomment them:

;listen.owner = www
;listen.group = www
;listen.mode = 0660

Looking like this in the picture:

3.- Configuring PHP to support Lighttpd
3.- Configuring PHP to support Lighttpd

So, save the changes and close the file.

Now it is necessary to create a new php.ini file. During the installation, two example files are created that we have to use depending on the function of our computer. These files are php.ini-production and php.ini-development.

So we have to choose one, in my case, I will assume that FreeBSD 12 is for production, so that will be my choice.

Note: it is likely that if you choose the other one this tutorial will work as well.

So, we copy the example file as php.ini:

:~$ sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

And we edited the file in question:

:~$ sudo nano /usr/local/etc/php.ini

And locate the line:


And exchange it for this one:


4.- Editing the PHP configuration file
4.- Editing the PHP configuration file

Again, save the changes and close the file.

Now we can start and enable the PHP-fpm service.

:~$ sudo sysrc php_fpm_enable=yes
php_fpm_enable: -> yes
:~$ sudo service php-fpm start
Performing sanity check on php-fpm configuration:
[20-Feb-2020 14:50:21] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
Starting php_fpm.

3.- Configuring Lighttpd on FreeBSD 12

In this section of the tutorial, we have to make some configurations to Lighttpd so that it can work with PHP.

So, open the file /usr/local/etc/lighttpd/modules.conf

:~$ sudo nano /usr/local/etc/lighttpd/modules.conf

And uncomment the line:

include "conf.d/fastcgi.conf"

5.- Configuring Lighttpd to work with PHP
5.- Configuring Lighttpd to work with PHP

What this does is to include the fastcgi module which is the one we will use for Lighttpd to process PHP.

At the end of that same file, add the following:

fastcgi.server += ( ".php" =>
                "socket" => "/var/run/php-fpm.sock",
                "broken-scriptfilename" => "enable"

6.- Editing the Lighttpd configuration file
6.- Editing the Lighttpd configuration file

Save the changes and close the editor.

Before starting the service, edit the main Lighttpd configuration file and uncomment the line:

:~$ sudo nano /usr/local/etc/lighttpd/lighttpd.conf
server.bind = "localhost"

So, you can save the changes and close the file.

If your server uses IPv6, you have to locate this line as well and leave it as it is:

server.use-ipv6 = "enable"

And at the end of the file comment on this line:

$SERVER["socket"] == "" { }

Remember, this is only if your server uses IPv6, if not omit this.

Now, enable and start the Lighttpd service:

:~$ sudo sysrc lighttpd_enable=yes
lighttpd_enable: -> yes
:~$ sudo service lighttpd start

So, we are going to test it.

4.- Testing Lighttpd and PHP on FreeBSD 12

Now we’re going to try everything we’ve done. The best way is to create a PHP file for the server to run.

First, create the folder where Lighttpd will look for the web files. In other words, the root directory.

:~$ sudo mkdir -p /usr/local/www/data

And now create a PHP file called test.php and add the following:

:~$ sudo nano /usr/local/www/data/test.php

Save the changes and close the file.

Now open your favorite web browser and go to http://server-ip/test.php and you will see the following:

7.- Lighttpd and PHP working on FreeBSD 12
7.- Lighttpd and PHP working on FreeBSD 12

So, that is it. If you want to use a database management program in FreeBSD 12, you can check these posts:

How to install PostgreSQL on FreeBSD 12?

How to install SQLite on FreeBSD 12?

So, enjoy it.


Lighttpd is less popular than Apache and Nginx, that’s for sure, but it’s quite useful on small servers or when we want maximum performance in a web application. Today thanks to this post, you have learned how to install it on FreeBSD 12.

Please share this post and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article