Increasing max processes and files to fix Apache (macOS Monterey)

All MAMP discussions around troubleshooting and anything related to MAMP. Be as detailed as possible here when posting an issue.
Post Reply
mampsupportmod
Site Admin
Posts: 156
Joined: Wed Jan 20, 2021 3:06 am

Increasing max processes and files to fix Apache (macOS Monterey)

Post by mampsupportmod »

In Apache, you may start seeing errors:

Code: Select all

(24)Too many open files: AH00099:
(24)Too many open files: mod_wsgi (pid=931)
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.

Launchctl Limit Maxfiles 256 Macos Monterey
Launchctl Limit Maxfiles 256 Macos Monterey (9.65 KiB) Viewed 6550 times


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



Maxproc Maxfiles Plist Root Wheel Permissions Macos Monterey
Maxproc Maxfiles Plist Root Wheel Permissions Macos Monterey (60.81 KiB) Viewed 6551 times


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

Ulimit Macos Monterey New Limits
Ulimit Macos Monterey New Limits (27.38 KiB) Viewed 6547 times


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.
MAMP Support Forums is an unofficial support forum covering MAMP & MAMP Pro solution stacks.
Post Reply