Call us 7am - Midnight 0207 855 2055My.tsoHostshopping_basket0 Item(s): £0.00
menuMenu

keyboard_backspaceBack to the Blog

Complete guide: how to install WordPress locally

Complete guide: how to install WordPress locally

Posted 23rd June, 2020 by Sarah

Since its launch in 2003, WordPress has matured into one of the world’s most popular content management systems. About a third of all websites today run on WordPress.

Though it is very user-friendly, it still throws up roadblocks in the form of an error from time to time. Therefore, it can be a good idea to set up and install WordPress locally for testing purposes rather than directly changing the content on the server.

In this tutorial, we’ll look at the various requirements that you need to install WordPress locally, the step-by-step process of installing WordPress after downloading its source code, and packaged WordPress solutions for one-click installs.

Why install WordPress locally?

If you install WordPress locally, it provides you with a good testing environment without affecting your online content. A local version of WordPress lets you make changes to your site without the fear of downtime if an error creeps up.

When WordPress developers create or modify plugins and themes for WordPress, they need a local version of WordPress to test changes. When they are satisfied with the results, they can package these plugins and themes to be used by others. A local version of WordPress helps developers test changes quickly.

Working on a local WordPress site is also quicker, simply because changes are visible instantly: there is no need for you to wait for a network connection to refresh, or a cache to clear to view the changes.

What’s more, a local WordPress installation gives you complete security when experimenting with your site as any vulnerabilities introduced stay local to your system for you to systematically check before making the final changes.

Testing WordPress locally is different from a staging environment. A staging site is hosted on a server. You need a staging environment for sharing changes with others. For instance, if you would like to solicit feedback from your peer group or a client, you can set up a staging environment. In this post, we only talk about working with WordPress locally.

Prerequisites for installing WordPress locally

Before you install WordPress locally, you should first install its requirements. Primarily, you need to satisfy three core dependencies before you can install WordPress locally: a web server, PHP and a database.

Depending on your operating system, you need to follow different steps to install these dependencies. We will cover three operating systems for installing WordPress locally in this tutorial: Windows, Mac and Linux.

Install a web server

First, you need to install a web server on your local development machine, that would execute WordPress's PHP code, interact with the database, and serve HTML pages through a browser. Apache and Nginx are the two most popular web servers for webmasters with WordPress sites. WordPress does not recommend any specific version of these web servers, as long as they are compatible with the PHP and database versions that you would need.

Apache does not provide a binary version of its server for installing locally on Windows. You must, therefore, download and compile the source code to install it on a Windows machine. Nginx provides an installer for Windows. You may also wish to compile the Nginx source code to use a development version of the server.

In a Mac, the easiest way to install a web server is through Homebrew, a popular package manager. The following commands should be run from the terminal to install Apache and Nginx, respectively.

bash

brew install httpd

brew install nginx

The best way to install a web server on a Linux environment is through a package installer too. However, package managers are not uniform across the various distributions of Linux. If you use a Debian based Linux distribution like Ubuntu, you can run the following commands to install Apache and Nginx using the package installer, apt.

bash

apt install httpd

apt install nginx

Before running a package installer, update it to ensure that you are getting the latest stable versions of the packages.

Install PHP locally

Since WordPress is a content management system based on PHP, you need to install a compatible version of PHP before you install WordPress locally. PHP is a general-purpose scripting language designed for web development. The version of PHP that you should install is listed on the download page of WordPress. WordPress version 5.3 recommends that you run PHP version 7.3 or higher for best results.

To install PHP on Windows, download the package installer from the PHP website, extract it and configure PHP to work with the web server. Here is a guide to installing PHP as an Apache module in Windows. This guide walks you through the process of configuring PHP for Nginx on Windows..

To install a specific PHP version on Mac, use Homebrew and specify the version to install.

bash

brew install php@7.3

In Ubuntu, use the following to install PHP version 7.3.

bash

apt install php7.3

Install a database

Next, you need to install a database for the management of your website's data. WordPress supports two databases - MySQL and MariaDB. For WordPress version 5.3, you need to have MySQL version 5.6 or MariaDB version 10.0 or higher.

To install specific versions of MySQL or MariaDB, head to the respective download pages and select the specific installer.

To install MySQL version 5.6 or MariaDB 10.1 on a Mac, use the Homebrew command as shown below. Installing MySQL or MariaDB through the terminal asks for root user credentials during installation.

bash

brew install mysql@5.6

brew install mariadb@10.1

Similarly, you can use the apt package manager to install a database on Ubuntu.

bash

apt install mysql-server-5.6 mysql-client-5.6

apt install mariadb-server-10.1 mariadb-client-10.1

Installing a PHP-Apache-MySQL stack locally

We have outlined a detailed process of installing web servers, PHP, and databases in this section so far.

However, it may be difficult for everyone, especially non-developers, to install each component and configure them to run coherently. You can solve this by using a Stack, which installs a web server (typically Apache), PHP and a database.

In Windows, you can use the WampServer (Windows-Apache-MySQL-PHP, also known as Wamp) package to set your machine for a WordPress install. You have two installers, one each for 32-bit and 64-bit versions of Windows. The installation is fully automated, and comes with PhpMyAdmin too, a GUI based client for MySQL and MariaDB.

