Databases

Install Apache, MariaDB, and PHP (LAMP) on Void Linux

Void Linux handles services differently from most distros. There’s no systemd here. Runit manages everything, and the package manager (xbps) is fast and minimal. Setting up a LAMP stack on Void takes about 10 minutes once you know the right steps, but a few configuration details will trip you up if you follow generic guides written for Debian or Fedora.

Original content from computingforgeeks.com - post 83703

This guide walks through installing Apache 2.4, MariaDB 11.1, and PHP 8.4 on Void Linux with real commands and output from a fresh system. We also cover two practical scenarios: deploying a PHP application with MariaDB connectivity and hosting a simple HTML/PHP site with virtual hosts.

Tested March 2026 | Void Linux (glibc, x86_64), Apache 2.4.65, MariaDB 11.1.2, PHP 8.4.7

Prerequisites

  • A running Void Linux system (glibc variant recommended for maximum compatibility)
  • Root or sudo access
  • Tested on: Void Linux x86_64 (glibc), kernel 6.x, with Apache 2.4.65, MariaDB 11.1.2, PHP 8.4.7

Update the System

Start by updating the xbps package manager itself, then pull in all available updates. Void requires updating xbps separately before a full system upgrade.

sudo xbps-install -u xbps

Once xbps is current, run a full system update:

sudo xbps-install -Syu

Install Apache Web Server

Install Apache from the Void repos:

sudo xbps-install -y apache

Void Linux uses runit instead of systemd. To enable a service, you create a symlink from /etc/sv/ to /var/service/. This both enables the service at boot and starts it immediately.

sudo ln -s /etc/sv/apache /var/service/apache

Give it a couple of seconds, then verify Apache is running:

sudo sv status apache

The output should show the service with a PID and uptime:

run: apache: (pid 2283) 5s; run: log: (pid 2282) 5s

Confirm the installed version:

httpd -v

You should see Apache 2.4.65 or later:

Server version: Apache/2.4.65 (Unix)
Server built:   Oct 15 2025 23:25:32

Apache’s default document root on Void Linux is /srv/www/apache, not /var/www/html like on Debian or RHEL. The main configuration file lives at /etc/apache/httpd.conf.

Install MariaDB

Void ships MariaDB 11.1.x as its default MySQL-compatible database. Install it:

sudo xbps-install -y mariadb

Enable and start the MariaDB service through runit:

sudo ln -s /etc/sv/mysqld /var/service/mysqld

Wait a few seconds for MariaDB to initialize, then check its status:

sudo sv status mysqld

A healthy service looks like this:

run: mysqld: (pid 2570) 40s; run: log: (pid 2569) 40s

One thing to note: MariaDB 11.x has deprecated the mysql command in favor of mariadb. Both still work for now, but you’ll see deprecation warnings if you use the old name. The article uses mariadb throughout.

Secure the Installation

Run the interactive security script to set a root password, remove anonymous users, and drop the test database:

sudo mariadb-secure-installation

Answer the prompts as follows (press Enter for the default where shown):

Enter current password for root (enter for none): [Enter]
Switch to unix_socket authentication [Y/n]: Y
Change the root password? [Y/n]: Y
New password: ********
Re-enter new password: ********
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

Verify you can log in with the new password:

mariadb -u root -p -e "SELECT VERSION();"

The output confirms MariaDB 11.1.2:

+------------------------+
| VERSION()              |
+------------------------+
| 11.1.2-MariaDB-debug   |
+------------------------+

Install PHP 8.4 with Apache Module

Void Linux currently ships PHP 8.4 (a significant jump from the PHP 7.4 that was available in older Void releases). Install the Apache SAPI and the MySQL extension together:

sudo xbps-install -y php-apache php-mysql

This pulls in php8.4, php8.4-apache, and php8.4-mysql (which includes both mysqli and PDO MySQL drivers).

Confirm PHP is installed:

php -v

Expected output:

PHP 8.4.7 (cli) (built: Mar 25 2026 10:12:57) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies

Configure Apache to Use PHP

PHP’s Apache module is not thread-safe on Void, so Apache must use the prefork MPM instead of the default event MPM. Open the Apache configuration file:

sudo vi /etc/apache/httpd.conf

Find the MPM module lines (around line 66) and make these changes:

# Comment out event MPM (not compatible with mod_php)
#LoadModule mpm_event_module /usr/libexec/httpd/mod_mpm_event.so

# Uncomment prefork MPM
LoadModule mpm_prefork_module /usr/libexec/httpd/mod_mpm_prefork.so

