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.
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.