Free and open-source Apache is one of the most popular web servers around the globe. It is based on process-driven architecture and supports all major operating systems, including Linux, Windows, macOS, and Solaris. Apache is customizable and can be integrated with other modules. It offers many features, including load balancing, URL tracking, auto-indexing, robust media support, and more.

This post will explain how to install the Apache web server on Arch Linux.

Step 1 – Configure Repository

By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:

nano /etc/pacman.d/mirrorlist

Remove all lines and add the following lines:

## Score: 0.7, United States
Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.8, United States
Server = http://lug.mtu.edu/archlinux/$repo/os/$arch
Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.9, United Kingdom
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
## Score: 1.5, United Kingdom
Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch
Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch
## Score: 6.6, United States
Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch
## Score: 6.7, United States
Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch
## Score: 6.8, United States
Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch
## Score: 7.1, India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
## Score: 10.1, United States
Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch

Save and close the file, then update all the package indexes with the following command:

pacman -Syu

Step 2 – Install Apache Web Server

By default, the Apache web server package is included in the Arch Linux default repository. You can install it using the following command:

pacman -S apache

Once the Apache package is installed, start and enable the Apache service with the following command:

systemctl start httpd
systemctl enable httpd

You can also check the Apache status using the following command:

systemctl status httpd

You will get the following output:

● httpd.service - Apache Web Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
     Active: active (running) since Tue 2022-09-27 04:41:54 UTC; 6s ago
   Main PID: 54484 (httpd)
      Tasks: 82 (limit: 2362)
     Memory: 6.8M
     CGroup: /system.slice/httpd.service
             ├─54484 /usr/bin/httpd -k start -DFOREGROUND
             ├─54485 /usr/bin/httpd -k start -DFOREGROUND
             ├─54486 /usr/bin/httpd -k start -DFOREGROUND
             └─54487 /usr/bin/httpd -k start -DFOREGROUND

Sep 27 04:41:54 archlinux systemd[1]: Started Apache Web Server.
Sep 27 04:41:54 archlinux httpd[54484]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20>

By default, the Apache package does not provide any default index.html file to test the Apache. You can create it in the Apache default root directory using the following command:

nano /srv/http/index.html

Add the following code:

<html>
 <title>Welcome</title>
  <body>
   <h2>Welcome to Atlantic Cloud test page</h2>
  </body>
</html>

Save and close the file, then open your web browser and verify the Apache test page using the URL http://your-server-ip. You should see the Apache page on the following screen:
Apache test page

Step 3 – Create an Apache Virtual Host

Virtual hosting allows users to host multiple websites on a single server. First, create a directory for virtual hosts using the following command:

mkdir /etc/httpd/conf/vhosts

Next, create an Apache virtual host configuration file:

nano /etc/httpd/conf/vhosts/example.com

Add the following code:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/srv/example.com"
    ServerName test.example.com
    ErrorLog "/var/log/httpd/example.com-error_log"
    CustomLog "/var/log/httpd/example.com-access_log" common

    <Directory "/srv/example.com">
        Require all granted
    </Directory>
</VirtualHost>

Save and close the file, then create a website directory with the following command:

mkdir /srv/example.com

Next, create an index.html page for your website:

nano /srv/example.com/index.html

Add the following code:

<html>
 <title>Example.COM</title>
  <body>
   <h1>Welcome to example.com</h1>
  </body>
</html>

Save and close the file, then change the ownership of your website:

chown -R root:http /srv/example.com

Next, edit the Apache main configuration file:

nano /etc/httpd/conf/httpd.conf

Add the following line to define your virtual host:

Include conf/vhosts/example.com

Save and close the file, then restart the Apache service to apply the changes:

systemctl restart httpd

Step 4 – Verify Apache Virtual Host

Now, open your web browser and verify your website using the URL http://test.example.com. You should see your website on the following screen:
Apache virtual host test page

Conclusion

In this post, we explained how to install the Apache web server on Arch Linux. We also explained how to create a virtual host in Apache. You can now host multiple websites on a single website using Apache’s virtual hosting feature. You can now try to use the Apache web server on dedicated hosting from Atlantic.Net!