Then scroll to the bottom of the file and add the PHP module configuration:

LoadModule php_module /usr/libexec/httpd/modules/libphp.so
Include /etc/apache/extra/php_module.conf

The libphp.so symlink automatically points to the active PHP version (currently libphp8.4.so), so you won’t need to update this line when PHP gets upgraded.

Test the configuration for syntax errors:

httpd -t

If everything is correct, you’ll see:

Syntax OK

Restart Apache to load the PHP module:

sudo sv restart apache

Enable PHP Extensions

The MySQL extension is installed but not automatically enabled. PHP on Void reads additional config files from /etc/php8.4/conf.d/. Create that directory and enable the extensions:

sudo mkdir -p /etc/php8.4/conf.d

Enable the MySQLi and PDO MySQL extensions:

echo "extension=mysqli.so" | sudo tee /etc/php8.4/conf.d/mysqli.ini
echo "extension=pdo_mysql.so" | sudo tee /etc/php8.4/conf.d/pdo_mysql.ini

Verify the extensions are loaded:

php -m | grep -i mysql

All three MySQL-related modules should appear:

mysqli
mysqlnd
pdo_mysql

Restart Apache once more to pick up the new extensions:

sudo sv restart apache

Verify the LAMP Stack

Create a PHP info page to confirm everything works through the web server:

echo '<?php phpinfo(); ?>' | sudo tee /srv/www/apache/info.php

Open http://your-server-ip/info.php in a browser. You should see the full PHP information page showing PHP 8.4.7, the Apache 2.0 Handler SAPI, and the mysqli section confirming database support is active.

Check that all three services are running:

sudo sv status apache mysqld

Both should show run with their PIDs:

run: apache: (pid 2864) 11s; run: log: (pid 2282) 270s
run: mysqld: (pid 2570) 183s; run: log: (pid 2569) 183s

Verify both Apache and MariaDB are listening on their expected ports:

ss -tlnp | grep -E '80|3306'

Apache should be on port 80 and MariaDB on port 3306:

LISTEN  0  80    0.0.0.0:3306   0.0.0.0:*  users:(("mysqld",pid=2570,fd=23))
LISTEN  0  511         *:80         *:*  users:(("httpd",pid=2864,fd=4))
LISTEN  0  80     [::]:3306      [::]:*  users:(("mysqld",pid=2570,fd=24))

Remove the info.php file after verification since it exposes server details:

sudo rm /srv/www/apache/info.php

Scenario 1: PHP Application with MariaDB

A LAMP stack by itself doesn’t do much. Here’s how to connect PHP to MariaDB with a working example. First, create a database and user for the application:

mariadb -u root -p

Run these SQL statements inside the MariaDB shell:

CREATE DATABASE appdb;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'AppP@ssw0rd';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Now create a PHP file that connects to MariaDB, creates a table, inserts a row, and reads it back:

sudo vi /srv/www/apache/app.php

Add the following PHP code:

