How to Configure Apache Web Server on Fedora

Apache is a powerful, feature rich web server that is used for serving both static and dynamic websites and has been around since 1995. The latest version on Apache is Apache httpd 2.4.39 ,  and in this topic, you will learn how you can install and configure Apache web server on Fedora 27 and later.

Prerequisites

Before you begin, its important to conduct a flight check and ensure the following requiements are met:
  1. An instance of Fedora 27 server
  2. SSH access to the Server
  3. Non-root user configured with sudo privileges

Step 1. Install Apache on Fedora

To get started, let’s first the system repositories. To do this, log in to your Server vua SSH and run the following command with sudo privileges

$ sudo dnf update

Next, install apache webserver using the command

$ sudo dnf install httpd

To start Apache2 web server run

$ sudo systemctl start httpd

To verify and confirm that Apache2 web server is running execute the command

$ sudo systemctl status httpd

Sample output


In addition, you can use the netstat command to check if  apache web server is listening to port 80.

In the output below, we can clearly see that httpd is listening to port 80


Step 2. Configuring Apache web server


The primary Configuration file of Apache web server in Fedora 27 is  found in /etc/httpd/conf/httpd.conf .  The web files are stored in /var/www/html  by default.

The configuration is quite enormous and only very attributes require tweaking for a website to be up and running.

Let’s look at some of these attributes of the configuration file

1.      Listen statement

This defines the IP address and the  port that the web server is listening for HTTP requests. This line normally looks like

Listen 127.0.0.1:80

This implies that the website is only available to the local machine on the loopback address 127.0.0.1.  To open your web server to the outside world,  simply edit it out like

Listen 80

2.      DocumentRoot directive

This attribute defines the location of the website files. This file needs not be changes because by default, it already points to that location which is  /var/www/html.

This attribute is as shown

DocumentRoot "/var/www/html"

These are the main attributes that may require some tweaking if you need to host a simple website. Now let’s create a simple html file for testing our web server.

Step 3. Creating a simple index.html file for testing the web server

The index.html , located at /var/www/html file acts as a default file that the web server serves when a website is accessed.

To test our web server therefore, backup the existing index.html file

$ sudo mv index.html  index.html.bak

Next Create a new index.html file

$ sudo touch index.html

Add some sample content  to the file for example:

echo "<h1>Hey there ! your web server is up and running !</h1>" > index.html

Using the chown command, set the ownership to apache.apache

$ sudo chown apache:apache index.html

Next, restart your Apache web server

$ sudo systemctl restart httpd


Now head out to your browser and browse your servers’ IP address as shown
http://server-ip-address   In my case, the IP address is  http://34.68.0.205/

You should be able to view the contents of the index.html file you just created. Voila !


And that’s how you configure your Apache web server to host a basic html websites. 

Comments

Popular posts from this blog

Sandmap - A Tool to Use Advanced Scanning Techniques on Linux

Basic Linux Interview Questions