So now that we have Apache installed, we're going to configure two virtual hosts on your server.
Why do we need to do this ? Well it's not mandatory to do this, just extremely useful. Having multiple virtual hosts set up allows for you to work on multiple sites at once, without having to hard code links. So you can set it up like it was being hosted all by itself. This prevents having to go through the painful process of going through your pages and editing each link manually after you deploy it. Really it's just a time saver, and it's not that difficult to do.
First thing you want to do is open your "httpd.conf" file located in the conf folder in your Apache installation.Once you open your file, scroll all the way to the bottom and you should see this :
I added a few spaces to show where we're going to insert the code.
Now to add a virtual host. To add a virtual host to your Apache server we have to add something that tells us what the website domain is and where we are going to find it.
First we are going to tell our server what ports we want it to listen to our websites on. We are going to use 80 since that is what the web server is using. So add the code below into the space we made.
NameVirtualHost *:80
What this does is tells the server it is going to be a Name Virtual Host and will be listening for all sites on port 80.
Now that's great and all, but we have to tell it what specifically we are listening for so it knows what to redirect and where to redirect the request. So below the code we just added, lets add a virtual host!
<VirtualHost *:80>
ServerName myfirstphp.tbd
DocumentRoot htdocs/myfirstphp.tbd
</VirtualHost>
So now we have some code telling the web server that a website is located in the folder myfirstphp.tbd that is located in the htdocs folder. It is also telling our browser "Hey, my domain name is myfirstphp.tbd".
So we're done right ? Wrong !
Some things to check for before proceeding :
- Is the folder we told it to look in there ? If not make sure to create it!
- Did you spell everything correctly ?
- Are your ports configured properly ?
- Do you have a webpage inside the folder you told it to look in? If not then create one
If you answered "Yes" then lets continue to configure these virtual hosts!
Now before we can actually type "myfirstphp.tbd" in the browser and have a web page come up, we need to tell your local computer that when you type that in, its local and not an actual domain. So to do that we need to edit the hosts file in windows.
To get to the file:
- Open your Start Menu
- Click Computer
- Double click your C: drive (normally Local Disk)
- Double click Windows
- Double click system32
- Double click drivers
- Double click etc
- Open the file hosts in notepad
Now if you don't see the file there, don't worry. It's actually there, we just need to change some settings to be able to see it. To do that :
- Open your Start Menu
- Click Computer
- Click the Organize drop down item ( on your menu bar)
- Double click Folder and search options
- Click the View tab
- In advance settings find and uncheck : Hide extensions for known file types
- Also in advance settings make sure : Show hidden files,folders, and drives is selected
- Click Apply
Now we have almost successfully set up a virtual host, lets continue.
Make sure the file is opened in notepad ( *WARNING : you may have to run notepad in administrator mode to make changes), and you should see text that looks like this :
Now to add your virtual host and make it active all we have to do is add :
127.0.0.1 myfirstphp.tbd
Add this in the empty space , and save it.
Restart Apache, and now if done correctly you should be able to type http://myfirstphp.tbd:8080 into the address bar of your favorite browser and see your website ! (Make sure you have a webpage in your folder!)
Lets add another one. Follow the same steps but this time lets use the domain mysecondphp.tbd.
Once done, you should have something that looks like this :
Lets add another one. Follow the same steps but this time lets use the domain mysecondphp.tbd.
Once done, you should have something that looks like this :
Rinse and repeat to add a third, fourth, and even fifth virtual host to your server !
Stay tuned for my next post on How To : Install PHP 5
No comments:
Post a Comment