How to Permanently Disable Apache (httpd) Service on CentOS 6: chkconfig vs Upstart vs Traditional Init


2 views

When working with CentOS 6, you might encounter a hybrid init system. While the system shows /sbin/init as PID 1, CentOS 6 actually uses a transitional approach between traditional System V init and Upstart. This explains why your httpd.override attempt failed.

First, verify your system's init approach:

# Check for Upstart compatibility
ls /etc/init/*.conf 2>/dev/null

# Check for traditional init scripts
ls /etc/rc.d/init.d/httpd

For CentOS 6, you should use the chkconfig command:

# Stop Apache immediately
service httpd stop

# Disable Apache from starting at boot
chkconfig httpd off

# Verify the service is disabled
chkconfig --list httpd

If you prefer a more thorough approach, you can manually remove symlinks:

# Find all symlinks pointing to httpd init script
find /etc/rc.d -name "*httpd" -exec ls -la {} \;

# Remove all runlevel symlinks
for i in 0 1 2 3 4 5 6; do
    rm -f /etc/rc.d/rc${i}.d/*httpd
done

As you correctly identified, deleting /etc/init.d/httpd isn't ideal because:

  • It's part of the official Apache RPM package
  • Future package updates might restore it
  • It breaks the package manager's tracking

After making changes, confirm Apache won't start on boot:

# Check boot services
chkconfig --list | grep httpd

# Simulate reboot (careful with this in production!)
touch /var/run/rebooting
service httpd status

Consider these optional cleanup actions:

# Remove Apache from xinetd if present
sed -i '/httpd/d' /etc/xinetd.d/*

# Clean up any remaining processes
pkill -9 httpd

# Verify no httpd processes are running
ps aux | grep httpd

If you suspect Upstart might still be involved, create both configurations:

# For traditional init
chkconfig httpd off

# For Upstart (just in case)
echo "manual" > /etc/init/httpd.override

CentOS 6 uses a hybrid init system that combines traditional SysVinit with some Upstart components. The confusion arises because while some services are managed by Upstart, others still follow the SysVinit model. To verify your init system:

# Check init system
$ readlink /proc/1/exe
/sbin/init

# Check if Upstart is installed
$ rpm -q upstart
upstart-0.6.5-16.el6.x86_64

For Apache (httpd) specifically, you should use the traditional chkconfig command rather than Upstart methods:

# Stop the running service
$ sudo service httpd stop

# Disable automatic startup
$ sudo chkconfig httpd off

# Verify it's disabled
$ sudo chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

Apache on CentOS 6 primarily uses the SysVinit script (/etc/init.d/httpd) rather than a native Upstart job. The httpd.override approach only works for services that are primarily managed by Upstart.

If you want to completely remove Apache instead of just disabling it:

# Remove the package
$ sudo yum remove httpd

# Clean up configuration files
$ sudo rm -rf /etc/httpd/

After making these changes, verify that Apache won't start automatically:

# Check service status
$ sudo service httpd status
httpd is stopped

# Simulate reboot (without actually rebooting)
$ sudo init 6

When setting up Nginx, ensure it's configured to start automatically:

# Enable Nginx
$ sudo chkconfig nginx on

# Start Nginx
$ sudo service nginx start