Mac Hacks

Page 62

Figure 2-5. Editing the httpd.conf file in the nano editor.

Automating Apache To make Apache run all the time, you need a way to launch it in the background with root (administrator) permissions. There’s more than one way to pull this off. The short script below does it with a launchd daemon. (Launchd is what starts and stops daemons, and daemons are processes that run in the background without your intervention. There’s also a way to do it with a single command, but the launchd method is more informative.) Create a file called com.brettterpstra.apache.plist (you can change the brettterp stra part to whatever you like, but keep the .plist filetype) in ~/Library/LaunchDaemons (create this folder if it’s not already there). By default, this folder is owned by the root user and the group “wheel” with permissions 644 and contains the following: <?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.brettterpstra.apache</string> <key>ProgramArguments</key> <array> <string>/usr/sbin/apachectl</string>

48

MAC HACKS


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.