Apache is a free and open-source web server developed and maintained by the Apache Foundation, which is satisfactorily fast and easy to install and configure.
It provides lots of modules for customizing your site to your preference. For example, you can enable SSL for your website, configure virtual hosts, and so on.
In this guide, we will demonstrate how to install and configure the Apache webserver on Alpine Linux.
Install Apache Webserver in Alpine Linux
To get started, log into your Alpine Linux instance and update the package index using the following apk command.
# apk update
Once the repositories have been refreshed, install the Apache webserver as shown.
# apk add apache2
Next, start the Apache web server, run the command:
# rc-service apache2 start OR # service apache2 start
To confirm or verify that Apache is running, execute the command.
# service apache2 status
Alternatively, you can browse the IP address of your Alpine Linux on a web browser and this is what you will get.
http://Server-IP-Address
This is a sure confirmation that the Apache webserver was installed.
Hosting a Website with Apache on Alpine Linux
In Alpine Linux, the Document root is located in the /var/www/localhost/htdocs path. This is where the default index.html file is found whose content we have just seen on the browser.
To host your own site, rename or delete the default index.html file and place or create your own.
Here is a sample of our custom file.
<!DOCTYPE html> <html lang="en"> <head> <title>Test Site</title> </head> <body> <h1>Success! The Test Site is working!</h1> </body> </html>
Save the file and reload Apache.
# service apache2 restart
Head over to your browser and reload the page. Your site will be displayed as shown.
Install PHP on Alpine Linux
If you are intending to host PHP sites, then you need to install PHP for Apache, run the command:
# apk add php$phpverx-apache2
To confirm that PHP is installed, create an info.php file in the Document root.
$ sudo nano /var/www/localhost/htdocs/info.php
Paste the following lines of code.
<?php phpinfo(): ?>
Save the file and exit.
Then browse the following URL to access the PHP page.
http://Server-IP-Address/info.php
You should get this page, a clear indication that PHP has successfully been installed on Alpine Linux.
And it’s a wrap! In this guide, we have demonstrated how you can install the Apache webserver on Alpine Linux.
This tutorial is just a copy of my CC-BY license made in the wiki of alpine. There are missing commands notable the way of the incomplete setup.
@Mckaygerhard,
Please share the link yours, will give credit to you in the article if it is copied by our author…