×


Install Apache on CentOS 7 Server - Step by Step Process ?

Apache web server is one of the most popular web servers in the world. It is an open-source and cross-platform HTTP server that powers a large percentage of the Internet's websites. Apache HTTP server providing powerful features which can be extended by a wide variety of modules.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Apache queries.

In this context, we shall look into how to install Apache web server on your CentOS 7 machine.


How to Install Apache on CentOS ?

By default, Apache is available in the default CentOS repositories and the installation is pretty easy.

Before proceeding with this installation task, you need to ensure that you are using a sudo enabled user.

Then follow the steps given below.


1. Install Apache

We will use CentOS's package manager yum to install Apache. Using package manager we can install Apache easily from a repository maintained by CentOS.

On CentOS, Apache package is known as httpd

Run below command to install Apache package :

$ sudo yum install httpd

After installation is complete, you can start and enable Apache on your server:

$ sudo systemctl start httpd

Next, run below command to enable Apache auto start on boot:

$ sudo systemctl enable httpd


2. Configure Firewall

If your firewall enabled then you have to open http and https ports. Use below commands to open 80 and 443 ports :

$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload


3. Test Apache Installation

i. After Apache Installation, you can check its status and version of Apache service by executing the command:

$ sudo systemctl status httpd
Output
● httpd.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
    Active: active (running) since Fri 2021-05-05 15:25:07 UTC; 11s ago
      Docs: man:httpd(8)
            man:apachectl(8)
  Main PID: 5793 (httpd)
    Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    CGroup: /system.slice/httpd.service
            ├─5793 /usr/sbin/httpd -DFOREGROUND
            ├─5802 /usr/sbin/httpd -DFOREGROUND
            ├─5803 /usr/sbin/httpd -DFOREGROUND
            ├─5804 /usr/sbin/httpd -DFOREGROUND
            ├─5805 /usr/sbin/httpd -DFOREGROUND
            └─5806 /usr/sbin/httpd -DFOREGROUND

ii. To check version of Apache service, run the command:

$ sudo httpd -v

You might get an output such as this:

Output
Server version: Apache/2.4.6 (CentOS)
Server built:   May 5 2021 01:47:09

iii. Finally, you can do final testing to know everything is working proper, open browser and browse with your server public ip address. It should show a CentOS apache default page:

http://YOUR_SERVER_IP


How to Manage Apache Service ?

You can manage Apache services by following commands:

To stop Apache service you can run :

$ sudo systemctl stop httpd

To again start it type:

$ sudo systemctl start httpd

Restart (stop and start) Apache service by typing:

$ sudo systemctl restart httpd

You need to reload Apache if changes made in configuration. You can do it by:

$ sudo systemctl reload httpd

If you want to disable the Apache service to start at boot:

$ sudo systemctl disable httpd

You can re-enable by:

$ sudo systemctl enable httpd


[Need assistance in fixing Apache configuration errors? We can help you. ]


Conclusion

This article covers how to install Apache on your CentOS 7 system. You can now ready to start deploying your applications and use Apache as a web server.

Basically, The Apache HTTP server is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.


To Install Apache on CentOS:

1. Update the local Apache httpd package index to reflect the latest upstream changes:

$ sudo yum update httpd

2. Once the packages are updated, install the Apache package:

$ sudo yum install httpd

3. Enable firewalld's http service with the following command:

$ sudo firewall-cmd --permanent --add-service=http

4. Configure Apache to serve content over HTTPS, you will also want to open up port 443 by enabling the https service:

$ sudo firewall-cmd --permanent --add-service=https

5. Finally, reload the firewall to put these new rules into effect:

$ sudo firewall-cmd --reload