How to Completely Remove and Install Apache package on CentOS 7.6

To Completely Remove And Install the Apache Package On Centos 7.6

Procedure:

  1. Query and list all the Apache rpm packages.

  2. list the installed httpd and mod packages

  3. Remove the installed httpd and mod packages

  4. Remove the Document root Directory

  5. Check the Apache user in /etc/passwd and remove the user

  6. Remove the Configuration files Of Apache

  7. Remove the Supported files and modules of Apache

  8. Check the service of Apache

  9. Install Apache

  10. Enable And Start the service Of Apache.

  11. Check the service Of Apache

Remove the Apache server:

Before you begin, list all the installed httpd rpm packages.

[root@linuxhelp ~]# rpm -qa "httpd"
httpd-2.4.6-88.el7.centos.x86_64

List the installed httpd packages

[root@linuxhelp ~]# yum list installed "httpd*"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: www.ftp.ne.jp
 * extras: mirror.dhakacom.com
 * remi-php72: remi.schlundtech.de
 * remi-safe: remi.schlundtech.de
 * updates: mirror.nbrc.ac.in
base                                                 | 3.6 kB     00:00     
extras                                               | 3.4 kB     00:00     
extras/7/x86_64/primary_db                             | 201 kB   00:01     
Installed Packages
httpd.x86_64                       2.4.6-88.el7.centos                 @base
httpd-tools.x86_64                 2.4.6-88.el7.centos                 @base

List the installed mod packages.

[root@linuxhelp ~]# yum list installed "mod_*"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: www.ftp.ne.jp
 * extras: mirror.dhakacom.com
 * remi-php72: remi.schlundtech.de
 * remi-safe: remi.schlundtech.de
 * updates: mirror.nbrc.ac.in
Error: No matching Packages to list

Remove the httpd packages by executing the following command.

[root@linuxhelp ~]# yum remove httpd
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be erased
--> Processing Dependency: httpd-mmn = 20120211x8664 for package: php-7.2.17-1.el7.remi.x86_64
---> Package httpd-tools.x86_64 0:2.4.6-88.el7.centos will be erased
--> Running transaction check
---> Package php.x86_64 0:7.2.17-1.el7.remi will be erased
--> Finished Dependency Resolution
.
.
.
.
Removed:
  httpd.x86_64 0:2.4.6-88.el7.centos                                        
  httpd-tools.x86_64 0:2.4.6-88.el7.centos                                  

Dependency Removed:
  php.x86_64 0:7.2.17-1.el7.remi                                            

Complete!

Remove the Document root directory.

[root@linuxhelp ~]# rm -rfv /var/www

Delete the Apache user with the series of following commands.

[root@linuxhelp ~]# grep "apache" /etc/passwd
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

[root@linuxhelp ~]# userdel -r "apache"
userdel: apache mail spool (/var/spool/mail/apache) not found
userdel: apache home directory (/usr/share/httpd) not found

[root@linuxhelp ~]# grep "apache" /etc/passwd

Remove the configuration files of httpd.

[root@linuxhelp ~]# rm -rfv /etc/httpd

Remove the supporting files and httpd modules.

[root@linuxhelp ~]# rm -rf /usr/lib64/httpd

Check the status of httpd.

[root@linuxhelp ~]# systemctl status httpd
Unit httpd.service could not be found.

Installation Of Apache server:

Install the httpd package.

[root@linuxhelp ~]# yum install httpd -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: www.ftp.ne.jp
 * extras: mirror.dhakacom.com
 * remi-php72: remi.schlundtech.de
 * remi-safe: remi.schlundtech.de
 * updates: mirror.nbrc.ac.in
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-89.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-89.el7.centos for package: httpd-2.4.6-89.el7.centos.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-89.el7.centos will be installed
--> Finished Dependency Resolution
.
.
..
.
.


Installed:
  httpd.x86_64 0:2.4.6-89.el7.centos                                                                                                                                                                               

Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-89.el7.centos                                                                                                                                                                         

Complete!

Enable the service of Apache server.

[root@linuxhelp ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

Start the service Of Apache server.

[root@linuxhelp ~]# systemctl start httpd

**Check the status of Apache server. **

[root@linuxhelp ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-05-08 17:23:08 IST; 9s ago

Thus the procedure of completely remove and install the Apache package on Centos 7.6 comes to end.

Tag : Apache CentOS
FAQ
Q
What is the document root directory of Apache server On CentOS 7.6?
A
/var/www/html is the document root directory of Apache server On CentOs 7.6
Q
WHat is the location of the configuration file of Apache On CentOS 7.6?
A
/etc/httpd/conf and /etc/httpd/conf.d are the configuration files location of Apache On CentOS 7.6
Q
How could I check an Apache user On CentOS 7.6?
A
grep apache /etc/passwd to check a particular user On CentOS 7.6
Q
How to delete the Apache user completely On CentOS 7.6?
A
userdel -r apache is the command to delete the user completely On CentOS 7.6
Q
Where could the Apache user be viewed On CentOS 7.6?
A
Under /etc/passwd file, you could find the apache user On CentOS 7.6