On Ubuntu you can do something like this:

sudo adduser {username} www-data

That doesn't work on OS X, and may not be the best approach anyway. On OS X, how can you make Apache start or stop without having to enter a password?

2 Answers 2


Open Terminal and enter sudo visudo to modify the file /etc/sudoers.

Change the part:

## User privilege specification
root ALL=(ALL) ALL
%admin  ALL=(ALL) ALL


## User privilege specification
root ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
your_username ALL=(ALL) NOPASSWD: /usr/sbin/apachectl

and save the file.

If you don't know vi: after entering sudo visudo you have to change to insert mode by hitting i. Enter the additional line as indicated above. To leave insert mode hit esc. Then enter :wq and the Enter key to write the modified file to disk and quit vi.

Starting and stoping Apache with sudo apachectl start or sudo apachectl stop doesn't require a password anymore.

apachectl requires root/sudo to execute it. Only the root user can execute the command without entering a password. Neither adding a user to the admin group nor to another group (e.g. _www) allows to execute (sudo )apachectl without password.

So, the least intrusive method is adding a user - even a standard user - in the sudoers file and restrict the account to execute /usr/sbin/apachectl only. The added user is not allowed to execute any other command as sudoer!

  • Is this better than adding yourself to a group that already has such permissions? Or is there no such group on OS X?
    – iconoclast
    Commented Mar 22, 2016 at 21:15

I don't have the reputation to comment (but I have the rep to answer? What a backwards system), so this is really a response to klanomath's answer.

I just want to make sure people avoid corrupting their etc/sudoers file like I did (and had to restore from Time Machine backup).

Do not edit etc/sudoers in any other way other than running sudo visudo as klanomath said. You will likely corrupt your file and will not be able to run sudo.

Another tip: run which apachectl to determine the path to Apache. Mine was installed via Homebrew so the path is different.

You must log in to answer this question.

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