Warning: THE VOID WIKI IS DEPRECATED. It is no longer being maintained, contains outdated and incorrect information, and will eventually be shut down. Please refer to the Void Handbook, https://docs.voidlinux.org/, for the official documentation. If you can't find the information you're seeking, please raise an issue at https://github.com/void-linux/void-docs/issues

Apache HTTP Server -

From Void Linux Wiki
Jump to navigation Jump to search

The Apache HTTP Server, or Apache for short, is a very popular web server, developed by the Apache Software Foundation.

Apache is often used together with a scripting language such as PHP and database such as MySQL. This combination is often referred to as a LAMP stack (Linux, Apache, MySQL, PHP). This article describes how to set up Apache and how to optionally integrate it with PHP and MySQL.

Before getting the LAMP stack up and running make sure to create a strong password for the primary user on the machine, and either disable the root account or change the default password. If the password on the machine is weak than it creates a big security risk on the network the web server is on.


Install the apache package.

# xbps-install -S apache

To setup the service, link the service file

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



AllowOverride None
This directive in <Directory> sections causes Apache to completely ignore .htaccess files. Note that this is now the default for Apache 2.4, so you need to explicitly allow overrides if you plan to use .htaccess files. If you intend to use mod_rewrite or other settings in .htaccess files, you can allow which directives declared in that file can override server configuration. For more info refer to the Apache documentation.


For use the rewrite module, you must uncomment the following line in the configuration file /etc/apache/httpd.conf

LoadModule rewrite_module /usr/libexec/httpd/mod_rewrite.so


Create a file in apache's DocumentRoot (the default location is /srv/www/apache) called index.html. Copy the below html into the file.

<h1>Apache Is Working</h1>

Open a web browser go to http://localhost/. If the text shows up in bold letters the apache server is up. It cannot yet process PHP or handle database tasks.



To use PHP, first install php-apache package (which will pull in php).

# xbps-install -S php-apache

In /etc/apache/httpd.conf, comment the line:

#LoadModule mpm_event_module modules/mod_mpm_event.so

and uncomment the line:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

To enable PHP, add these lines to /etc/apache/httpd.conf:

  • Place this at the end of the LoadModule list:
LoadModule php7_module /usr/libexec/httpd/modules/libphp7.so
AddHandler php7-script .php

At the bottom of this file, add

Include /etc/apache/extra/php7_module.conf

Restart apache service using runit.

# sv restart apache

To test whether PHP was correctly configured, create a file called test.php in your Apache DocumentRoot directory (e.g. /srv/www/apache/) with this line:

<?php phpinfo(); ?>

To see if it works go to: http://localhost/test.php

MySQL / MariaDB

Note: Install MariaDB first!

To use MariaDB, first install php-mysql package.

# xbps-install -S php-mysql

Uncomment the following lines in /etc/php/php.ini:


Restart the apache service.

Warning: mysql.so was removed in PHP 7.0.

You can add minor privileged MySQL users for your web scripts. You might also want to edit /etc/mysql/my.cnf and uncomment the skip-networking line so the MySQL server is only accessible by the localhost. You have to restart MySQL for changes to take effect.