How to Fix “httpd dead but subsys locked” Error After Modifying php.ini on Linux Server


2 views

When you encounter the "httpd dead but subsys locked" error after modifying php.ini and restarting Apache, it typically indicates a process conflict and improper service shutdown. The key symptoms include:

Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use
httpd dead but subsys locked

Here's the complete troubleshooting process I've used to resolve this issue on CentOS/RHEL systems:

1. Force Kill All Apache Processes

First, ensure no httpd processes are lingering:

sudo pkill -9 httpd
sudo pkill -9 apache2
sudo rm -f /var/lock/subsys/httpd
sudo rm -f /var/run/httpd.pid

2. Check for Port Conflicts

Verify what's using port 80/443:

sudo netstat -tulnp | grep -E ':80|:443'
sudo lsof -i :80
sudo ss -tulnp | grep -E ':80|:443'

3. Clean Up Lock Files

Remove all lock and PID files:

sudo rm -f /var/run/httpd/*
sudo rm -f /etc/httpd/run/*

4. Verify Apache Configuration

Check your config before restarting:

sudo apachectl configtest
sudo httpd -S

Handling Virtual Host Conflicts

For complex virtual host setups like in your case, check for duplicate configurations:

grep -r "Listen 80" /etc/httpd/
grep -r "NameVirtualHost" /etc/httpd/

Systemd Specific Solution

For systems using systemd:

sudo systemctl stop httpd
sudo systemctl reset-failed httpd
sudo systemctl start httpd

To avoid this issue in future:

# Create a custom restart script
#!/bin/bash
sudo pkill -9 httpd
sudo rm -f /var/lock/subsys/httpd
sudo apachectl configtest
sudo systemctl start httpd

Check log directory permissions:

sudo chown -R apache:apache /var/log/httpd
sudo chmod 755 /var/log/httpd
sudo restorecon -Rv /var/log/httpd

After modifying max_execution_time in php.ini and attempting to restart Apache (httpd), you encountered multiple symptoms:

Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80
no listening sockets available, shutting down
httpd dead but subsys locked

First, verify what's holding port 80:

sudo netstat -tulpn | grep :80
sudo lsof -i :80
ps aux | grep httpd

Common findings might show residual processes:

httpd   1234  0.0  0.5 123456 7890 ?        S    12:34   0:00 /usr/sbin/httpd
httpd   5678  0.0  0.6 234567 8901 ?        S    12:35   0:01 /usr/sbin/httpd

Here's a complete reset sequence:

# Stop Apache forcefully
sudo pkill -9 httpd
sudo service httpd stop

# Remove lock files
sudo rm -f /var/lock/subsys/httpd
sudo rm -f /var/run/httpd.pid

# Verify no processes remain
pgrep -l httpd

# Check for zombie processes
ps -A -ostat,ppid | grep -e '[zZ]'

Inspect critical config files for conflicts:

# Check for duplicate Listen directives
grep -r "Listen 80" /etc/httpd/

# Verify vhost configurations
apachectl -S

# Test configuration syntax
apachectl configtest

After cleanup, execute this restart workflow:

# Release any remaining port locks
sudo fuser -k 80/tcp
sudo fuser -k 443/tcp

# Clear systemd cache if applicable
sudo systemctl daemon-reload

# Start Apache with debug logging
sudo /usr/sbin/httpd -DFOREGROUND -e debug

Add these checks to your restart scripts:

#!/bin/bash
# Pre-restart checklist
if lsof -i :80 | grep -q httpd; then
    echo "WARNING: Existing httpd processes found"
    pkill httpd
    sleep 2
fi

if [ -f /var/lock/subsys/httpd ]; then
    rm -f /var/lock/subsys/httpd
fi

# Normal restart
service httpd restart

When standard methods fail:

# Check SELinux context
ls -Z /var/run/httpd.pid

# Verify filesystem permissions
namei -l /var/log/httpd/error_log

# Monitor system calls during startup
strace -f -o httpd_strace.log /usr/sbin/httpd -DFOREGROUND