I don’t actually host any web sites from my PC but I often do web development on it. As such I run Apache on this machine. I read about Mod_UserDir in Linux Format Magazine (best Linux mag out there) and thought I’d give it a shot. Why? Well, when installing Apache, the root web directory is /var/www which is owned by root. When I need to put new files there I have to either do it via sudo and cp or do sudo nautilus, etc to get permission to write to that directory. Then, if I want to modify a file there (index.html for instance) I have to remember to launch BlueFish, Kate, etc as root in order to have write access to the folder. This isn’t the biggest pain ever and I could probably grant extra permissions to the folder or pursue some other avenue. However, using mod_UserDir allows me a little easier time of it. Here’s how to do it:
1. Go to /etc/apache2/sites-available/ and type sudo gedit default.
2. Once the default file opens, add a new line: UserDir public_html which I put directly under the ServerAdmin line. You can also add extra lines to only allow certain users in there – search google for mod_UserDir for info.
3. Restart apache (sudo apache2ctl –restart) and now you have the ability to create your own user dir.
4. Go to your home directory and create a folder called public_html and put anything you like in it.
5. Browse to http://localhost/~yourname/ and you will see your stuff.
The nice feature here is that because it is in your own home directory you have full read/write access to all of the files. Being that I’m not actually publishing anything to the web I don’t mind the ~ operator in there and it makes local web development a lot easier.