These steps will vary slightly depending on your version of macOS.
Open
System Preferences.
Click
Battery.
Click Options.
Set Put hard disks to sleep when possible to Never. If you don't see this option, move on.
Set Wake for network access to Always.
On the left, click Displays.
Click Advanced.
Toggle on Prevent automatic sleeping on power adapter when the display is off.
