When you make changes to Apache’s configuration file (
/etc/httpd/httpd.conf), you need to restart Apache to get the changes to take effectMy most frequent need for this is when I set up new staging servers using virtual hosting, but it’s the case for any change you make to httpd.conf.
Apple’s built-in way to restart Apache is the use the Personal Web Sharing section of the Sharing panel in System PreferencesJust click Stop and then click StartEasy — but it’s only really convenient if you’ve already got the Sharing prefs panel open.
apachectl gracefulcommand, which requires administrator privileges, which means you’d typically invoke it as
sudo apachectl优雅That’s easy too, but, again, is only convenient if you’ve already got a terminal window open and can remember the exact spelling of ‘apachectl’.
因为我真的很懒，所以我制作了一个AppleScript来做到这一点It’s just one single line:
/图书馆/脚本folder in my home folder, which puts it in my system-wide Scripts menu(You can turn the system-wide Scripts menu on using the AppleScript Utility app in your
So it’s as simple as this: when I need to restart Apache, I choose “Restart Apache” from my system-wide Scripts menu, the script prompts me to authenticate with admin credentials, and that’s it.
更新： Shane Becker演示了如何添加键盘快捷键to the ‘Restart Apache’ script menu item.