Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
    
I have edited your post because formatting improves readability and helps users to understand your question. Without formatting, users have difficulties to read this big bloc of text. –  Zistoloen May 29 '13 at 10:42

4 Answers 4

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. 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.

share|improve this answer
    
Is there a reason you suggest git as opposed to SVN? I've actually tried get before and it was damn difficult to use. –  TdotThomas Jun 1 '13 at 16:57
    
Git is my personal preference. I used to us svn. Git is slightly more complex but way more capable and doesnt require a server. –  Stephen Ostermiller Jun 1 '13 at 17:15
    
I've been able install wordpress on my development server and I was also able to dump and install my wordprss dbs and my wordpress files but because www.MySite.com is in the database at various places the links are all broken. Can I just do an SQL query to just replace "www.mysite.com" with "www.mysite.test" where ever it appears in the db? Also the when creating the file structure who should the folders belong to? wordpress can't create any of its configure files because it doesn't have write permission. –  TdotThomas Jun 3 '13 at 16:41
    
Its easiest to do that search and replace in the dump file than try to make it happen with database queries. I use the command line sed like this for it: sed -i 's/www.mysite.com/testsite.dev/gI' mysql.site.dump.sql –  Stephen Ostermiller Jun 6 '13 at 10:32
    
User for the files that wordpress needs to write need to such that it is writable by the user running the webserver (apache2 maybe). So either chown -R apache2:apache2 /var/www/ or give everybody write access: chmod -R a+rw /var/www/ and find /var/www -type d -exec chmod a+x {} \; –  Stephen Ostermiller Jun 6 '13 at 10:35

Although it looks like Stephen answered your question I figured I would respond to the title of the question, "Setting up a LAMP VM server for Development and Testing?"

  1. Get Virtual Box, it's free and easy to use.
  2. Get the ISO for Ubuntu, Debian or the operating system that best mimics your production environment. You might have to spend money. Microsoft offers an evaluation version of Windows Server. I don't have experience with these but heard that the evaluation versions of Windows expire after some date.
  3. Get Xampp for your OS because it installs and configures PHP and MySQL for you. It also includes phpMyAdmin and an email server that have come in handy.
  4. Install Virtual Box.
  5. Run Virtual Box and then install the OS on it using the ISO you downloaded.
  6. Install Xampp on your mint virtual boxed OS. Write down those usernames and passwords, or make them easy to guess. This is a local development and testing environment after all.
  7. Use Virtual Box to create a backup of your virtual machine image. This will make starting over and setting up a new environment a breeze.
  8. Dance, you deserve it.

Also, I second the suggestion to use source control. It doesn't matter to me what you use, just use it. I'd also recommend that you backup your hard work, and your client's investment. Embracing source control will change how you work for the better.

share|improve this answer
    
If I'm the only one working on a project is source control worth the set up time? I understand if its a team of people but what are the advantages of source control if I'm the only programmer? Especially since Virtual Box has a pretty great snapshot feature. –  TdotThomas Jun 8 '13 at 6:25
    
Absolutely, @TdotThomas, there are advantages even when working alone and I think you'd be surprised just how quick and easy it is to use TortoiseHg. When moving from SVN to Hg or Git there is a learning curve, but in the long run it will save you time. Here's an SO answer I think is applicable from For home projects, can Mercurial or Git (or other DVCS) provide more advantages over Subversion?. –  Jeremy Cook Jun 8 '13 at 14:05
    
Oooh yes, set up source control as early on as you possibly can and learn how to use it well. I prefer git. This is the voice of experience speaking from doing manual version control. Having multiple branches you can check out for independent "what ifs", etc make it quite worthwhile. Plus you can revert in a heartbeat to something working and untouched for any item that comes up on the live site before you're ready to commit any of those other changes. When it comes together, push it live. –  Fiasco Labs Sep 12 '13 at 2:31

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

share|improve this answer
up vote 0 down vote accepted

The thing with projects like this is it never really works the way its suppose to I've imported my database and my HTML/PHP/JS code but something is never right. To those reading about doing this its more then just code and a database, its permissions, users, etc, etc. Below are somethings I've learned, some advice, and tools I've used.

  1. I'm using Virtual Box it has a great snapshot feature, great support for my Host OS of choice(Debian) and my Guest OS of choice(Debian), and its free.
  2. I'm only using free software/webware the online support is better and I'm broke.
  3. Take a ton of snapshots and backups.
  4. Keep everything with documented.
  5. If you get stuck ask for help.
  6. Setup host only networking so that you can get to www.YourSite.test
  7. Remove as much unneeded software as you can to increase performance and limit potential bugs.

This was a good idea but its a lot more work then just setting up some software. The info on this page is a good place to start but do your own research because there is a lot of stuff to learn even if you consider yourself a pro.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.