When diagnosing Apache2 startup failures, we need to examine multiple indicators:
# System service status shows Apache isn't running despite apparent successful start
$ service --status-all
[ - ] apache2
# Error logs reveal critical thread creation failures
[Sat May 01 14:45:18 2010] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
The key error apr_thread_create: unable to create worker thread
typically indicates one of:
- System resource exhaustion (ulimit restrictions)
- Process limit reached (max user processes)
- Memory constraints
- Zombie Apache processes holding resources
First, check current system limits and resource usage:
# Check process limits
$ ulimit -a
# Count existing Apache processes
$ ps -ef | grep apache | grep -v grep | wc -l
# Check system-wide process limit
$ cat /proc/sys/kernel/threads-max
# Verify available memory
$ free -h
1. Cleaning Up Stale Processes
# Force kill all Apache processes
$ sudo pkill -9 apache2
# Remove stale PID file
$ sudo rm -f /var/run/apache2.pid
2. Adjusting System Limits
Edit /etc/security/limits.conf
:
www-data soft nproc 1024
www-data hard nproc 2048
* soft nproc 4096
* hard nproc 8192
3. Optimizing Apache Configuration
Modify /etc/apache2/apache2.conf
:
# Reduce worker threads if system resources are limited
StartServers 2
MinSpareThreads 4
MaxSpareThreads 8
ThreadLimit 16
ThreadsPerChild 8
MaxRequestWorkers 16
For persistent issues, examine kernel messages:
$ dmesg | grep -i 'thread'
$ cat /var/log/kern.log | grep -i 'limit'
- Implement proper Apache graceful restart procedures
- Monitor system resources with tools like Nagios or Datadog
- Consider using mod_event instead of worker MPM for high-traffic servers
When your Apache2 service appears to start successfully but fails to maintain operation, you're likely dealing with deeper system resource issues. The key indicators in your logs are:
[alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[alert] No active workers found... Apache is exiting!
First, verify the actual process status:
ps aux | grep apache
systemctl status apache2
ulimit -a
Check for competing processes that might be consuming resources:
lsof -i :80
lsof -i :443
netstat -tulnp | grep -E '80|443'
The "Resource temporarily unavailable" error typically indicates one of:
- System-wide process/thread limit reached
- Insufficient memory for thread creation
- Zombie Apache processes holding resources
- Improper MaxClients/MaxRequestWorkers configuration
Increase system limits by editing /etc/security/limits.conf
:
* soft nproc 10000
* hard nproc 10000
* soft nofile 10000
* hard nofile 10000
www-data soft nproc 10000
www-data hard nproc 10000
Adjust Apache's MPM configuration (/etc/apache2/mods-available/mpm_prefork.conf
or equivalent):
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
Force clean any lingering processes:
pkill -9 apache2
rm -f /var/run/apache2/apache2.pid
service apache2 start
For systemd-based systems, add proper resource limits:
# Create/edit /etc/systemd/system/apache2.service.d/limits.conf
[Service]
LimitNOFILE=10000
LimitNPROC=10000
After changes, verify operation:
systemctl daemon-reload
service apache2 restart
apache2ctl status
journalctl -u apache2 --since "1 hour ago"
Monitor thread creation with:
watch -n 1 "ps -eLf | grep apache | wc -l"