How to Make Apache Start httpd Automatically on Boot in Mac OS X

Aug 30, 2015 - 3 Comments

Start Apache in Mac OS X Automatically

Mac based web developers are probably familiar with manually starting and stopping the Apache web server in OS X through the command line by now, but if you want Apache to start itself automatically upon boot and reboot of a Mac, you’ll want to go a step further and use launchctl. By doing so, webdevs won’t need to run the apache start commands manually to start the Apache httpd daemon, it will start itself automatically each time the Mac boots up. Naturally, we’ll also show how to stop Apache from starting itself up on boot as well.


Essentially what these commands do is load the apache web server launch daemon into OS X upon system start. Because it uses launchctl you’ll need to have administrator access through sudo to load or unload apache. Remember, this is only necessary for more modern versions of OS X which no longer have a ‘web sharing’ option in the Sharing preference panel.

Note: This assumes you have already configured and setup Apache on the Mac, if you have not done so already you should start there, otherwise you’re auto-loading Apache without much configuration.

Set Apache to Start Automatically on Boot in Mac OS X

From the Terminal, enter the following command:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Hit return and enter the admin password as requested to complete the job.

Now when the Mac is booted or rebooted, Apache will start automatically, which is easily verified by going to any browser and entering “localhost” as the URL.

Apache web server running automatically on boot in Mac OS X at localhost

You’ll see the familiar “It Works!” message at localhost and those core files are located in:

/Library/WebServer/Documents/

Going further, you can also enable the user level Sites option for localhost/~User, but that’s beyond the scope of this article, we cover that here.

Stop Apache from Loading on Boot in Mac OS X

To stop Apache from starting itself automatically upon system start, you simply need to remove the agent from launchd as with any other daemon, like so:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Again you will need to enter the admin password to confirm the change.

Determine if Apache is Loaded or Unloaded in launchd

If you’re not sure whether you have set Apache to load automatically or not, you can query launchd for apache like so:

launchctl list|grep apache

Don’t see apache.httpd returned? Then the daemon is not loaded, and it will not automatically start. Apache can still be used and started manually, but it won’t start itself with a reboot or boot, pretty simple.

If configuring Apache, PHP, and MySQL in OS X sounds overly complicated or is deemed too much of a hassle, another great solution is to use a pre-configured web server package like MAMP. MAMP offers a self contained web server solution as well, with Apache, PHP, and MySQL already included in an a single application package, a user just launches MAMP app and begins the necessary services to start and stop a web server for local development. MAMP is powerful and a great tool for Mac based web developers, and it involves generally much less tinkering and complexity than manually configuring the individual components to run in OS X yourself. Either solution can be great, so use whichever works for you and your comfort level.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

3 Comments

» Comments RSS Feed

  1. P Fan says:

    Actually apachectl [ start | stop ] already calls the launchctl [ load | unload ] -w …. So if you execute
    apachectl start, your web server will start at reboot. Have a look at the /usr/sbin/apachectl script.

  2. Wharf Xanadu says:

    Well this is cool. Works in el capitan too. Just rebooted to verify. For single person workstation local host is sufficient no need for the user folders. Thanks.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site