Skip to main content

How to Install Apache HTTP Server on CentOS

Apache HTTP Server is a popular web server software that allows users to serve web pages over the internet. Installing Apache HTTP Server on CentOS is a relatively simple process. In this tutorial, we will walk you through the step-by-step process of installing Apache HTTP Server on CentOS.

Prerequisites

Before we begin, ensure that you have a CentOS server to install Apache HTTP Server on. Additionally, you should have root access to the server.

Step 1: Update the System

The first step to installing Apache HTTP Server on CentOS is to update the system. This ensures that all necessary packages are up to date. Run the following command to update the system:

sudo yum update

Step 2: Install Apache HTTP Server

Once the system is updated, it’s time to install Apache HTTP Server. Run the following command to install Apache HTTP Server:

sudo yum install httpd

This command will install Apache HTTP Server on your CentOS server.

Step 3: Start Apache HTTP Server

After installing Apache HTTP Server, start the service by running the following command:

sudo systemctl start httpd

This command starts the Apache HTTP Server service.

Step 4: Enable Apache HTTP Server

To ensure that Apache HTTP Server starts automatically whenever the system boots up, enable the service by running the following command:

sudo systemctl enable httpd

This command enables the Apache HTTP Server service on your CentOS server.

Step 5: Check Apache HTTP Server Status

To verify that Apache HTTP Server is running, run the following command:

sudo systemctl status httpd

This command will display the status of the Apache HTTP Server service. If the service is running, you will see an output that looks like this:

httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-04-05 15:41:09 UTC; 1 day 4h ago

If the service is not running, you will see an output that looks like this:

httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: inactive (dead)

Step 6: Configure Apache HTTP Server

To configure Apache HTTP Server, open the Apache configuration file by running the following command:

sudo nano /etc/httpd/conf/httpd.conf

This command opens the Apache configuration file in the nano text editor.

Step 7: Test Apache HTTP Server

To test Apache HTTP Server, create a simple PHP file by running the following command:

sudo nano /var/www/html/index.php

This command creates a new file named index.php in the /var/www/html directory.

Add the following code to the index.php file:

<?php
phpinfo();
?>

Save and close the file.

Then, open a web browser and navigate to http://your_server_IP_address/index.php. If Apache HTTP Server is working correctly, you will see a page that displays information about your PHP installation.

Conclusion

Congratulations! You have successfully installed Apache HTTP Server on CentOS. You can now use Apache to serve web pages over the internet. Remember to keep your system up to date and secure by regularly updating packages and configuring Apache HTTP Server according to your needs.