How to move your xampp localhost files to another location using an alias.
By BartV
Introduction
Why would someone want to move their localhost files and folders, there could be many reasons. The reason I wanted to do this was the fact that I have two computers where I develop my websites on. The problem here was that I always had to copy the files I had worked on at one computer to the other to synchronise them. I started to think about a better way to do this and then realised I had Dropbox running on both the computers. After a long search I figured out how to move these files to my Dropbox so they are always synched, and that is what I am going to explain to you today.
Things you need to know
This how to will explain you how to make an alias to the new location. Why did I choose to add an alias instead of giving the http://localhost/ a new root location? Very simple. You might have noticed some default folders and files in the htdocs folder which belong to the xampp service itself. These are folders like:
- forbidden
- restricted
- xampp
I just didn't want to mess with them so I chose to make an alias and just work from that point on.
What is an alias?
If you know what aliasses are you can skip this part, if you don't I recommend reading this brief explenation.
Aliasses allow you to give a certain url another phisical location. To show you what I mean I will explain you how I use them.
I made an alias called /~dropbox. This means I can access whatever is in this alias by typing http://localhost/~dropbox/ in the address bar of my web browser. The trick here is that I don't have a folder called ~dropbox in my htdocs folder, it is just a pointer to another location on my computer. In my case to a certain folder in my Dropbox.
To clarify any misunderstandings about the "~" character I use in my example, this is just a character I personally use to easily see that it is an alias.
The moving part
First of all, end the apache process that might be running in the background. Test this by going to your localhost, if you can't access your localhost, you are good to go.
Now, go to your xampp folder and find the htdocs folder. This is the folder containing all the files visible from the http://localhost/ address. Now move all the files and folders you want to move from the htdocs folder to the desired location.
That being done, you are now going to make the alias pointing to the location you chose. Go to xampp\apache\conf\extra\ . Here you will see a lot of .conf files, open the httpd-xampp.conf file. Now go to the <IfModule alias_module> part. In this module you now add your alias like this:
Alias /~dropbox "D:/Bart/Dropbox/Websites/Websites/"
<Directory "D:/Bart/Dropbox/Websites/Websites/">
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>All you now have to do is change the alias name, in my example /~dropbox and change the folder location, in my example "D:/Bart/Dropbox/Websites/Websites/" . Don't forget to do the latter twice!
Save and close the file and start your apache process again. Normally you are now able to view the files and folders in the new location by going to http://localhost/yourAlias.
Useful references
- Click here for more information about aliasses.
- More information about the <Directory> tag I used can be found here.