Increasing max processes and files to fix Apache (macOS Monterey)
Posted: Sun Jan 02, 2022 4:39 pm
In Apache, you may start seeing errors:
You notice Apache getting hung, not starting, or forcibly quitting. You likely have a lot of VHOSTS setup and are reaching the default macOS open file and descriptor limits. The default maxfiles limit in macOS Monterey is 256. You can check this by running launchctl limit maxfiles in macOS Terminal.
We will create 2 PLIST files to load on startup to increase maximum files, descriptors, and processes to give Apache more horsepower.
1. Create a file called limit.maxfiles.plist with:
2. Create a file called limit.maxproc.plist with:
3. Put both files in
4. Make the plists root:wheel so macOS has permission to load them on startup. In Terminal type:
sudo chown -R root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo chown -R root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
5. Reboot macOS system.
6. Confirm new limits are in place. In Terminal type: ulimit -a
Note: It appears macOS Monterey may have a limit of setting a maximum of 4000 processes. In addition, you may need to disable SIP (System Integrity Protection in macOS to allow the higher limits. Follow this guide.
There's one annoying cavet to this. If you use MAMP Pro auto start Apache and MySQL plists LaunchDameon scripts, sometimes those load before your maxproc and maxfile plist files causing Apache to not startup with the new file limits. Your new limits wouldn't take affect until you stop/start Apache again. To get around this, need to figure out how to load the plist's in order. Will follow back up here once determined.
Code: Select all
(24)Too many open files: AH00099:
(24)Too many open files: mod_wsgi (pid=931)
We will create 2 PLIST files to load on startup to increase maximum files, descriptors, and processes to give Apache more horsepower.
1. Create a file called limit.maxfiles.plist with:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>64000</string>
<string>524288</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
2. Create a file called limit.maxproc.plist with:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>12784</string>
<string>14176</string>
</array>
<key>RunAtLoad</key>
<true />
<key>ServiceIPC</key>
<false />
</dict>
</plist>
3. Put both files in
Code: Select all
/Library/LaunchDaemons
4. Make the plists root:wheel so macOS has permission to load them on startup. In Terminal type:
sudo chown -R root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo chown -R root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
5. Reboot macOS system.
6. Confirm new limits are in place. In Terminal type: ulimit -a
Code: Select all
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8176
-c: core file size (blocks) 0
-v: address space (kbytes) unlimited
-l: locked-in-memory size (kbytes) unlimited
-u: processes 4000
-n: file descriptors 64000
Note: It appears macOS Monterey may have a limit of setting a maximum of 4000 processes. In addition, you may need to disable SIP (System Integrity Protection in macOS to allow the higher limits. Follow this guide.
There's one annoying cavet to this. If you use MAMP Pro auto start Apache and MySQL plists LaunchDameon scripts, sometimes those load before your maxproc and maxfile plist files causing Apache to not startup with the new file limits. Your new limits wouldn't take affect until you stop/start Apache again. To get around this, need to figure out how to load the plist's in order. Will follow back up here once determined.