How to Install and Configure Apache Webserver on Red Hat/CentOS

How to Install and Configure Apache Webserver on Red Hat/CentOS

Apache is a popular open-source web server software that can be installed on Red Hat or CentOS operating systems. In this tutorial, we will explain how to install and configure Apache on Red Hat or CentOS.

Step 1: Update Your System

Before installing any new software, it is important to make sure your system is up to date. You can update your system by running the following command:

sudo yum update

Step 2: Install Apache

Once your system is up to date, you can install Apache using the following command:

sudo yum install httpd

This command will download and install Apache on your system.

Step 3: Configure Firewall

If you have a firewall installed on your system, you will need to open the HTTP and HTTPS ports for Apache to function properly. You can do this using the following commands:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Step 4: Verify Apache Installation

You can verify that Apache is installed and running correctly by opening your web browser and navigating to your server's IP address. You should see the Apache Test Page.

Step 5: Configure Virtual Hosts

If you plan to host multiple websites on your server, you can configure virtual hosts. Virtual hosts allow you to host multiple websites on the same server with different domain names. You can do this by creating a new configuration file in the /etc/httpd/conf.d/ directory. For example:

sudo nano /etc/httpd/conf.d/example.com.conf

In this file, you can specify the configuration for your website, including the domain name, document root, and other settings. Once you have configured your virtual host, you can enable it using the following command:

sudo systemctl restart httpd

Step 6: Restart Apache

After making any changes to the Apache configuration, you will need to restart Apache for the changes to take effect. You can do this using the following command:

sudo systemctl restart httpd

That's it! You have now installed and configured Apache on your Red Hat or CentOS server.