Coding

Run Apache as your user for fewer conflicts


When writing code, so many things can go wrong. So many little things can be forgotten or overlooked and cause bugs and interruption. However, your time is finite and your patience is limited. Removing all these little causes of frustration pays incredible dividends down the line.

One of the frustrations I regularly encounter is failing to save a file in our backend tool after making modifications in SVN, which is caused by a permissions conflict. The user I run SVN as (me) is different from the user I run Apache as (_www by default), which means that if when I own a file, Apache can run into trouble trying to save it (such as through our backend tool).

For a while, I depended on a custom bash script that would recursively modify the permissions in my development folder, but I still have to remember to run that script every time I make certain modifications via SVN. Every once in a while I’ll forget and get glaring error messages. It breaks my flow, which slows me down and frustrates me. Thankfully, there is an easy solution.

Be someone else

If Apache runs as the same user that SVN does, suddenly these problems dissappear. They both have the same rights and access to the files, and no longer need I worry about running scripts to fix things.

Kick open a console:

$ sudo nano /etc/apache2/httpd.conf

Find the line that says:

User _www

And change “_www” to your username. If you’re not sure what that is, type “whoami” at the console to find out. With that done, save and restart Apache:

$ sudo apachectl restart

From here on out, your problems should be solved! (Well, you may need to change permissions on or remove certain files created by _www, like session files.) Apache will open and save files as you, so as long as you have access, so too will your web server.

Coding
Code faster with simple Sublime Text improvements
Coding
Rage-quit support for fish shell
Coding
Gulp.js – an AMAZING build system!
  • Giorgio

    GiorgioGiorgio

    Author

    Quick note for Linux users:

    – The Apache config will be located elsewhere: /etc/httpd/conf/httpd.conf
    – Restart using the service command: service httpd restart

    Great post, Dan!