Should I as a developer use var/www in conjuction with apache?

Solution 1:

Apache is a powerful and flexible web server and there is ample documentation on the web.

To get you started:

1) Yes, the default web root is /var/www

2) You can change Apache's behavior if you wish. From your question , I would activate the home directory option.

sudo  a2enmod userdir

Restart apache

To use a directory in your home, make a directory public_html

mkdir ~/public_html

Put your web pages in ~/public_html

FYI: ~ is short hand for your home directory.

You can browse them with

http://server/~username

or

http://localhost/~username

Where "username" is your log in user name.

That should get you started, do not feel overwhelmed if you do not understand all that code yet, you will learn.

See:

Apache symlinked to home directory - Permission Errors

https://help.ubuntu.com/10.04/serverguide/C/httpd.html

Solution 2:

The answers to this question https://askubuntu.com/a/25045/9598 can be illustrative also. In my case I don't wish to change Apache's behavior, just the folder that I am going to use for testing purposes, of which I suggest you to give a chance to this:

However, if we wish to use another local folder for testing in our PHP code, we can change the default folder location used by our php engine to manage these files. This is done using the following procedure:

gksu gedit /etc/apache2/sites-available/default

Provide user password

Then, change all occurrences of "/var/www/" to the folder that we use to test our PHP. (Example: /home/geppettvs/www/ or where appropriate, change "geppettvs" by your local folder.

After that you must restart the computer for the purpose of the changes to take effect. Do not forget also that the files must have the proper file permissions to run properly. (755 is usually sufficient, but some folders [and/or files] may need 777 permissions to read and write them correctly.)

This procedure was working on Natty, and I can't say for 11.10 yet. And I use this trick in order to test PHP, that's why I drop the warning about the 777 permissions for some files/folders.

If you do this, you can gain access to your files via http://localhost instead of calling a given folder name. The "www" folder (or whatever you name it) will be your "public_html" folder.

Good luck!

IMPORTANT: People have suggested that you don't need to restart your machine in order to the changes take effect, but if you don't, then you must stop and restart apache, restart your session and pray for everything to work without a hassle. I suggest you to restart the computer and I can say for sure it will work.