How to Test a WordPress Site Locally Without Access to Your Client’s Web Server

By | December 9, 2016

Sometimes you do not have access to your client’s web server. All you can get is a copy of their WordPress files and database. In this situation, you can still troubleshoot and make modifications to their site by copying everything to a local server and working on it from there.

All you need to do is setup a local LAMP server in VirtualBox, copy the client’s files, and import the database to start testing or making changes to the website. This post will cover the steps involved in the process, along with some troubleshooting you can do if the installation doesn’t go smoothly.

You will need:

  • LAMP server image
  • VirtualBox installation

Copy the Client’s WordPress Files and Database

  1. Retrieve a copy of the client’s WordPress files and database directly from the client via email, ftp, etc. If you have access to the client’s server then you can use rsync to copy the files
      rsync -avz username@clientA.com:/home/username/public_html/sitename/* .
  2. Create a directory on the host machine for the client’s website files (for example: /home/username/www/clientA.com
  3. Extract the contents of zipped file from step one into the new directory
  4. Create a backup copy of wp-config.php to retain the client’s database configuration.

Create a Virtual Web Server to Host The Client’s Website

  1. Create a new Virtual Machine in VirtualBox
  2. Install SSH and LAMP during installation process
  3. Change the Virtual Machine’s network mode from NAT to bridged
  4. Configure /etc/network/interfaces so that the server has a static IP address
  5. Install VirtualBox guest additions 
  6. Setup a Shared Folder in VirtualBox that maps the host’s www directory (containing the client’s websites files) to the virtual server’s www directory that Apache is configured to use. See this post for details on setting up shared folders in VirtualBox.
  7. Create a MySQL database on the virtual server and grant privileges to it to the local user
    • CREATE DATABASE clientA;
      GRANT ALL PRIVILEGES ON clientA.* to "username"@"localhost" identified by "password";
      
  8. Import the client’s WordPress database
    • mysql -u root -p clientA < database.sql
  9. Configure the hosts file on the host machine to point the client’s domain to the virtual machine’s IP address.
    1. sudo gedit /etc/hosts
    2. Add [ip address] clientA.com
  10. If necessary, reset the WordPress admin password
    • SELECT id, user_login, user_pass FROM arufl_users;
      UPDATE arufl_users SET user_pass="[md5 hash]" where id = [user id];

      Generate a hash from a new password using this hash generator

You should now be able to access the client’s website from a browser on the host machine. If not, see the troubleshooting section below.

Remember to replace wp-config.php with wp-configBAK.php before sending the files back to the client

Troubleshooting

  • If you receive 404 errors that pages cannot be found, ensure the apache rewrite module is enabled
    • sudo a2enmod rewrite
  • If the 404s continue, ensure AllowOverride All is set in the Apache config file (/etc/apache2/sites-available) for the corresponding site
    • <Directory /var/www/>
      	Options Indexes FollowSymLinks
      	AllowOverride All
      	Require all granted
      </Directory>
  • Some PHP code not working? If any of the PHP code is between short tags ( <? ?> ) then make sure the short_open_tag is set to “On” in the PHP configuration file. Note that it’s recommended to use full tags ( <?php ?> )
  • Are you seeing this in the Apache error log?

    PHP Fatal error:  Call to undefined function imagetypes() in /var/www/html/wp-content/plugins/contact-form-7/modules/really-simple-captcha.php on line 402

    Try installing GD support for PHP and then restart Apache:

    sudo apt-get install php5-gd
    sudo service apache2 restart

Leave a Reply

Your email address will not be published. Required fields are marked *

*