I’m not sure if my post’s heading puts across exactly what I want to convey. Anyway, I stumbled upon a neat trick which I wanted to share with you folks.
When you usually do PHP development on Ubuntu, you will have to put your files into /var/www or whichever is your document root configured for Apache for the application to be able to run. The downside here is that, you will not always have root permission and every time you either want to add, change or remove a file, you need to do so using ‘sudo’. So what you can do is map any folder (in this case, a folder in your workspace when you use an IDE like Eclipse) to the /var/www (or your document root folder). That way your files will be visible under the /var/www folder and you can execute your files or even debug them without much hassle.
Here is what I did:
1. Go into /var folder and remove the existing www folder
cd /var sudo rm -rf www/
2. Create a folder which you would use as your workspace
cd /home/username/ mkdir workspace/www/
I have set it up this way, so that my Java project go into workspace and all my PHP development goes into workspace/www/ folder
3. Now go back to /var folder and create the mapping
cd /var sudo ln -s /home/username/workspace/www/
That’s it! Now you are all set. Any file you drop into /home/username/workspace/www will be automatically visible in your Apache and you can click on it to run the web application.
Please do let me know if I have done something wrong or if there is anyway to do this better.
PS: Just make sure you don’t have an index.html or something like that inside /www/. If that is there, instead of getting a folder listing you will directly be taken to that page. I think there is a configuration change in Apache that will prevent this from happening. Well, what you would like to do is up to you.
