Working with WordPress and Drupal with Macbook localhost is good so far. If I am on a terminal, I just cd into the directory and start editing. Drag-and-drop is quick, too. However, manually changing the owner of each file to _www can be a nuisance if you are working something everyday, and you want to see the changes on the browser immediately.
For those who don’t use Macbook’s localhost, _www is the Apache username. In some cases, if a file is not label with _www as owner, the browser may display a permission error, since locahostling requires Apache to access the file and then display the result on the browser.
For the regular Linux user, a simple solution is to just log in as the user _www using su -. Macbook, however, have several hindrance about logging in as _www or just switching to different users on the terminal. That got me curious quickly, so I did some light digging:
- A regular user, even assigned with administrator access, are not allowed to su – into a different user by default.
- Of course, Macbook left some recourse for the admin users should they require root permission. The “Macbook” to gain root access to use sudo.
- On the other hand, if a user sudo into su (repeat that 10 times at triple the speed, please), nothing appears to happen.
- The sudo su command does actually gets executed, hence no error message. However, the default shell of _www is /usr/bin/false. Unlike /sbin/nologin, /false is a binary that immediately exits and returns false. So, you successfully sent the command to change user, but the shell is false, thus the session ends, and you are back to being whatever user you started with with no warning message whatsoever!
- SOLUTION: Just add in an option to retain your current shell. Add in -s for keeping the shell, follow by -u for username: sudo -s -u _www.
After that, I just use vi to create or edit the files!