Home Alpine Linux How to Install Apache Web Server on Alpine Linux

How to Install Apache Web Server on Alpine Linux

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
Install Apache in Alpine Linux
Install Apache in Alpine Linux

Next, start the Apache web server, run the command:

# rc-service apache2 start
# service apache2 start

To confirm or verify that Apache is running, execute the command.

# service apache2 status
Check Apache in Alpine Linux
Check Apache in Alpine Linux

Alternatively, you can browse the IP address of your Alpine Linux on a web browser and this is what you will get.

Check Apache Page in Alpine Linux
Check Apache Page in Alpine Linux

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">
    <title>Test Site</title>
    <h1>Success! The Test Site is working!</h1>

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.

Check Website Page
Check Website Page

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
Install PHP in Alpine Linux
Install PHP in Alpine Linux

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.


Save the file and exit.

Then browse the following URL to access the PHP page.


You should get this page, a clear indication that PHP has successfully been installed on Alpine Linux.

Check PHP in Alpine Linux
Check PHP in Alpine Linux

And it’s a wrap! In this guide, we have demonstrated how you can install the Apache webserver on Alpine Linux.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

2 thoughts on “How to Install Apache Web Server on Alpine Linux”

  1. 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.


Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.