How to install Apache 2.4 on Arch Linux

Installing Apache, Version 2.4

Apache web server installation is possible using the following command:

# pacman -S apache

Start the web server after each download:

# systemctl enable --now httpd

You must make sure that everything is working correctly. Go to http: //YOUR-SERVER-WEB-ADDRESS-OR-IP and you will see a page with an index / index. If you need to know your IP, run the command:

ip addr

The Apache configuration file is /etc/httpd/conf/httpd.conf. Although Apache is started by the root user, User http immediately switches to work on behalf of that user for security reasons. DocumentRoot “/srv/http” sets where it will search for web files. CustomLog “/var/log/httpd/access_log” common sets where Apache access, which is successful, will be logged. ErrorLog “/var/log/httpd / error_log” sets where access to Apache is that the error will be logged.

Disabling Indexes

If Apache is provided with a directory in which it does not find the index file with the extension that it has configured to use, it will automatically generate an index that shows the contents of the directory. To disable it, generate /etc/httpd/conf/httpd.conf., then inside <Directory “/srv/http”>, from Options, remove Indexes. After restarting, Apache will give you the following: “Access is denied!”. This error message appears if the file /srv/http/index.html does not exist.

Restart Apache

# systemctl restart httpd

Custom directories

By default, ~ /public_html/ the user directory will be shown at http: //YOUR-SERVER-WEB-ADDRESS-OR-IP/~ USERNAME/. But the http user must have executable bit access to the user’s directory and its public_html directory

$ mkdir ~/public_html
$ chmod o+x ~/
$ chmod o+x ~/public_html

Restart Apache

# systemctl restart httpd

Virtual Hosts

It is possible to host several domain names from one Apache web server at once and serve them with different content.
Create a folder to store your virtual host settings:

# mkdir /etc/httpd/conf/vhosts

Create a configuration file for each virtual host, for example /etc/httpd/conf/vhosts/YOUR-DOMAIN-NAME.com:

<VirtualHost *:80>
    ServerAdmin webmaster@YOUR-DOMAIN-NAME.com
    DocumentRoot "/srv/YOUR-DOMAIN-NAME.com"
    ServerName YOUR-DOMAIN-NAME.com
    ServerAlias YOUR-DOMAIN-NAME.com
    ErrorLog "/var/log/httpd/YOUR-DOMAIN-NAME.com-error_log"
    CustomLog "/var/log/httpd/YOUR-DOMAIN-NAME.com-access_log" common

    <Directory "/srv/YOUR-DOMAIN-NAME.com">
        Require all granted
    </Directory>
</VirtualHost>

Create a virtual host service directory:

# mkdir /srv/YOUR-DOMAIN-NAME.com

At the end of /etc/httpd/conf/httpd.conf., include each of these virtual host configuration files:

Include conf/vhosts/YOUR-DOMAIN-NAME.com

Restart Apache

# systemctl restart httpd

Was this article helpful?

Related Articles

Leave A Comment?