1

I had to install a custom Apache on OSX because I needed a very specific configuration for a client and I could not make the default one work correctly with it, unfortunately.

So, I saw how to start in manually, using apachectl binary:

sudo /usr/local/apache2/bin/apachectl start

And I also saw I can make the default Apache start with a launchctl command.

But, how could I make a custom installed to start at boot, instead of the default one? If it's possible, I would like to use system's launchctl.

2 Answers2

3

Solution:

Unload default Apache:

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

Create a LaunchDaemon file ( /Library/LaunchDaemons/com.aaa.launchd.apache2.plist ):

<?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>com.aaa.launchd.apache2</string>
<key>ProgramArguments</key>
<array>
    <string>/usr/local/apache2/bin/apachectl</string>
    <string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Change file owner:

sudo chown root:wheel /Library/LaunchDaemons/com.aaa.launchd.apache2.plist

And, finally, add it to be loaded on boot:

sudo launchctl load -w /Library/LaunchDaemons/com.aaa.launchd.apache2.plist
2

You would do the same as the launchctl procedure you linked to. The missing piece is that you need to make your own launchd.plist and save it in the LaunchDaemons/ directory. man launchd.plist for information on the plist format; or, you can probably copy the original apache one and change the path to suit your needs.

Kent
  • 1,734