<?php
$conn = new mysqli("localhost", "appuser", "AppP@ssw0rd", "appdb");
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Create table
$conn->query("CREATE TABLE IF NOT EXISTS messages (
    id INT AUTO_INCREMENT PRIMARY KEY,
    content VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");

// Insert a test record
$conn->query("INSERT INTO messages (content) VALUES ('Hello from PHP 8.4 on Void Linux')");

// Read back
$result = $conn->query("SELECT * FROM messages ORDER BY id DESC LIMIT 5");
echo "<h2>Messages from MariaDB</h2>";
echo "<table border='1'><tr><th>ID</th><th>Message</th><th>Created</th></tr>";
while ($row = $result->fetch_assoc()) {
    echo "<tr><td>{$row['id']}</td><td>{$row['content']}</td><td>{$row['created_at']}</td></tr>";
}
echo "</table>";
echo "<p>PHP " . phpversion() . " | MariaDB " . $conn->server_info . "</p>";
$conn->close();
?>

Visit http://your-server-ip/app.php in your browser. You should see a table with the test message, confirming PHP can read from and write to MariaDB. Each page refresh adds another row.

Scenario 2: Apache Virtual Hosts

Hosting multiple sites on one Void Linux server requires Apache virtual hosts. Open the main configuration file:

sudo vi /etc/apache/httpd.conf

Find and uncomment this line to enable virtual host configuration:

Include /etc/apache/extra/httpd-vhosts.conf

Now edit the virtual hosts file:

sudo vi /etc/apache/extra/httpd-vhosts.conf

Replace the example entries with your site configuration:

<VirtualHost *:80>
    ServerName site1.example.com
    DocumentRoot "/srv/www/site1"
    <Directory "/srv/www/site1">
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "/var/log/httpd/site1-error.log"
    CustomLog "/var/log/httpd/site1-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerName site2.example.com
    DocumentRoot "/srv/www/site2"
    <Directory "/srv/www/site2">
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "/var/log/httpd/site2-error.log"
    CustomLog "/var/log/httpd/site2-access.log" common
</VirtualHost>

Create the document roots and log directory:

sudo mkdir -p /srv/www/site1 /srv/www/site2 /var/log/httpd

Add a test page for each site:

echo "<h1>Site 1 on Void Linux</h1>" | sudo tee /srv/www/site1/index.html
echo "<h1>Site 2 on Void Linux</h1>" | sudo tee /srv/www/site2/index.html

Test the configuration and restart Apache:

httpd -t && sudo sv restart apache

Each site now responds to its own hostname on port 80. Point your DNS records (or local /etc/hosts file) to the server’s IP and test both sites independently.

Install Additional PHP Extensions

Most PHP applications need more than the base install. Void provides a solid set of extensions through its repos. Install the most commonly needed ones:

sudo xbps-install -y php-gd php-intl php-sqlite

After installing, each extension needs an ini file in the conf.d directory to be activated:

echo "extension=gd.so" | sudo tee /etc/php8.4/conf.d/gd.ini
echo "extension=intl.so" | sudo tee /etc/php8.4/conf.d/intl.ini
echo "extension=sqlite3.so" | sudo tee /etc/php8.4/conf.d/sqlite3.ini
echo "extension=pdo_sqlite.so" | sudo tee /etc/php8.4/conf.d/pdo_sqlite.ini

Restart Apache and confirm the full module list:

sudo sv restart apache
php -m | sort

You should see 34+ modules loaded, including gd, intl, mysqli, pdo_mysql, sqlite3, and pdo_sqlite.

Other available extensions you can install the same way include: php-redis, php-ldap, php-pgsql, php-sodium, php-tidy, and php-xsl. Run xbps-query -Rs php- to see the full list.

Runit Service Management Quick Reference

If you’re coming from systemd-based distros, runit’s service management takes some getting used to. Here are the essential commands for managing your LAMP services:

ActionRunit commandsystemd equivalent
Start a servicesv start apachesystemctl start httpd
Stop a servicesv stop apachesystemctl stop httpd
Restart a servicesv restart apachesystemctl restart httpd
Check statussv status apachesystemctl status httpd
Enable at bootln -s /etc/sv/apache /var/service/systemctl enable httpd
Disable at bootrm /var/service/apachesystemctl disable httpd
View logscat /var/log/socklog/apache/*journalctl -u httpd

One key difference: runit starts a service the moment you symlink it to /var/service/. There’s no separate “enable” and “start” step. Removing the symlink stops and disables the service.

Void Linux vs Other Distros: LAMP Differences

If you maintain LAMP stacks across multiple Linux distributions, these are the differences that catch people off guard on Void:

ItemVoid LinuxDebian/UbuntuRHEL/Rocky
Init systemrunitsystemdsystemd
Package managerxbpsaptdnf
Apache document root/srv/www/apache/var/www/html/var/www/html
Apache config/etc/apache/httpd.conf/etc/apache2/apache2.conf/etc/httpd/conf/httpd.conf
PHP config/etc/php8.4/php.ini/etc/php/8.3/apache2/php.ini/etc/php.ini
MariaDB commandmariadbmariadbmariadb
MariaDB servicesv status mysqldsystemctl status mariadbsystemctl status mariadb
SELinux/AppArmorNeitherAppArmorSELinux

Going Further

  • Set up an Nginx reverse proxy with SSL in front of Apache for production deployments
  • Install LAMP on Fedora or Rocky Linux if you need systemd-based service management
  • Consider LAMP on Debian or Ubuntu for production web hosting with broader community support
  • Explore php-fpm (available as xbps-install php-fpm) if you want Apache to use FastCGI instead of mod_php for better memory management under load
  • Install socklog-void (xbps-install socklog-void) for persistent logging, since runit’s default logging is minimal compared to journald

Related Articles

Databases How To Install MariaDB 10.8 on CentOS 8 / RHEL 8 AlmaLinux Install Azure Data Studio on Rocky / AlmaLinux 8 Databases SQL from scratch: how to get started learning databases? Databases How To Install MariaDB 10.8 on CentOS 7 or RHEL 7

Leave a Comment

Press ESC to close