The symlinks in your rc*.d directories show an interesting pattern - all runlevels (0-6) have K15httpd (Kill) scripts, but no S* (Start) scripts. This explains why Apache won't autostart. On Amazon Linux AMI (which uses SysVinit), services need S* symlinks in the appropriate runlevel directories to start automatically.
# Current incorrect state
find /etc/rc.d -name "*httpd*" | xargs ls -l
# Expected correct state should include S* symlinks
S85httpd -> ../init.d/httpd # In runlevels where it should start (typically 3,5)
For Amazon Linux AMI (based on RHEL/CentOS 6), you should use the chkconfig
command instead of manually managing symlinks:
# Check current configuration
chkconfig --list httpd
# Correct configuration (example output):
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# To set this up:
sudo chkconfig httpd on
If you're using a newer Amazon Linux AMI version with systemd, the approach changes:
# Check if systemd is present
which systemctl
# Enable autostart
sudo systemctl enable httpd.service
sudo systemctl is-enabled httpd.service # Verify
Sometimes autostart fails due to missing dependencies. Check the init script headers:
# View init script requirements
head -n 20 /etc/rc.d/init.d/httpd
# Look for these lines:
# chkconfig: 345 85 15
# description: Apache web server
The numbers after "chkconfig:" indicate:
- Runlevels (3,4,5)
- Start priority (85)
- Kill priority (15)
If chkconfig
isn't working, you can manually create symlinks:
# For runlevel 3 (multi-user)
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S85httpd
# For runlevel 5 (graphical)
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd
After making changes, test without rebooting:
# Simulate startup sequence
sudo /etc/rc.d/rc.local
sudo service httpd status
# Or force runlevel change
sudo telinit 3
When dealing with Amazon Linux AMI 2012.03, I noticed Apache HTTPD (httpd
) fails to start automatically on system boot despite manual starts working perfectly via:
/etc/init.d/httpd start
The symlinks in /etc/rc.d/
appear correctly configured:
find /etc/rc.d -name "*httpd*" | xargs ls -l
-rwxr-xr-x 1 root root 3371 Feb 16 2012 /etc/rc.d/init.d/httpd
lrwxrwxrwx 1 root root 15 Apr 14 2012 /etc/rc.d/rc0.d/K15httpd -> ../init.d/httpd
[... other symlinks ...]
The key issue lies in the symlink naming convention. Notice all links begin with K15
(kill) rather than S85
(start) in runlevels 2-5. This explains why other services like MongoDB and Postfix start while Apache doesn't.
To verify runlevel configuration:
chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
For SysV init systems, use chkconfig
to properly configure startup:
chkconfig --add httpd
chkconfig httpd on
This creates correct symlinks for all runlevels. Verify with:
ls -l /etc/rc.d/rc{3,4,5}.d/S*httpd*
For systems transitioning to systemd (though not applicable to 2012.03 AMI):
systemctl enable httpd
systemctl is-enabled httpd
If permissions are suspected:
ls -l /etc/init.d/httpd
chmod +x /etc/init.d/httpd
Add debug output to the init script:
vim /etc/init.d/httpd
# Add near the top:
echo "Apache init script executed at $(date)" >> /var/log/httpd-init.log
Check boot logs post-reboot:
dmesg | grep httpd
journalctl -b | grep httpd # For newer systems
After making changes, validate with:
chkconfig --list httpd
# Should show 'on' for runlevels 2-5
reboot
ps aux | grep httpd
curl -I localhost