Difference between revisions of "Apache HTTP Server -"
(Corrected a section name and some typos.)
Latest revision as of 08:11, 10 June 2020
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.
# xbps-install -S apache
To setup the service, link the service file
# ln -s /etc/sv/apache /var/service
- This directive in
<Directory>sections causes Apache to completely ignore
.htaccessfiles. Note that this is now the default for Apache 2.4, so you need to explicitly allow overrides if you plan to use
.htaccessfiles. If you intend to use
mod_rewriteor other settings in
.htaccessfiles, 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
LoadModule rewrite_module /usr/libexec/httpd/mod_rewrite.so
Create a file in apache's
DocumentRoot (the default location is
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.
# xbps-install -S php-apache
/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
- Place this at the end of the
LoadModule php7_module /usr/libexec/httpd/modules/libphp7.so AddHandler php7-script .php
At the bottom of this file, add
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
# xbps-install -S php-mysql
Uncomment the following lines in
Restart the apache service.
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.