How do I start/stop Apache from Terminal?

I'm probably making this harder for myself than it has to be, but I'd like to know how to start, stop, or restart Apache from Terminal. I've googled for this command and found the following:


sudo apachectl restart graceful (this simply gives me a reference to the commands I can run, but doesn't seem to do anything)


sudo apachectl -k start

sudo apachectl -k stop


the second two actually work, however I get a 404 not found error. Checking the error log (/private/var/log/apache2/error_log) reports the following:


[Sat Jun 02 00:18:50 2012] [error] [client ::1] File does not exist: /usr/htdocs


I'm confused as to why it's looking in /usr/htdocs when the DocumentRoot is defined as "/Library/WebServer/Documents"


As a note, my server does work normally if I turn web sharing on/off from System Preferences (that is, if i forcefully stop all httpd processes in Activity Monitor and then toggle Web Sharing off/on). But I'd like to know how to avoid using using that option (even though I may rarely have a need to start/stop or restart my local server)

MackBook Pro, Mac OS X (10.5.2)

Posted on Jun 2, 2012 12:40 AM

Reply
2 replies

Jun 2, 2012 8:25 AM in response to alyda

You need to have Web Sharing turned on in the Sharing Preferences pane. This sets the

WEBSHARING_ON
flag which will avoid referencing the /usr/htdocs location.


apachectl is a bit quirky. You can do either restart or you can do graceful. You can't do both.


@Paul Lima,

Plese don't tell people to login as root. That is a very bad idea. This is not Linux. We do things properly here.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I start/stop Apache from Terminal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.