How to add new drives, subdomains, and extensions to your website.
How to add new drives, subdomains, and extensions to your website.
Have you ever got to thinking you would like to add more storage space for multimedia files or data files but you don't know how? How about adding a subdomain to point to something like a blog? Or maybe an extension to go to another part of your site? Perhaps you decided to add on the contents of an external hard drive to your website and you don't want to have to copy all of the files over to your server root folder.
Or maybe even you want to start a new site and you want it on a different hard drive than the other site(s).
Well whatever it is that you're wanting to do, there's a couple of options I know on how to do it and the great thing is they're actually really simple. Probably one of the biggest problems comes with running into permissions issues, which you can read more about that here.
Now this article is assuming you've already enabled vhosts. If not, this will not work until done so in the httpd.conf file.
First, let's cover how to put a second or additional website on a different hard drive.
1.) Go to the drive you are wanting the new site to be on and create a folder for it.
It doesn't matter where you put it just as long as you remember the directory path to it. The simpler the better though.
We're going to pretend our server is installed on C:/xampp/ and our new website is E:/newsite/.
2.) Now go ahead and put your website content in E:/newsite/.
3.) Go to your apache/conf/extra/ folder, which ours is going to be C:/xampp/apache/conf/extra,
and open the file called httpd-vhosts.conf . If you don't already have this configured, then you can do so now.
My suggestion is to delete everything in there and paste the following and modify it to your needs.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName myfirstdomain.com
ServerAlias www.myfirstdomain.com
DocumentRoot "B:/xampp/htdocs"
<Directory "B:/xampp/htdocs">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName myseconddomain.com
ServerAlias www.myseconddomain.com
DocumentRoot "E:/newsite"
<Directory "E:/newsite">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
************NOTES ***************
Now all of that may look really complicated, but if you look at it just right, it's quite simple. If you want to read more about what all of that means, take a look at the footnotes located at the bottom.
If you try to restart Apache and it refuses to start, you may have something spelled wrong here or something missing. Check your directory paths and make sure everything is correct.
If you get an Error 500 or Error 403, chances are it's because you don't the the permissions set for the folder you're trying to access. There's other things such as .htaccess files or config files that could be causing the problem too. Refer to your error log in C:/xampp/Apache/logs/error.log file and if you're lucky, it'll even tell you which one is causing the fuss.
***************************************
4.) Notice how my directory for myseconddomain.com is set for the new website.
This tells any traffic coming in on port 80 for myseconddomain.com to go to that folder. It doesn't matter what drive it's on. You could have it on a USB flash drive for that matter if you wanted.
And that's how you do that part. Next, I will tell you how to direct a sub domain to a different directory and how to add on extensions and make them also go to different places.
Sub-domains and web address extensions directing.
Now in this part I will explain how to make your sub-domains and web address extensions go to whichever folder you want them to.
It's pretty much the same thing as above.
** You MUST make sure you have your subdomain forwarded like you did your web address.
Example, you probably fowarded both www.myfirstdomain.com and myfirstdomain.com. You must go back and add subdomain.myfirstdomain.com to your DNS server. Otherwise it will not work and you could get angry thinking it's a setting in your configuration file. To check, point localhost at the directory for your website and verify the content can be viewed. If so, check and make sure spelling is correct for everything. One mispelled letter will cause a major headache.
For sub-domains, you just create a new VirtualHost for it like you did the www.
<VirtualHost *:80>
ServerName blog.myseconddomain.com
ServerAlias www.blog.myseconddomain.com
DocumentRoot "E:/newsite/blog"
<Directory "E:/newsite/blog">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
That's pretty simple huh? You can direct your subdomain to whatever folder you want to and on whatever drive you wish. Just set your DocumentRoot to the desired directory.
And how about the extensions? Just as easy, actually probably a little easier.
Let's say you want to have http://www.myfirstdomain.com/blog/ go to a blog directory somewhere.
Simply add this to the Virtual Host for it:
<VirtualHost *:80>
ServerName myfirstomain.com
ServerAlias www.myfirstdomain.com
DocumentRoot "E:/blogforsite"
<Directory "E:/blogforsite">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>Alias /forum/ "E:/site2forums/"
<directory "E:/site2forums" >
Options Indexes FollowSymlinks Includes MultiViews Includes
AllowOverride All
Order allow,deny
Allow from all
</directory>
</VirtualHost>
And that's it! That was easy wasn't it? So if you wanted to add on a media section to your site and the media files were contained on an external drive, you could use either of the above methods to link to it.
I'll give one file example to make sure you got it.
We decided to use the subdomain method. (Although the extension one doesn't require any additional settings with your DNS server and is considered a lot easier because it is.)
We added media.myfirstdomain.com and it links to our external drive path G:/Media/.
Now we have a song called awonderfulsong.mp3 in G:/Media/ that we want to add a hyperlink to. So then we simply add this for our hyperlink:
http://media.myfirstdomain.com/awonderfulsong.mp3 and that will link you to that file.
As I just mentioned, I might use the extension method due to simplicity and it can make typing long directory extensions much easier when linking several files manually.
** FOOTNOTES **
Perhaps you're curious like myself and want to know what all of the "extra" stuff in the virualhost settings is for.
Here's a basic explanation followed by a link that goes in depth of all of the possible settings available.
Technically, you only need these lines for each VirtualHost:
<VirtualHost *:80>
ServerName blog.myseconddomain.com
ServerAlias www.blog.myseconddomain.com
DocumentRoot "E:/newsite/blog"
</VirtualHost>
What you most commonly will encouter is a problem with the permissions for that directory. It can be a nusiance to track this down and figure out what's causing the problem sometimes. Your Apache error.log a great place to look, as mentioned earlier. But sometimes it may be vague on what's causing it, so a lot of times it's just easier to go ahead and add on the extra bit to solve the issue.
It may not always solve it though. I personally have encountered .htaccess files in the folders blocking those settings. I just move them or delete them. So you want to know what are your possibilities for settings? I thought you'd never ask. Check this link out:
http://httpd.apache.org/docs/2.2/mod/quickreference.html
Once you get a good grasp on VirtualHosts, you will have a lot more control over how and where your content is stored. This can be handy in many ways. Use your imagination.
Last Updated (Tuesday, 06 January 2009 17:29)






