CentOS / RHEL 5/6: Uninstall Apache (HTTPD) Server

I do not want to use Apache server on a CentOS / RHEL 6 server. How do I uninstall and remove Apache (HTTPD) server using command line option on Red Hat Enterprise Linux / CentOS / Fedora Linux based server?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 2m
You need to uninstall the following package on a CentOS / RHEL:

  1. httpd
  2. httpd-tools
  3. apr
  4. apr-util

Warning: Backup your Apache data stored in DocumentRoot (default /var/www/), configuration files in /etc/httpd/ and database if any.

Uninstall Apache on a CentOS / Red Hat Enterprise Linux (RHEL)

Login as a root user and type the following yum command:
$ sudo yum erase httpd httpd-tools apr apr-util
# yum erase httpd httpd-tools apr apr-util
Sample outputs:

Loaded plugins: downloadonly, fastestmirror, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package apr.x86_64 0:1.3.9-5.el6_2 will be erased
---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be erased
--> Processing Dependency: apr-util = 1.3.9-3.el6_0.1 for package: apr-util-ldap-1.3.9-3.el6_0.1.x86_64
---> Package httpd.x86_64 0:2.2.15-29.el6.centos will be erased
---> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be erased
--> Running transaction check
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
 Package             Arch         Version                     Repository   Size
 apr                 x86_64       1.3.9-5.el6_2               @base       296 k
 apr-util            x86_64       1.3.9-3.el6_0.1             @base       198 k
 httpd               x86_64       2.2.15-29.el6.centos        @base       2.9 M
 httpd-tools         x86_64       2.2.15-29.el6.centos        @base       137 k
Removing for dependencies:
 apr-util-ldap       x86_64       1.3.9-3.el6_0.1             @base       9.3 k
Transaction Summary
Remove        5 Package(s)
Installed size: 3.6 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : httpd-2.2.15-29.el6.centos.x86_64                            1/5 
  Erasing    : httpd-tools-2.2.15-29.el6.centos.x86_64                      2/5 
  Erasing    : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         3/5 
  Erasing    : apr-util-1.3.9-3.el6_0.1.x86_64                              4/5 
  Erasing    : apr-1.3.9-5.el6_2.x86_64                                     5/5 
  Verifying  : httpd-2.2.15-29.el6.centos.x86_64                            1/5 
  Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         2/5 
  Verifying  : httpd-tools-2.2.15-29.el6.centos.x86_64                      3/5 
  Verifying  : apr-util-1.3.9-3.el6_0.1.x86_64                              4/5 
  Verifying  : apr-1.3.9-5.el6_2.x86_64                                     5/5 
  apr.x86_64 0:1.3.9-5.el6_2          apr-util.x86_64 0:1.3.9-3.el6_0.1        
  httpd.x86_64 0:2.2.15-29.el6.centos httpd-tools.x86_64 0:2.2.15-29.el6.centos
Dependency Removed:
  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                                        

Update you firewall config

You need to edit /etc/sysconfig/iptables and remove line that allows TCP port 80/443 for Apache:
# vi /etc/sysconfig/iptables
Find and remove line as follows:

## open port 80 /443 ##
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Save and close the file. Restart iptables:
# service iptables restart
You need to repeat the same steps for ip6tables – IPv6 packet filter by editing /etc/sysconfig/ip6tables
# vi /etc/sysconfig/ip6tables
Find and remove line as follows:

## open port 80 /443 for IPv6 ##
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Save and close the file. Restart the ip6tables service:
# service ip6tables restart

Related media

This tutorial is also available in a quick video format:

(Video 01: Uninstall Apache Server on a CentOS / Red Hat Enterprise Linux)

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Nitin Rajpurohit May 20, 2015 @ 7:22

    why i need to Update firewall config as abowe given

  • Nitin Rajpurohit May 21, 2015 @ 6:30

    How to remove all reference files after uninstalling apache from CentOs

  • Pulsel Jul 25, 2015 @ 16:25

    thank you so much, it’s wonderful

  • aref ghobadi Aug 16, 2015 @ 11:04

    thanks, it is useful

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum