Running unnecessary services on production servers is a security risk and wastes system resources. On a database server, having Apache HTTPD automatically start up serves no purpose and creates potential attack surfaces.
First, verify if Apache is actually running:
sudo systemctl status httpd
Or for older sysvinit systems:
service httpd status
For modern CentOS/RHEL 7 and above using systemd:
sudo systemctl disable httpd sudo systemctl stop httpd
To verify it won't start on boot:
systemctl is-enabled httpd
For CentOS 6 or older systems using init scripts:
sudo chkconfig httpd off sudo service httpd stop
Verify with:
chkconfig --list httpd
Deleting /etc/init.d/httpd
isn't recommended because:
- Package updates might restore it
- You lose the ability to manually start/stop Apache when needed
- Other dependent services might expect it to exist
If you'll never need Apache on this server:
sudo yum remove httpd
Or to remove all Apache-related packages:
sudo yum remove 'httpd*'
After stopping Apache, verify ports 80 and 443 are free:
sudo netstat -tulnp | grep -E '80|443'
For maximum security on a database server:
sudo firewall-cmd --permanent --remove-service=http sudo firewall-cmd --permanent --remove-service=https sudo firewall-cmd --reload
Or for iptables:
sudo iptables -D INPUT -p tcp --dport 80 -j ACCEPT sudo iptables -D INPUT -p tcp --dport 443 -j ACCEPT
On a dedicated database server, every non-essential service consumes precious system resources. Apache running unnecessarily can:
- Waste memory (typically 50-150MB per process)
- Create unnecessary network exposure
- Consume CPU cycles during maintenance tasks
- Interfere with port binding if other services need port 80/443
First determine whether your CentOS uses systemd or SysV init:
# Check the init system
ps -p 1 -o comm=
For CentOS 7+, this will typically return "systemd". Older versions may show "init".
For modern CentOS installations (7+):
# Stop Apache immediately
sudo systemctl stop httpd
# Disable automatic startup
sudo systemctl disable httpd
# Verify status
sudo systemctl is-enabled httpd
# Should return "disabled"
For CentOS 6 or earlier:
# Stop Apache
sudo service httpd stop
# Disable auto-start
sudo chkconfig httpd off
# Verify
sudo chkconfig --list httpd
# All runlevels should show "off"
If you want to completely remove Apache (not just disable it):
# For yum-based systems:
sudo yum remove httpd
# For dnf-based systems (CentOS 8+):
sudo dnf remove httpd
After rebooting, verify Apache isn't running:
# Check running processes
ps aux | grep httpd
# Check listening ports
sudo netstat -tulnp | grep ':80\|:443'
Don't forget to:
- Check for residual cron jobs (grep -r httpd /etc/cron*)
- Remove Apache user if unused (userdel apache)
- Clean up configuration files (rm -rf /etc/httpd)