Learn Void Linux - Web Server & Database Stack
Episode 12 of 23

Learn Void Linux - Web Server & Database Stack

This episode builds a complete web stack on Void: nginx with PHP-FPM, and MariaDB or PostgreSQL as the database. You will enable all the services via runit symlinks and manage the logs in /var/log/nginx with svlogd.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

It's time to put Void to work for a real workload: web servers and databases. Episode 12 guides you through building an nginx + PHP-FPM + database stack, enabling everything as runit services, and managing their logs. This is the foundation of almost every modern web application.

The stack we build is the classic LEMP pattern (Linux, nginx, MariaDB, PHP). You'll see how each component lives as an independent runit service, and how logs are managed with svlogd — not journald.

Let's start with the web server.

Installing and Configuring nginx

Install and Enable nginx

Install nginx and enable it as a runit service:

Install and enable nginx
sudo xbps-install -S nginx
sudo ln -s /etc/sv/nginx /var/service/
sudo sv start nginx

The ln -s /etc/sv/nginx /var/service/ command makes nginx start automatically at boot. Check that the service is actually running:

Check the nginx status and port
sv status nginx
ss -tlnp | grep :80

The output of ss -tlnp | grep :80 shows nginx listening on port 80 — a sign the web server is active.

Creating a Site Configuration

Place the site configuration in /etc/nginx/conf.d/. Example server block:

/etc/nginx/conf.d/example.conf
server {
    listen 80;
    server_name example.com;
    root /srv/http/example;
    index index.html index.php;
}

After writing the configuration, test the syntax then reload nginx:

Test and reload nginx
sudo nginx -t
sudo sv reload nginx

The nginx -t command validates the syntax before it's applied. sv reload nginx makes nginx read the new configuration without downtime.

PHP-FPM

Install and Enable PHP-FPM

For dynamic pages, install PHP-FPM:

Install PHP and FPM
sudo xbps-install -S php php-fpm
sudo ln -s /etc/sv/php-fpm /var/service/
sudo sv start php-fpm

The php-fpm package provides the FastCGI Process Manager service. Add the extensions your application needs, for example php-pdo_mysql for the database.

Connecting nginx to PHP-FPM

Connect nginx to PHP-FPM via a server block:

Location block for PHP
location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
    include fastcgi.conf;
}

Test the integration by creating a test file:

Create a PHP test file
echo '<?php phpinfo(); ?>' | sudo tee /srv/http/example/index.php

Then open http://localhost/index.php in your browser — you'll see the phpinfo page if PHP-FPM is working.

Database: MariaDB and PostgreSQL

MariaDB

Install and initialize MariaDB:

Install and initialize MariaDB
sudo xbps-install -S mariadb mariadb-connector-c
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo ln -s /etc/sv/mariadbd /var/service/
sudo sv start mariadbd

The mysql_install_db command initializes the data directory for the first time. Once the service is active, secure the installation:

Secure the MariaDB installation
sudo mysql_secure_installation

PostgreSQL

As an alternative, PostgreSQL is also available:

Install and initialize PostgreSQL
sudo xbps-install -S postgresql
sudo -u postgres initdb -D /var/lib/postgresql/data
sudo ln -s /etc/sv/postgresql /var/service/
sudo sv start postgresql

The initdb -D /var/lib/postgresql/data command creates a new database cluster. Once the service is active, create a user and database:

Create a user and database
sudo -u postgres psql -c "CREATE USER app WITH PASSWORD 'secret';"
sudo -u postgres createdb -O app appdb

Managing nginx Logs

Logs via svlogd

nginx logs on Void are managed by svlogd. The log directory structure:

nginx log structure
/etc/sv/nginx/log/run   : script directing logs to svlogd
/var/log/nginx/current  : active log being written continuously

Read the log live:

Watch the nginx log
tail -f /var/log/nginx/current

The tail -f /var/log/nginx/current command shows the nginx access log in real time. Old log files are rotated and archived by svlogd automatically.

Finding Errors

When a site isn't responding, the right diagnosis sequence:

Web stack diagnosis
sv status nginx php-fpm mariadbd
tail -n 20 /var/log/nginx/current
sudo sv restart nginx

Check the status of all services, read the nginx log, then restart the component having trouble. This habit solves the majority of web stack problems.

Conclusion

Episode 12 built a complete web stack on Void: nginx with PHP-FPM as the dynamic frontend, MariaDB or PostgreSQL as the database, all enabled as runit services, with logs managed by svlogd in /var/log/nginx.

Key takeaways:

  • nginx is enabled via the /var/service/nginx symlink.
  • PHP-FPM connects to nginx via a Unix socket.
  • MariaDB and PostgreSQL must be initialized before the service activates.
  • nginx -t validates the configuration before reloading.
  • nginx logs are managed by svlogd in /var/log/nginx/current.
  • sv status helps diagnose the stack in order.

In the next episode, episode 13, we will cover firewalls with nftables — writing rulesets with the nft CLI, enabling IP forwarding and NAT for a gateway, and applying a persistent firewall on Void.

Learn Void Linux - Web Server & Database Stack | Learn Void Linux