PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Configure a virtual directory using WAMP

Configure a virtual directory using WAMP


As a web developer many want to test their developments on their local machines. But when it comes to dealing with PHP and MySQL you will need a web server (software) to test the sites you make. Normally we would have to download Apache from www.apache.org , MySQL from MySQL.net and configure these separately to work with each other on our local machine. Also if you want to administer MySQL on the browser you will have to install PHPMyAdmin which is a burden for the novice user.

To tackle these problems there are several packaged solutions on the net. Popular and more robust one is WAMP server. www.wampserver.com .

Let see step by step on how to create a root folder for our new web site that has to be built using PHP.

Step 1: Easiest way!

After installing WAMP on your local machine (You should see a white Speedo meter on the notification area) goes the folder where WAMP resides (If you install it on you C: partition then it is C:/wamp/). The folder structure is as follows,

image 1

Go inside the www folder and create a new folder inside it called "TestSite". This is the rot folder of your web site. Better if you do not put spaces. Open up a simple notepad document and insert the following on it (don't copy the formatting. Just type it),

<?php echo "Hello World!"; ?>

Then same it inside the newly created folder and name it index.php.

Go to your browser and call http://localhost/TestSite/

If you see something like this then you are ready to do building rest of your dynamic web site.

image 2

Step2: Assigning a root folder outside "www".

Well, if we want separate our web site folders from the WAMP server folder and put somewhere else in the hard drive then procedure gets a bit tricky for the beginners.

First create the folder you want as the web site root folder. Let's say D:/MyNewTest/

Now we have to tell the WAMP server that this folder contains a web site and it should come up when the URL is called through the browser right?

Ok, first click on the little Speedometer icon on the notification area. Then go to,

Apache > Alias directories > Add an alias

image 3

Then you will be asked to give an alias to the site, this is what you type after http://localhost/ in the browser. Previous one was "TestSite" which is actually the folder name itself. But this is not necessary in this case. You can put anything. But don't use spaces or dots. J

image 4

Let's put "MySite".

image 5

Then you will be asked what is the actual folder that MySite alias point to.

image 6

Give the following, D:/MyNewTest/

Note the forward slashes.

Configure a virtual directory using WAMP

Now press enter to close the DOS prompt.

Go to your browser and type the http://localhost/MySite/

You will see the root index now. Put the notepad file we created earlier to "D:/MyNewTest"and refresh the browser page to test the PHP.

That is it. Simple isn't it?



Author's URL: Maya Creations
PHP is open source scripting language. It\'s widely used to develop web applications. More PHP Tutorials: Featured Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Reader's comments
comments Magento Multi Store December 05, 2011 says:
This is an excellent information over here. You have provided very valuable and useful information in this post.
Reply
comments Vincent November 05, 2011 says:
Thanks a lot buddy...! This helped. On another note if you think you might have got the actual path to your website directory wrong, then you can go and edit the same with any test editor. Just go to the alias folder "wamp/alias" and open the file named <<alias name>>.conf file. Open it in a notepad and copy the path of your virtual directory in the "Directory" tag as shown below:
<Directory "F:Projects3 Development">

Reply
comments Stefan July 03, 2011 says:
Unfortunately, if you use root-relative urls in your HTML tag attributes, it now doesn't work anymore because the site root folder is still seen as localhost/ instead of localhost/MySite/. For example if you have an image in MySite/images/image.jpg and you use an img tag with src='/images/image.jpg', then the image doesn't load.
Reply
comments Stefa July 14, 2011 says:
I tried various ways to solve the problem with root-relative urls, including using a <base> html tag. However the way it works best for me is to do the following:

1. Setup your virtual/alias directory as specified in this article
2. Edit the httpd.conf file (wamp icon rightclick -> Apache -> httpd.conf):
2a) Comment out 'Document Root: c:/wamp/www/' (by using #)
2b) Comment out the entire "Directory" c:/wamp/www/" section
2c) Replace "Allow Override None" with "Allow Override All" in the "Directory /" section
2d) Add "Allow from

Reply
comments Stefan July 14, 2011 says:
Above comment truncated - here is the rest:

2d) Add "Allow from 127.0.0.1" in the "Directory /" section
2e) Restart all services (wamp icon click -> Restart all services)

Note: "wamp icon rightclick" in previous comment should be "wamp icon click"

Reply
comments personal loans June 11, 2011 says:
Don't have enough money to buy some real estate? You should not worry, just because it's available to take the mortgage loans to work out such problems. So take a bank loan to buy everything you require.
Reply
comments Paige24Roth June 10, 2011 says:
People in the world receive the <a href=" loans</a> from various creditors, just because this is easy and fast.
Reply
comments alistair makayi June 04, 2011 says:
thank you a lot you helped
Reply
comments using zend with redirector May 22, 2011 says:
If your use redirector of zend, the solution won't work!
Reply
comments Romeo November 25, 2010 says:
Thanks a lot this was really helpful i sorted out my issue. At first I wanted to create 2 virtual directory like this: "http : //localhost /Virtual1 /Virtual2" but unfortunately i can make it up only to "http :// localhost /virtual1".

So I used only one virtual directory.

Thanks again.

Reply
comments Dorin GRIGORE May 06, 2010 says:
Thanks.

How do you setup a network driver directory ?

servernamedir
Gives Forbidden

Reply
comments S M Nabeel Dibaji February 23, 2010 says:
Thanks, My Virtual Directory has been Created Successfully :-)
Reply
Add comments to "Configure a virtual directory using WAMP"

Captcha