CentOS 7 / RHEL 7 : How To Install And Configure Apache HTTP Server

For A Linux administrator, you probably want to know that how to setup or configure  Apache web server under new CentOS 7 or Red Hat Enterprise 7 linux?  How do I install httpd package to configure Apache web server under centos 7 or RHEL 7 operating system? this tutorial shows how you can install an Apache Http Server on Centos 7 system.

For Centos 7 or RHEL 7 linux version, there is a big change is that the name of network interface changed from “eth*” to “eno*“,  you can have a refer for change centos 7 network interface name if you want.

​CentOS Configure Apache HTTP Server

Step1# CentOS 7 /RHEL Install Httpd Package

Before configuring Apache web server, you need install Httpd package firstly, directly issue the following yum command:

yum install httpd

Outputs:

[root@osetc Desktop]# yum install httpd

Loaded plugins: fastestmirror, langpacks

base                                                     | 3.6 kB     00:00

extras                                                   | 3.4 kB     00:00

updates                                                  | 3.4 kB     00:00

updates/7/x86_64/primary_db                                | 4.8 MB   00:04

Loading mirror speeds from cached hostfile

* base: mirrors.btte.net

* extras: mirrors.btte.net

* updates: mirrors.nwsuaf.edu.cn

Resolving Dependencies

--> Running transaction check

---> Package httpd.x86_64 0:2.4.6-18.el7.centos will be installed

--> Processing Dependency: httpd-tools = 2.4.6-18.el7.centos for package: httpd-2.4.6-18.el7.centos.x86_64

--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-18.el7.centos.x86_64

--> Running transaction check

---> Package httpd-tools.x86_64 0:2.4.6-18.el7.centos 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-18.el7.centos         updates       2.7 M

Installing for dependencies:

httpd-tools       x86_64       2.4.6-18.el7.centos         updates        77 k

mailcap           noarch       2.1.41-2.el7                base           31 k

Transaction Summary

================================================================================

Install  1 Package (+2 Dependent packages)

Total download size: 2.8 M

Installed size: 9.6 M

Is this ok [y/d/N]:

Downloading packages:

warning: /var/cache/yum/x86_64/7/base/packages/mailcap-2.1.41-2.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Public key for mailcap-2.1.41-2.el7.noarch.rpm is not installed

(1/3): mailcap-2.1.41-2.el7.noarch.rpm                     |  31 kB   00:02

Public key for httpd-2.4.6-18.el7.centos.x86_64.rpm is not installed  00:00 ETA

(2/3): httpd-2.4.6-18.el7.centos.x86_64.rpm                | 2.7 MB   00:03

(3/3): httpd-tools-2.4.6-18.el7.centos.x86_64.rpm          |  77 kB   00:03

--------------------------------------------------------------------------------

Total                                              750 kB/s | 2.8 MB  00:03

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Importing GPG key 0xF4A80EB5:

Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"

Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5

Package    : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@anaconda)

From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Is this ok [y/N]: y

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Warning: RPMDB altered outside of yum.

** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:

open-vm-tools-desktop-9.4.0-3.el7.x86_64 has missing requires of libhgfs.so.0()(64bit)

open-vm-tools-desktop-9.4.0-3.el7.x86_64 has missing requires of libvmtools.so.0()(64bit)

open-vm-tools-desktop-9.4.0-3.el7.x86_64 has missing requires of open-vm-tools(x86-64) = ('0', '9.4.0', '3.el7')

Installing : httpd-tools-2.4.6-18.el7.centos.x86_64                       1/3

Installing : mailcap-2.1.41-2.el7.noarch                                  2/3

Installing : httpd-2.4.6-18.el7.centos.x86_64                             3/3

Verifying  : mailcap-2.1.41-2.el7.noarch                                  1/3

Verifying  : httpd-tools-2.4.6-18.el7.centos.x86_64                       2/3

Verifying  : httpd-2.4.6-18.el7.centos.x86_64                             3/3

Installed:

httpd.x86_64 0:2.4.6-18.el7.centos

Dependency Installed:

httpd-tools.x86_64 0:2.4.6-18.el7.centos     mailcap.noarch 0:2.1.41-2.el7

Complete!

Step2# Congiure httpd configuration file named httpd.conf

Before edit httpd.config file, you’d better have a backup for this file, type:

cp httpd.conf httpd.conf.bak

Edit “/etc/httpd/conf/httpd.conf” file using “vim” command, type:

vim /etc/httpd/conf/httpd.conf

set new values for “ServerAdmin“, ” ServerName“, “AllowOverride” , “DirectoryIndex” and “keepAlive” fields just like the below:

ServerAdmin  itsprite@gmail.com         # set its value as admin's email address

ServerName    www.itsprite.com :80      # set its value as your web server's domain name

AllowOverride  all                             # set its as "all"

DirectoryIndex index.html index.php     # add file name if your www directory have index.php file.

DocumentRoot  "/var/www/html"           #By default, all requests are taken from this directory

Step3# Enable httpd service while system startup

issue the following command to start httpd server automatically while system booting up, type:

systemctl enable httpd.service

Outputs:

[root@osetc Desktop]# systemctl enable httpd.service

ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

Step4# Start Apache httpd service, issue the following command:

systemctl start httpd.service

Outputs:

[root@osetc Desktop]# systemctl status httpd.service

httpd.service - The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)

Active: active (running) since Thu 2014-12-04 10:13:36 EST; 7s ago

Main PID: 12630 (httpd)

Status: "Processing requests..."

CGroup: /system.slice/httpd.service

├─12630 /usr/sbin/httpd -DFOREGROUND

├─12631 /usr/sbin/httpd -DFOREGROUND

├─12632 /usr/sbin/httpd -DFOREGROUND

├─12633 /usr/sbin/httpd -DFOREGROUND

├─12636 /usr/sbin/httpd -DFOREGROUND

└─12637 /usr/sbin/httpd -DFOREGROUND

Dec 04 10:13:36 osetc systemd[1]: Started The Apache HTTP Server.

Step5# Create a HTML test page under DocumentRoot directory (the default is “/var/www/html”), type:

$sudo echo "this is a test page" >/var/www/html/index.html

Step6# Verifying the test page can be resolved by Apache HTTP Server

Open firefox brower, and input address “127.0.0.1”, if you can see the below similar page, indicated that your Apache web server was setup successfully.

You might also like:

Sidebar



back to top