Tag Archive for WordPress

Running a WordPress site locally using WAMP

The WAMP server menu visible from the task bar

WAMP server

When working with any site it is important to have a development environment. With WordPress there can be conflicts with WordPress versions and plugins. It is also vital to be able to test code before making it live. I am documenting here how I run a local development environment and populate it with a live site.
These instructions work and have been tested on Windows 8 and 10.
First step is to install WAMP. You will need to allow it to pass through your firewall. When it is installed and you run it there will be an icon in the taskbar that will turn green if successful.

Note:  If the icon won’t turn green then there could e another process running on port 80. Skype will interfere so you may want to close it down. Alternatively you can set up WAMP to listen on a different port. To do this you will need to:

  1. Edit C:\wamp\bin\apache\apacheX.X.X\conf\httpd.conf
  2. Change the two Listen lines to use port 8080 instead of 80
  3. Change localhost:80 to localhost:8080
  4. Use :8080 after URLs

Now you need to get a copy of your WordPress site:

  1. Export and download your database
  2. On your live Wordress site, zip wp­admin, wp­content and wp­includes as well as any files beginning with wp­ in root and index.php
  3. Download the zip file from the above step and be sure to remove it from the server
  4. Create a folder in c:\wamp\www called yourwebsite
  5. Unzip the live WordPress files to the folder you just created
  6. Create a database using http://localhost/phpmyadmin/ the database name will be the same as the database listed in your wp-config.php file
  7. Import the database file exported from the live site in step 1
  8. Update C:\wamp\www\yourwebsite\wp_config.php, change user to “root” and empty password
  9. Edit C:\wamp\bin\apache\apacheX.X.X\conf\httpd.conf change DocumentRoot “c:/wamp/www/” to DocumentRoot “c:/wamp/www/yourwebsite/”
  10. In the apache modules (from clicking on WAMP in the taskbar and choosing apache > modules ensure rewrite_module is enabled
  11. Using http://localhost/phpmyadmin/ run the SQL script at the end of this list. This is important as all the links in the database will be pointing at your live server.
  12. See if the site works: http://localhost (ot http://localhost:8080 if you canged port numbers)
  13. In admin panel go to settings / permalinks and save. This will overcome page not found on child links

These steps should work to get a local development environment working. It will not send emails, so if that is required you may want to try using Test Mail Server Tool

SQL Script to fix links

You need to ensure you replace yourwebsite.com with your website name

UPDATE wp_options SET option_value = replace(option_value, ‘https://www.yourwebsite.com’, ‘http://localhost’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
UPDATE wp_posts SET post_content = replace(post_content, ‘https://www.yourwebsite.com’, ‘http://localhost’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’https://www.yourwebsite.com’,’http://localhost’);
update wp_posts set post_content = replace(post_content, ‘https://www.yourwebsite.com’, ‘http://localhost’) where instr(post_content, ‘https://www.yourwebsite.com’) > 0;
update wp_posts set post_content = replace(post_content, ‘http://www.yourwebsite.com/’, ‘http://localhost/’) where instr(post_content, ‘http://www.yourwebsite.com’) > 0;
update wp_links set link_url = replace(link_url, ‘http://www.yourwebsite.com/’, ‘http://localhost/’) where instr(link_url, ‘http://www.yourwebsite.com/’) > 0;
update wp_links set link_url = replace(link_url, ‘https://www.yourwebsite.com/’, ‘http://localhost/’) where instr(link_url, ‘https://www.yourwebsite.com/’) > 0;
update wp_links set link_url = replace(link_url, ‘https://yourwebsite.com/’, ‘http://localhost/’) where instr(link_url, ‘https://yourwebsite.com/’) > 0;

Alternatively you can use a text editor to do a find and replace on the SQL file before you import it. If using Notepad++ the following will work well, assuming your site is example.com.au:

Find (using Regulat expression): http?://(www\.)?example.com.au([^\s”]*)

Replace: http://localhost/example\2

And that’s it!

Good luck. The main issues I have come across are that:

WAMP won’t start – you will need to check what else is running on the same port

Internal links are broken – Make sure to go to settings > permalinks and press save, and that you updated the SQL script before running it.

Upgraded to WordPress 3.0

I have upgraded to WordPress 3.0. It’s very impressive the amount of work that so many people have put into this platform. It still amazes me how good this platform is and it keep getting better. Now I need to really check out WordPress.tv and get to playing around with creating some plug-ins.

There is a good overview of what’s new in WordPress 3.0 available on the WordPress blog.   It has been embedded below. The features I want to play with most are the custom posts and the multi-user blogs.