How to Install Lighttpd on CentOS 8
In this short walk‑through you’ll get Lighttpd up and running on a fresh CentOS 8 box in under ten minutes. No fluff about “modern web stacks” – just the commands, why they matter, and one quick tweak that saves headaches later.
Step 1: Enable the EPEL Repository
Lighttpd ships in EPEL, so you need to turn that on first.
sudo dnf install epel-release -y
The base CentOS repo doesn’t ship Lighttpd; it’s a lightweight alternative to Apache and nginx, but the only official package is in EPEL. Skipping this step means you’ll be chasing the wrong RPMs forever.
Step 2: Install Lighttpd and Common Modules
sudo dnf install lighttpd lighttpd-mod-headers lighttpd-mod-proxy -y
mod_headers lets you tweak response headers—useful for cache control. mod_proxy is handy if you later want to push a PHP worker or reverse‑proxy a Node app. If you’re serving static files only, you can leave out the modules; I’ve seen people over‑install and end up with unnecessary bloat.
Step 3: Start and Enable the Service
sudo systemctl enable --now lighttpd
The enable flag puts Lighttpd on boot, while --now starts it immediately. A quick check:
curl -I http://localhost
You should see a 200 response and the “Server: lighttpd” header. If you don’t, the service isn’t listening; look at /var/log/lighttpd/error.log.
Step 4: Open HTTP in the Firewall
CentOS 8 ships with firewalld enabled by default.
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload
If you forget this, browsers will complain “connection refused.” I’ve run into that on a colleague’s laptop when the dev server was up but the port stayed closed.
Step 5: Tweak the Default Config (Optional)
The default /etc/lighttpd/lighttpd.conf is minimal, but you can add a few lines to improve security and performance:
server.document-root = "/var/www/html"
server.error-handler-404 = "/error.html"
# Disable directory listings unless you explicitly want them
dir-listing.activate = "disable"
# Tell browsers to cache static content for a week
header.set("Cache-Control", "max-age=604800")
Save the file, then reload:
sudo systemctl reload lighttpd
Step 6: Drop a Test Page and Verify
Create an index file:
echo "<h1>Hello from Lighttpd!</h1>" | sudo tee /var/www/html/index.html
Now hit http://your‑server-ip/ in a browser. If you see that headline, congratulations – you’ve got a clean, lightweight web server running on CentOS 8.
Gotchas to Watch Out For
- Missing mod_fastcgi: If your PHP setup relies on FastCGI and you forgot to install lighttpd-mod-fastcgi, the PHP files will just return 500 errors. Add it with sudo dnf install lighttpd-mod-fastcgi and configure /etc/lighttpd/conf.d/fastcgi.conf.
- SELinux Denials: On a default SELinux enforcing system, Lighttpd might be blocked from reading your document root. Run restorecon -Rv /var/www/html after you create files to fix the context.
- Port Conflicts: If Apache or another service already owns port 80, Lighttpd will fail silently. Check with sudo lsof -i :80. Switch the listening port in /etc/lighttpd/lighttpd.conf if needed.
That’s it—Lighttpd is now a lean, efficient server on your CentOS 8 box. You can start adding virtual hosts or reverse‑proxy to other apps whenever you’re ready.