How to Install Lighttpd, MariaDB and PHP (LLMP) on AlmaLinux 9 or Rocky Linux 9
Install Lighttpd from EPEL on AlmaLinux 9 or Rocky Linux 9, add MariaDB and PHP-FPM, and connect them over a Unix socket.
This guide builds an LLMP stack (Linux, Lighttpd, MariaDB and PHP) on AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9. At the end, Lighttpd serves static files itself, passes .php requests to PHP-FPM over a Unix socket, and PHP can talk to a local MariaDB server.
CentOS 6 reached end of life in November 2020 and receives no updates; the RHEL 9 family replaces it. Two things changed along the way: services are managed with systemctl instead of service and chkconfig, and SELinux and firewalld are active by default.
Requirements
- A server running AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9.
- A user with
sudorights (the examples usedeploy). - Ports 80 and 443 free. If Apache or Nginx is installed, stop it first, because only one program can listen on a port.
Update the system, and stop Apache if it is present:
sudo dnf upgrade -y
sudo systemctl disable --now httpdThe second command prints an error if Apache is not installed; you can ignore it.
Enable the EPEL repository
Lighttpd is not in the BaseOS or AppStream repositories of the RHEL 9 family. It is packaged in EPEL (Extra Packages for Enterprise Linux), maintained by the Fedora project. EPEL 9 carries Lighttpd 1.4.67.
On AlmaLinux 9 and Rocky Linux 9:
sudo dnf install -y epel-releaseOn CentOS Stream 9, enable the CRB repository and install both EPEL release packages:
sudo dnf config-manager --set-enabled crb
sudo dnf install -y epel-release epel-next-releaseConfirm that the package is now visible and which repository provides it:
dnf info lighttpdInstall and start Lighttpd
Install the server together with its FastCGI module, which is a separate package:
sudo dnf install -y lighttpd lighttpd-fastcgiEnable the service at boot and start it:
sudo systemctl enable --now lighttpd
systemctl status lighttpdOpen the web ports in firewalld:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reloadBrowse to http://203.0.113.10/ (your server's address). You should see the Lighttpd placeholder page, which is served from /var/www/lighttpd, the package's document root.
If the server does not answer over IPv4
The packaged /etc/lighttpd/lighttpd.conf contains server.use-ipv6 = "enable". On a host with IPv6 switched off, Lighttpd then fails to start, and on some hosts it answers over IPv6 only. Check what it is listening on:
sudo ss -tlnp | grep lighttpd
curl -4 -I http://127.0.0.1/If the IPv4 request fails, edit /etc/lighttpd/lighttpd.conf, change the line to server.use-ipv6 = "disable" so the main listener is IPv4, and, if you also want IPv6, add an extra socket at the end of the file:
$SERVER["socket"] == "[::]:80" { }Then restart with sudo systemctl restart lighttpd.
Install MariaDB
The RHEL 9 family ships MariaDB 10.5 as its default version, supported for the life of the release. Newer versions are offered as module streams; dnf module list mariadb shows what your system has.
sudo dnf install -y mariadb-server
sudo systemctl enable --now mariadb
sudo mariadb-secure-installationThe script lets you remove anonymous users and the test database and disable remote root logins. Accept those suggestions. Then create a database and a user for your application:
sudo mariadbCREATE DATABASE appdb CHARACTER SET utf8mb4;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'change-this-password';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
EXIT;Install PHP-FPM
The default PHP in the RHEL 9 family is 8.0. Newer versions are provided as module streams, so list them and enable the newest one your system offers (8.3 in this example):
dnf module list php
sudo dnf module reset -y php
sudo dnf module enable -y php:8.3
sudo dnf install -y php-fpm php-cli php-mysqlnd php-mbstring php-xml php-gd php-opcachePHP-FPM listens on the Unix socket /run/php-fpm/www.sock. The packaged pool only grants access to that socket to the apache and nginx users, so Lighttpd, which runs as the lighttpd user, has to be added. Open /etc/php-fpm.d/www.conf, find the listen.acl_users line and extend it:
listen.acl_users = apache,nginx,lighttpdLeave the pool's user and group set to apache. PHP's session and cache directories under /var/lib/php are owned by that group, and changing the pool user means changing those too. The practical consequence: files that PHP must write to (uploads, caches) have to be writable by apache, while Lighttpd only needs to read them.
Start PHP-FPM:
sudo systemctl enable --now php-fpmConnect Lighttpd to PHP-FPM
Module configuration lives in /etc/lighttpd/modules.conf, which pulls in files from /etc/lighttpd/conf.d/. Open modules.conf and remove the # in front of the FastCGI include:
include conf_dir + "/conf.d/fastcgi.conf"That file loads mod_fastcgi; everything else in it is commented-out examples. Add this block at the end of /etc/lighttpd/conf.d/fastcgi.conf:
fastcgi.server += ( ".php" =>
((
"socket" => "/run/php-fpm/www.sock",
"broken-scriptfilename" => "enable"
))
)Older tutorials point Lighttpd at TCP port 9000 instead. That still works if you change listen in the PHP-FPM pool, but the socket is the packaged default and is not reachable from the network.
Check the configuration for syntax errors, then restart:
sudo lighttpd -tt -f /etc/lighttpd/lighttpd.conf
sudo systemctl restart lighttpdTest PHP and the database connection
Create a test script in the document root:
echo '<?php phpinfo();' | sudo tee /var/www/lighttpd/info.phpOpen http://203.0.113.10/info.php. The page should report FPM/FastCGI as the Server API and list the mysqli and pdo_mysql extensions. You can test the same thing from the shell:
curl -s http://127.0.0.1/info.php | grep -c "FPM/FastCGI"Delete the file afterwards, because it exposes details of your setup:
sudo rm /var/www/lighttpd/info.phpTroubleshooting
- 503 Service Not Available on PHP pages: Lighttpd cannot reach the socket. Check that PHP-FPM is running and that
lighttpdis inlisten.acl_users, then restartphp-fpm. - PHP source is downloaded instead of executed: the FastCGI include in
modules.confis still commented out. - Permission errors although file modes look right: SELinux is enforcing. Look for denials with
sudo ausearch -m avc -ts recent. Content under/var/wwwgets the correct label automatically; if you move a site elsewhere, label it withsemanage fcontextandrestoreconrather than disabling SELinux. - Logs: Lighttpd writes to
/var/log/lighttpd/error.log, PHP-FPM to/var/log/php-fpm/.
For HTTPS, install the lighttpd-mod_openssl package and follow the TLS section of the Lighttpd documentation.
Frequently asked questions
Is Lighttpd a fork of Apache?
No. It is an independent web server with its own code base and configuration language. It uses an event-driven design with a small memory footprint, which is why it is popular on small VPS plans and embedded devices.
Do Apache .htaccess files work?
No. Lighttpd does not read .htaccess. Rewrite rules and access restrictions must be translated to mod_rewrite and mod_access directives in the Lighttpd configuration, and a restart is needed after each change.
Why is the Lighttpd version in EPEL older than the upstream release?
EPEL keeps a stable version for the lifetime of a RHEL major release and avoids disruptive upgrades. Updates arrive through dnf upgrade like any other package. If you need a newer Lighttpd feature, check the version with lighttpd -v before relying on upstream documentation for it.
Do I have to set cgi.fix_pathinfo in php.ini?
No. Lighttpd's sample configuration asks for cgi.fix_pathinfo = 1, and that is already PHP's built-in default; the line in /etc/php.ini is commented out, so the default applies. Older tutorials uncomment it, which changes nothing.