How to install Apache Web Server on CentOS 7

CentOS Tutorial–CentOS is a great operating system for server. On this quick tutorial, I am going to show you how to install and configure Apache web server on CentOS 7. At the end, you will have a fully working web server on CentOS 7. I assume you have a fresh install of CentOS 7. I recommend you to install the core only, without any desktop environment.

Steps to install Apache Web Server on CentOS 7

Step 1. Install Apache

Execute the following command to install apache web server.

sudo yum install httpd

Example:

[root@localhost ~]# yum install httpd
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: centos.mirror.angkasa.id
 * extras: centos.mirror.angkasa.id
 * updates: centos.mirror.angkasa.id
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos.4 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7.centos.4 for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.centos.4.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-45.el7.centos.4 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================
 Package                           Arch                         Version                                     Repository                     Size
================================================================================================================================================
Installing:
 httpd                             x86_64                       2.4.6-45.el7.centos.4                       updates                       2.7 M
Installing for dependencies:
 apr                               x86_64                       1.4.8-3.el7                                 base                          103 k
 apr-util                          x86_64                       1.5.2-6.el7                                 base                           92 k
 httpd-tools                       x86_64                       2.4.6-45.el7.centos.4                       updates                        84 k
 mailcap                           noarch                       2.1.41-2.el7                                base                           31 k

Transaction Summary
================================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]:

Type y to confirm the installation.

Step 2. Configure httpd

Edit the file /etc/httpd/conf/httpd.conf using nano or vim.

nano /etc/httpd/conf/httpd.conf

Add the following lines at the end of the file:

ServerTokens Prod
KeepAlive On

Close and save the file

Step 3. Configure firewalld

We need to configure the firewall to allow http traffic. Use this command instead

firewall-cmd --add-service=http --permanent 
firewall-cmd --reload

Make sure it returned “success”.

Step 4. Start apache and enable during startup

systemctl start httpd
systemctl enable httpd

Step 5. Test it out

Type the server ip address on a web browser from other computer. You should see the default test page shown on your web browser. This means our web server is up and running.

 

Admin

Leave a Reply

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