Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run an alternate install of apache httpd (don't ask) on my Mac. I can do it but it only runs as long as I'm logged in, and I keep having to type

sudo /opt/local/apache2/bin/apachectl -k start

and was wondering if there was a way to setup a service on my Mac so I don't have to keep doing this.

share|improve this question
up vote 2 down vote accepted

The best option is to use launchd the built in replacement for cron, init and xinetd. To do so you need to create an XML document (specifically a .plist) to define what you want to do. A program called Lingon provides an excellent GUI for doing this and the installation as well.

You can save the following file as com.example.apache2.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

You then want to install this .plist within /Library/LaunchDaemons because you want this to run when the computer starts up (as a service). You can do this by copying the file to /Library/LaunchDaemons (User Daemons in Lingon) and running the command sudo launchctl load -w /Library/LauchDaemons/com.example.apache2.plist. Then whenever the computer is started up, the command is run. Of note, Launch Daemons in /Library are run as root so you don't need the sudo.

For more information on launchd, check out the man page, the man page for launchd.plist, Getting Started with launchd, or you can search here on Super User as there are several questions already about launchd.

share|improve this answer
great! Thanks, there was actually a /Library/LaunchDaemons/org.macports.apache2.plist already there, so I looked at it and then ran that. – Jason S Nov 17 '09 at 1:13

The correct way to do this would be through launchd.

share|improve this answer
Why the downvote - this is the easiest method (albeit the question would be more helpful with actual instructions). – Chealion Nov 16 '09 at 5:27
Because your solution is ridiculously convoluted, won't actually work and shouldn't be used by anyone. – Hasaan Chop Nov 16 '09 at 18:45
@NSD: What is that in relation to? My question was in relation to a downvote on your answer. – Chealion Nov 17 '09 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .