Setting Up a Local WordPress Development Environment
- Setting up the website and adding content.
- Installing plugins to test their functionality.
- Viewing a functional website without a shared environment.
- Theme or plugin development. This guide will walk you through the following steps.
- Installing a LAMP Development Environment
- Creating a database
- Downloading WordPress core files, and setting them up on server.
- Creating a local domain for use.
Installing A LAMP Development Environment
XAMPP is a cross-platform LAMP (Linux, Apache, MySQL, PHP) environment used for running WordPress on your local machine. A few platform-specific alternatives to use as well are WampServer for Windows, and MampServer for OS X. All of these options will provide the same functionality for running a local WordPress environment, but I chose XAMPP for the following reasons:
- Cross-platform compatibility, the setup and configuration for this tool will stay the same between different platforms.
- Personal preference for the XAMPP Control Panel over the other tools_._
- The use of MariaDB over MySQL**.
**Note that XAMPP actually uses MariaDB as it’s database server. This is different than the standard MySQL database server used for WordPress. I’ve provided a reference to a few articles at the end of this post if you’re interested in learning more.
Starting with XAMPP
When opening XAMPP, you’ll be presented with the Control Panel:
To get the environment started, start both the Apache and MySQL services. Check that the server is running correctly by accessing http://localhost on your machine. If the XAMPP dashboard appears, you’re good to move to the next step.
Creating a Database
The next step is creating or importing a database in your local MySQL server. This can be done using phpMyAdmin (set up with your XAMPP installation) or by using MySQL Workbench to connect. I’ll use MySQL Workbench, since it gives a more friendly UI to work with.
Right-click ‘Schemas’ on the left side to create a database for WordPress to use. Later, you’ll use this schema name when running the WordPress installer.
Linking/Installing WordPress
After the server is running and the database created, the next step is to get the WordPress source code onto the server. Download the files for WordPress and copy them to a directory on your computer, something like:
You’ll likely want to store the source code for the site somewhere other than the /htdocs folder. This way, you can have a central repository on your machine for all projects. You can use a symlink to accomplish this. Open a command line terminal as an admin and run the following:
After this, check that you can access the WordPress installation at **http://localhost/. **Assuming you can see the WordPress installation screen, you have everything ready to get started. You can progress from here if you so desire, but let’s also create a local domain for use as well, to make access to the site a little easier.
Creating a Local Domain
Creating a local domain will allow you to access your local running website at something such as http://local..com. There are two parts:
- Editing the Apache server configuration to serve the local domain.
- Editing the hosts file to point the new domain from your machine to your server.
First, open the Apache Virtual Hosts configuration file at C:\xampp\apache\conf\extra\httpd-vhosts.conf and add the following:
Next, open the C:\Windows\System32\drivers\etc\hosts as an administrator and add the following:
Restart Apache using XAMPP Control Panel. Attempt to access the site using the local domain. If you’re able to access the WordPress installer screen at the local domain, you’ll all set to start the 5-minute installation.
Complete the 5-minute WordPress Installation
Installing WordPress is very simple. Select the language for installation, and then fill out the database connection details like below. You’ll just need to change the database name to the schema created:
You should now be all set with a local WordPress environment, useful for plugin development, trying out different themes, and other configuration changes without affecting a live website.
References
MySQL Face-off: MySQL or MariaDB?]]>