If you are using WordPress as the publishing platform for your essential online content then you know that there are always changes that need to be made, updates to apply, and general maintenance that needs to be performed. And you understand the stress involved if you make a mistake and cause your blog or website to go down. Mistakes happen, code updates do have bugs in them. So what can you do to protect yourself? In this, the first in a series of articles, I am going to walk you through some simple steps to safeguard your WordPress powered blog or website.
The most basic step to safely managing a WordPress site is to set up a development environment. There are a number of ways we can do this – Install WordPress locally on your PC or laptop; Install WordPress on a virtual machine; and Install WordPress on a separate domain or subdomain. Today I am going to discuss setting up a local development environment on your PC of laptop and run through the steps you need to follow to successfully accomplish this.
So why do we need a WordPress development environment and what do we use it for?
The answer is because of change! Change is constant with WordPress as it is in IT generally. Whether it is patching software to guard against a vulnerability, upgrading to a new release of software to take advantage of new features, adding or removing content, or adding, removing or upgrading plugins or themes. Every time you make a change to your production WordPress site there are risks involved. You may not know what those risks are until it’s too late. So why not test what you are doing on a development copy of your site instead of blindly applying that update and crashing your site. No change should ever be made to a live site until it has been tested in a development environment. This should be a hard and fast rule that you follow from now on.
Creating a local development environment using WAMP or MAMP
The chances are that you are reading this on your laptop or PC and that it is running Windows or Apple OS. If so then I have some good news for you. WAMP and MAMP are available to you free of charge to install on your Windows or Apple system to run WordPress on.
WAMP is a Windows application that includes the collection of packages known as Linux, Apache, MySQL and PHP which are the vital base components needed to run WordPress. You can download WAMP at wampserver.com/en/download.php, it is free to use under the GPL license.
MAMP is the Apple equivalent. It creates the same Linux, Apache, MySQL and PHP components on an Apple system. You can download MAMP at mamp.info/en/downloads/index.html, it is also free to use under the GPL license.
The instructions to install WAMP or MAMP are very simple and are described below:
WAMP installation instructions
- Download the latest version of WAMP
- Run the installer file
- Accept the license agreement
- Select the destination where you would like to install WAMP or accept the default
- Select the start menu folder where you would like to place WAMP’s shortcuts or accept the default
- Select whether you want WAMP to auto start, for most users you should leave the checkbox unchecked
- Click Install
- Midway through the install you will be asked the location to save your websites (DocumentRoot). You can opt to save these under your My Documents or accept the default
- You will then be asked to select your default browser. You can either click Open or find the executable file for your preferred browser
- When the installation has completed click Finish
- To manually start the WAMP server, click Start>Programs>WampServer>start WampServer
- Open your preferred browser and type in the address bar http://localhost. It should display the WAMP homepage signifying a successful installation.
MAMP installation instructions
- Download the latest version of MAMP
- Open the image and drag the MAMP folder into your Applications folder. You can do the same with the MAMP Pro folder as well
- Open the MAMP application and click the Start Servers button
- You can check Preferences in MAMP to make sure the Ports are set to 8888 for Apache and 8889 for MySQL. Alternatively you can click the Set to default Apache and MySQL ports button to set them to port 80 for Apache and port 3306 for MySQL
- You can also check that the version under PHP is set to PHP 5 and that your Document Root under Apache is set to /users/your username/Sites
- Click the Open start page button. A browser window should appear with the Welcome to MAMP message
Now that you have installed WAMP or MAMP we can go ahead and start to set up WordPress. The first step in the WordPress installation process is to create a database for WordPress to use. To do this, follow the instructions below:
Setting up a database for WordPress
- Click on the phpMyAdmin tab in WAMP or MAMP
- Under Actions you will see a Create new database box. Enter a name for your database, making sure that it is descriptive and unique. Do not use spaces and try not to use special characters. Keep it simple, for example: developmentDB01
- Leave the dropdown boxes with their default settings and click Create
- Next click on the Privileges tab and click Add a new User
- Enter a username. Again keep it simple
- From the Host dropdown select Local
- Enter a password or click the Generate button
- Make sure you keep a note of your database name, username, and password. You will need these later
- Select the radial next to Grant all privileges on database and then click Check All
- At the bottom of the screen click the Go button
Now that the database is set up the next step is to download WordPress and install it. To do this, follow the instructions below:
Installing WordPress locally
- Download WordPress from wordpress.org/download/
- Copy the WordPress folder to your Document Root. This is the location you specified when installing WAMP or MAMP
- Double click on the WordPress folder and find the wp-config-sample.php file
- Rename this file so that it is called “wp-config.php”
- Edit this file using Notepad or a simple text editor
- Scroll down until you find the following text – define(‘DB_NAME’, ‘putyourdbnamehere’);
- Replace the text “putyourdbnamehere” with the database name you chose in Step 2 above
- Scroll down until you find the following text – define(‘DB_USER’, ‘usernamehere’);
- Replace the text “usernamehere” with the username you chose in Step 5 above
- Scroll down until you find the following text – define(‘DB_PASSWORD’, ‘yourpasswordhere’);
- Replace the text “yourpasswordhere” with the password you chose in Step 7 above
- Scroll down until you find the following text –
define(‘AUTH_KEY’, ‘put your unique phrase here’);define(‘SECURE_AUTH_KEY’, ‘put your unique phrase here’);define(‘LOGGED_IN_KEY’, ‘put your unique phrase here’);define(‘NONCE_KEY’, ‘put your unique phrase here’);
- Replace the text “put your unique phrase here” in each line with a random set of characters. These keys can be any variation of random characters. I tend to bang on the keyboard to generate these keys. These should be complex to provide optimal security
- Scroll down until you find the following text – $table_prefix = ‘wp_’;
- Replace the text “wp” with a unique name for your database. Keep it simple, do not use special characters
- Exit your text editor and save this file
- In a browser, go to http://localhost/ or http://localhost:8888/ if you kept the default port in MAMP
- You should be redirected to http://localhost/wp-admin/install.php and see a Welcome screen
- Enter a Blog Title and Your E-mail
- Uncheck the box that says Allow my blog to appear in search engines like Google and Technorati
- Click the Install WordPress button
- Copy the admin password or make a note of it and click the Log In button
- Log in using the admin password you copied in Step 22 above
Congratulations! You now have WordPress installed on your local PC or laptop.