Add Hard and Soft Limits for Apache Stack
Luke Hebert
- 2 minutes read - 227 wordsApache workers running under the nobody user can hit segmentation faults or unexpected crashes when the default stack size is too small for the workload. Raising the soft and hard stack limits in /etc/security/limits.conf gives each worker thread enough room to operate without being killed by the kernel.
Editing limits.conf
Open the limits file with your preferred editor:
sudo vi /etc/security/limits.confAppend the following two lines to set the soft and hard stack limits for the nobody user:
nobody soft stack 1024
nobody hard stack 2046Values are expressed in kilobytes. A soft limit of 1024 KB (1 MB) and a hard limit of 2046 KB (~2 MB) are common starting points for Apache on systems with moderate thread counts. Adjust upward if your workload requires deeper call stacks.
Applying the Changes
The limits file is read at login time, so you need to restart Apache for the new values to take effect:
sudo systemctl restart httpdVerifying
Confirm the running Apache processes picked up the new limits:
cat /proc/$(pgrep -n httpd)/limits | grep "stack size"You should see the soft and hard values match what you set in limits.conf.
Setting the hard limit lower than the soft limit will cause the soft limit to be rejected. Always ensure the hard value is greater than or equal to the soft value.