Home » repository » How to Install Apache on CentOS 6 Linux

How to Install Apache on CentOS 6 Linux

When we are thinking about web server the first name is coming Apache HTTP server, it is most popular in the world for hosting any type of web applications or websites.
 
The most important thing about Apache web server is, it is free and open-source web server and providing a powerful feature for your web application, including support of cross-platform.
 
In this tutorial, we will explain the process of installing the Apache HTTP webserver on CentOS 6 Operating System.

Prerequisites

To install Apache HTTP web server on your CentOS 6 Linux system, you should have user access to login on system and need sudo privileges to execute administrative commands to install applications.

Install Apache

The apache HTTP web server packages are inbuilt in CentOS repository packages which we can easily install using “yum” command. The only thing is to know the Apache HTTP server’s service is known as “httpd” in CentOS Operating System.

To install HTTP package, first, need to update CentOS package index and install httpd using the following command:

$ sudo yum update
$ sudo yum install httpd

Now, the apache httpd web server is installed. You can enable and start httpd service using following command:

$ sudo systemctl enable httpd
$ sudo systemctl start httpd

Configure the Firewall for Apache httpd server on CentOS 6

Nowadays, every system we protecting with Firewall to secure system and services. If Firewall also protests your CentOS system, you need to open HTTP (80) and HTTPS (443) port to access the webserver.

You can open the Apache ports using the following command:

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

Verify Apache Installation

To verify apache httpd web server installed  and everything working as per the instructions, you can check the status of httpd service status and version:

$ 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 Thu 2019-06-26 07:13:07 UTC; 11s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 3059 (httpd)
...
$ sudo httpd -v
Output-
Server version: Apache/2.4.6 (CentOS)
Server built:   Oct 19 2017 20:39:16

Manage Apache Service:

We can manage apache service in the similar of another systemd services.

To stop httpd service use following command:

$ sudo systemctl stop httpd

To start again httpd service, run following command:

$ sudo systemctl start httpd

To restart apache httpd service, use the following command:

$ sudo systemctl restart httpd

To reload apache httpd web service after any changes, run following command:

$ sudo systemctl reload httpd

To disable apache httpd service to start on boot, use following command:

$ sudo systemctl disable httpd

To enable httpd service again, use below command:

$ sudo systemctl enable httpd

Apache Configuration File’s Structure

The Apache2 configuration file’s default location is “/etc/httpd/” directory.

The main Apache2 web server configuration file is “/etc/httpd/conf/httpd.conf”.

The virtual host files configured on Apache webserver stored in the “/etc/httpd/conf.d/” directory. The configuration file ending with “.conf”.

The apache web server’s module configuration files stored in the “/etc/httpd/conf.modules.d/” directory. 

Generally  we can configure all virtual host in a single file, but I suggest to create seperate vhost files.

To troubleshoot or debug the issue with the apache web server, use the log file for apache server and virtual host. The log file for apache located at “/var/log/httpd/access.log” and “/var/log/httpd/error.log”. To make it easy to troubleshoot an issue with different virtual host need to create different access and error log for each virtual host.

There is no location boundary to create document root directory, you can create at any location but as per suggestion, the most common location for webroot directory is:
  • /var/www/<site_Name>
  • /var/www/html/<Site_Name>
  • /opt/<site_Name>
  • /home/<user_name>/<Site_Name>

Conclusion

You have learned to install Apache httpd web server on your CentOS 6 server or system. Now your system is ready to deploy a web application using Apache virtual host or use Apache as a web proxy server for your application.

Do you have any doubt, questions or feedback? Feel free to leave a comment.

Related Posts

How to Install MongoDB on CentOS 8 Linux

How to Install MongoDB on CentOS 8 Linux

MongoDB is an open-source and free NoSQL document based database system. Nowadays, it is prevalent as most application developers are using MongoDB, which can handle big data. As a MongoDB is a NoSQL database, It stores data in JSON-like documents where fields can...

How to Install OpenCV on CentOS 8 Linux

How to Install OpenCV on CentOS 8 Linux

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial...

How to install and use FFmpeg on CentOS 8 Linux Operating System

How to install and use FFmpeg on CentOS 8 Linux Operating System

The FFmpeg is the most potent and useful command-line tool on Linux system for multimedia files transcoding. You can use FFmpeg to convert multimedia files between various video and audio formats and resize videos. It has multiple audio and video libraries such as...

How to Install VirtualBox on CentOS 8 Linux

How to Install VirtualBox on CentOS 8 Linux

VirtualBox is an Open Source tool, known as a cross-platform virtualization application or software. It used to run multiple operating systems or virtual machines simultaneously on a single hardware. In this VirtualBox installation tutorial, we will explain the...

Follow Us

Our Communities

More on CentOS

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

twenty − thirteen =

Shares