You want to make a local copy of a website so you can work on it without breaking the live site, but there is so much to do just to get it working. You have to download all the files, set up the database, change configuration files to use your local mysql login details and then the bit that can be hair-pulling frustrating: making sure all the assets (css, js, images etc.) are being pointed to correctly. What you often end up with is a bare looking site missing all its styles and images. This makes developing a pain.

The problem arises in the difference between our live server’s and our local server’s directory structure. Chances are you have placed all the files in a sub-directory within your Apache document root. Yet on your live server the files are probably all placed in the document root. This makes setting paths easier, you can often simply use “../” to point to the root directory. On your local copy, this means it’s looking above the project folder in the directory tree.

Now the normal fix, and the one I’ve used personally for a long time, has been to go through the website files and modify everything to work. And of course modify it all back again when I put it live. There’s just so many chances to make mistakes and break something.

A better solution is to open your httpd.conf file and modify your document root. I use XAMPP, and all I have to do is open up {xampp install dir}/apache/conf/httpd.conf and modify a couple of lines. In my httpd.conf the line numbers are the ones listed below, but they may be different for you. Just look for the “DocumentRoot” and “<Directory ” parts.

Line 183:

DocumentRoot "E:/xampp/htdocs"
DocumentRoot "E:/xampp/htdocs/subdirectory"

Line 210:

<Directory "E:/xampp/htdocs">
<Directory "E:/xampp/htdocs/subdirectory">

When you’re done, simply restart Apache and point your browser to http://localhost/ to be redirected to what was previously http://localhost/subdirectory. Simply edit your httpd.conf again to reverse the change.

Hope you find this useful and if you have a different method please leave a comment.