Can I use a MacBook as a server with the lid closed?

Solution 1:

To use a MacBook as a server with the lid closed, all you need to do is to ensure that it's powered on and not in sleep state.

Closing the lid of a MacBook by default puts it into sleep mode irrespective of whether it is plugged into power or running on battery.

One common way to keep the MacBook powered on with the lid closed is to connect an external display (and keeping it plugged-in to power, to make sure that it doesn't run out of power) to your MacBook.

If that is not feasible, or is not an option that you are looking for, you can refer to the solution in the linked discussion:

  • https://apple.stackexchange.com/a/361398/279727

You can accomplish this in terminal. No additional software needed.

Display global power settings:
pmset -g

System-wide power settings:
Currently in use:
 lidwake              1
 autopoweroff         1
 standbydelayhigh     86400
 autopoweroffdelay    28800
 proximitywake        1
 standby              1
 standbydelaylow      10800
 ttyskeepawake        1
 hibernatemode        3
 powernap             1
 gpuswitch            2
 hibernatefile        /var/vm/sleepimage
 highstandbythreshold 50
 womp                 0
 displaysleep         10
 networkoversleep     0
 sleep                1 (sleep prevented by sharingd)
 tcpkeepalive         1
 halfdim              1
 acwake               0
 disksleep            10



To stop sleep entirely:
sudo pmset -a disablesleep 1

To revert, allowing sleep again:
sudo pmset -a disablesleep 0

Solution 2:

The macbook is designed to dissipate a substantial portion of its heat through the keyboard. If you run it closed for a long period of time, it will have reduced performance (as it can't dissipate heat as effectively). Additionally, the added heat could reduce the lifespan of the screen.

None of these effects should be too large, and it will work fine closed, but if you can leave the lid open it will be better for the computer's performance and longevity.

Solution 3:

Use Amphetamine

No need to get another monitor, or to buy an HDMI connector or to execute some terminal command. You just need to download this free and open source utility called Amphetamine.

When you run it, it will appear in your menu bar, you can go ahead and click on the logo. And from now, two clicks are enough to finish this :

Click the "Indefinitely" button. Click "Indefinitely"

Uncheck the middle option saying "Allow system sleep when display is closed" Uncheck the middle option saying "Allow system sleep when display is closed"

And there you go, if you now close your lid, your Mac won't go to sleep. Additionally, if you want to save power and preserve your Mac, you can set the luminosity to the minimum amount (which should make a black screen).