Corresponding stacks for Mac and Linux are MAMP and LAMP. MAMP has a downloader for a Mac, which provides an installation wizard. LAMP is a software stack for Linux, which comes with an installer.

If you are looking for a platform agnostic stack, you can opt for XAMPP. XAMPP is a software distribution that contains Apache with MySQL or MariaDB, PHP, and Perl. XAMPP can be installed on Windows, Mac and Linux operating systems.

You can setup XAMPP locally through its installation wizard. You can specify whether you would like to install Perl before the installation begins.

Xampp Installation Mac

Pictured: Installing XAMPP on a Mac

Once the installation is complete, you can start the control panel of XAMPP to manage all services. In the "Manage Services" tab, ensure that Apache and the database servers are running before proceeding further.

Xampp Manage Services

Pictured: XAMPP Dashboard on a Mac

Once they are in green, visit localhost on your browser to visit the home page of your local server. Before proceeding to install WordPress locally, you’ll need to set up the database. Click on the PhpMyAdmin tab to start the application. In PhpMyAdmin, select the "User Accounts" tab and click on "Add User Account" link. In this step, we’ll aim to create a username and database for the WordPress installation.

Fill in the user name and password for the new user to be created, and select the option to create a database with the same name and grant all privileges.

Phpmyadmin Create User

Pictured: Creating a new user for WordPress on PhpMyAdmin

Once you have filled in the details, click on the Go button to create the user and database. Once the user has been successfully created, notice that the new database name pops up on the left column.

Phpmyadmin Success

Pictured: PhpMyAdmin after creating a new user and database

Install WordPress locally on a development machine

To install WordPress locally, you need to first download WordPress source files from the WordPress website. The source code is downloaded as a ZIP file. You need to unzip the contents in the root directory of your web server.

In XAMPP, go to the installation directory. The directory named "htdocs" is the root directory of Apache. Create a directory named WordPress and unzip the source code of WordPress into this directory. Open your browser and visit http://localhost/wordpress to start the installation. If you did everything right until this point, you should see the following WordPress installation screen on the browser. Click on the "Let's Go" button to begin installation.

Wordpress Installation Screen

Pictured: WordPress Installation Screen

Until now, you know that your local machine is running a WordPress compatible version of PHP. In the next step, you need to enable WordPress to connect to your database in order to create the required tables. The following details are needed in the next step:

Database name: this is the name of the database where WordPress would create tables. Since we created a database with the same name as that of the user in the last step, enter "wp_user" in this field.

Username: this is the MySQL username for WordPress to connect to the database. Enter "wp_user" in this field too.

Password: enter the password of the MySQL username that you filled earlier in XAMPP.

Database host: enter "localhost" as the database is running locally.

Table prefix: you can set a prefix for all WordPress related tables in this field. You should change it if you plan to run multiple WordPress instances on the same database.

If you have done everything right, WordPress will be able to connect to the MySQL database, and create the wp-config.php file. In the last step of the installation, you will be asked to fill in the basic details of your site and create an admin user to access the WordPress site. This user is different from the MySQL user that you created above.

Once the installation is successful, you can login to your WordPress admin site by visiting the URL: localhost/wordpress/wp-login.php.

Enter the chosen admin username and password to login. Meanwhile, you can visit the WordPress site by visiting the URL: localhost/wordpress/.

Migrate a local site to the server

Now that you have successfully created your local site, you may wonder how to move the changes to the server once you have finalized them.

In this section, we broadly list down the steps involved in the process.

Explore WordPress database: A bulk of your website's information is stored in the database. To migrate from your local machine to the server, the first step is, therefore, to take a dump of your WordPress database. You can go to the Explore tab on PhpMyAdmin to export the current version of the database. Here is our guide to creating a backup of your WordPress database.

The next step is to upload the WordPress files to your server. You can zip the current wordpress directory within htdocs, upload it to the server and unzip it.

Import the database dump that you have created on the server. This process is fairly easy if you are using PhpMyAdmin on the server too. Go to the Import tab in PhpMyAdmin to upload the database dump. Finally, you need to change the Site URL in your wp_options table. Open the table in PhpMyAdmin and edit the siteurl option. If you fail to perform this step, all your links will point to the localhost/wordpress/ addresses.

Optional: Edit the wp-config.php file to connect to the database on the server if you are setting the site up for the first time.

Here is our guide to internal migrations.

Now you know how to install WordPress locally.

With this, we come to the end of the tutorial to install WordPress locally. You first understood WordPress's primary requirements - a web server, PHP, and a database. You explored various ways of installing these prerequisites locally, before proceeding to install WordPress locally. Finally, you looked at the process of migrating from a local site to the server.

Categories: WordPress

You may also like:

5 inspiring homepage designs and why they work
Video tutorial - how to install WordPress plugins
Sucuri setup video tutorial - WordPress website security plugin
Your guide to the WordPress template hierarchy: what you need to know
11 of the top plugins to optimise your WordPress eCommerce site
6 of the top WordPress eCommerce plugins to set up an online store