Question: **Info:** I would like to set up a VM server on my local computer which will serve pages in the exact same way as my current hosting (but only to me on my local computer). I currently pay a big web hosting company to host my website & web store and they are doing a great job, but I would like to be able to work on my Web site and its corresponding MySQL DB, HTML, and PHP code without being at risk of messing something completely up on the live servers.

My current plan of action:

1. Set up a VM webserver with Debian, MySQL, PHP, Apache.
2. Copy web store (PHP/HTML) code to VM server.
3. Copy my current MySQL databases from my hosting provider and install
on VM server.
4. Modify and test new features on VM server.
5. Upload MySQL DB and HTML/PHP code back to web host's server where it
should work as before but with new modifications.

**Questions:** Now I'm pretty sure I have steps one and two down correctly but I can't for the life of me figure out how to proceed next, so here are my questions.

I have my /etc/host file set up so www.MySite.test redirects to the IP address of the local VM webserver. Once I import my PHP/HTML files and MySQL file whats the best way to navigate around the fact that all of my files and DBs will reference www.MySite.com.

I can export my MySQL dbs but do I also have to export my MySQL users and passwords to access those db or are those coded into my html/php code?

Answer: 
MySql
-----

* Use `mysqldump` to get the data out of your live database
* Transfer the dump file to your VM
* Use `mysql` command to import the data

Here is a website that can walk you through the process: <http://www.mydigitallife.info/how-to-backup-and-restore-export-and-import-mysql-databases-tutorial/>

If your PHP code has the db user and password hard coded, then you will have to use the same user name and password in both places. If they are configuration options, then you can use different ones and set the configuration differently. 

Different host names
--------------------

To deal with the fact that they are running on different host names you can do one of the following:

* Use only relative linking within the site. So instead of linking to `http://mysite.example.com/foo/bar.html` link to `/foo/bar.html`
* Create a configuration file that has the base of the site in it and use that value every time you need the base url of the site.

Use source control
------------------

I highly recommend putting your code under source control using [git](http://git-scm.com/). Git is a free open source source control management tool. Using git you can see your edit history, and roll back to any previous version. It also makes the transfer of code back to your live site easy because you can check it in on your local VM and then check it out on your live server using your VM as a master. Subsequent transfers of code are then just `git pull`.
not really: if you know where your code stores db access details you can create a single user on you VM mysql instance and usa those credentials to access all dbs, and configure with such details all your code