×



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 LinuxAPT, 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


More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com