Configure Apache Web Server in Redhat Linux

Loading

Apache is a very popular and commonly used open-source web server that can run on both Linux and Windows operating systems. In this blog, we will build a very basic static Apache website and later branch this out to a dynamic webpage using LEMP stack.

Lab Server Setup:

Hostname: lnx03.ash.local
Operating System: Redhat 9.2

Packages and Config files required for the Apache server

  • httpd – Package installs the Apache web server.
  • mod_ssl -Additional package required to create secure websites ie: SSL
  • links – Optional package for text-based web browser
    Default ports: 80 and 443 (SSL)

These are the main folders storing Apache config files

PurposeLocation
Default Parent Directory /var/www/html
Main Apache root configuration directory./etc/httpd
Additional Apache configuration files are provided by third-party software./etc/httpd/conf.d
Main Configuration file/etc/httpd/conf/httpd.conf
Configuration files for additional modules.( SymLink to /etc/httpd/modules)/var/lib/httpd/modules
Configuration files which load modules/etc/httpd/conf.modules.d/ directory (e.g. PHP)
Contains log files ( SymLink to /etc/httpd/logs)
/etc/log/httpd
Main web document root directory/var/www
Access Logs/var/log/httpd/example.com.access.log
Error Logs/var/log/httpd/example.com.error.log

Step 1 – Set up the host file

Step 2 – Install the Apache server and the mod ssl package using the following command

Step 3 – Check Apache daemon(httpd) install

Step 4 – Enable the Apache service with either httpd.service or apache2.service using the below command

 

Step 5 – Check the version of Apache installed.

Step 6 –Verify that port 80 is open

Step 7 –Allow HTTP and HTTPS traffic in our firewall if enabled.

Step 8 – Create web content under /var/www/html folder for RHEL.

Step 9 – Test the config file

Step 10 – Verify the webpage

Apache Virtual Host Configuration to run multiple websites – Shared Website Hosting.

Most of the WordPress sites we use run with the virtual host configuration. The objective of a virtual host entry in Apache config is to handle multiple websites from a single IP address on our Apache VM so that a single massive VM can serve a ton of websites from it which is the principle of Shared Website Hoisting.

We will aim to set up our two hotel websites running from a single web server as shown below – www.east.ash.local and www.west.ash.local from our single server which has a single IP address of 192.168.0.17, so we must have DNS names resolving to this machine IP address or make an entry in /etc/hosts file. Each hotel branch will have its own URL as shown.

Set up the host file

For multiple websites, to be hoisted, create a dedicated directory for each website file and keep all the website content on those directories respectively as shown below. In this example, my east and west website files are kept separately.

Open the main configuration file /etc/httpd/conf/httpd.conf and make the below changes at the end of the file.

Test the config file

Test the east and west website page

Grep command example to strip out data and see what are all the uncommented lines in our config file.

(Visited 28 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.