Setup WordPress for Local Development in One Second

New developers make changes to their live site without considering any potential drawbacks. After all, it is a small change and can be done without any significant impacts. However, in many instances, it can interfere with the user’s experience or take down the website due to critical errors during changes.

To overcome this, you need to have your development environment locally. This will save you a lot of headaches later on as your site grows. This article will take a closer look at the local WordPress environment.

WordPress Development Environment

A local WordPress development environment is where you host your site with everything saved and accessible from your local hard drive. It provides a separate and secure environment where you can test out plugins and themes, update them to test compatibility, and check their performance. Moreover, you don’t need an internet connection to access your local development environment, meaning you can access it anytime.

So, if you want to test something new, you load it up in your local environment. If something gets broken, you can debug and fix it before making changes to the live site.

The three key parts of a local WordPress development environment include:

  • Apache or Nginx web server
  • PHP programming language
  • MySQL database management system

WordPress.com vs WordPress.org

Before we move forward, let’s quickly compare WordPress.org and WordPress.com.

What is WordPress.com

WordPress.com is an online service platform that you can use to host a WordPress website using managed hosting. It offers limited flexibility. Here, you can select from pre-installed themes or use custom themes or plugins(plan dependent). The service is provided by Automattic, which WordPress co-founder Matt Mullenweg manages.

Here, you get a complete WordPress environment with managed hosting plans starting at $48 per year. They do offer free plans, but it is very limited.

Before we move forward, let’s quickly compare WordPress.org and WordPress.com.

Advantages

  • You don’t have to worry about installing, updating, or creating backups of your site. WordPress.com does it for you.
  • The free version offers up to 3 GB of space which is more than enough to get started and learn about the service.

Disadvantages

  • WordPress.com run ads on your site if you use their free plan.
  • With them, you cannot sell ads, hindering monetization.
  • Uploading custom plugins is a mess. Here, you need access to a VIP program that starts at $5000 per month. For already-available plugins, you need to access the Business plan($300 per month).
  • Analytics is limited, and you cannot expand on their existing analytics feature.
  • WordPress.com can delete or cease your site anytime they want.
  • They do not offer eCommerce support.
  • Your site URL has a WordPress.com link and can only be removed if you use a Business plan or above.

What is WordPress.org

WordPress.org is a community and resource hub for WordPress. It offers complete access to open-source WordPress software. This means you can download a free copy and use it per your needs. It is 100% free as it is open-source.

Advantages

  • Access to 100% free-to-use open-source WordPress software.
  • You have complete access to all your data.
  • You’re free to customize your site as per your liking.
  • You can use custom plugins/themes without any limitations.
  • You can run ads on your site to generate revenue.
  • You can run analytics to measure the site’s performance.
  • You can sell products, services, and processes with your WordPress site.

Disadvantages

  • Even though WordPress is free and open-source, you still need hosting.
  • You need to install and manage WordPress yourself.
  • Updating plugins and themes need to be done manually.
  • Backups are to create and managed by yourself.

How to install WordPress locally

Convinced that a local WordPress environment is helpful? If so, let’s learn the steps you need to install WordPress locally. Here, we’re going to use the LAMP stack. You can also look at XAMPP and MAMP, which lets you create and manage WordPress local development for non-Linux operating systems.

Download WordPress Software

The first thing to do is to download WordPress software.

Go to WordPress.org, and then click on “Get WordPress” in the top-right corner of the site or on the homepage.

WordPress homepage

It’ll redirect you to the Download page, where you can see the latest WordPress version for download. At the time of writing the article, the latest WordPress version is 6.0.2. So, the download button will read “Download WordPress 6.0.2.”

It’ll start downloading WordPress software with the name “latest.zip.”

Note: You can also download it via commands using command line solutions. Check Step 5 in Setting up LAMP environment for more details.

Setting up LAMP environment

LAMP software bundle stands for Linux, Apache, MySQL, and PHP. It is also known as a software stack that defines application components. Using it, you can set up your local server environment to install and operate WordPress.

As it is Linux based, you need access to Linux operating system. If you’re not using one, you can check out Windows alternatives such as XAMPP – a cross-platform software stack that supports Apache, PHP, Perl, and MariaDB.

Note: To execute all the commands, you need root access to the system.

Step 1: Update and Upgrade System

The first step is to update and upgrade the system for any missing packages. To do it, simply run the following command.

$ sudo apt-get update && apt upgrade

If you get a similar error as the above image, “Could not open lock file,” you must run commands in the following sequence.

$ sudo apt-get update

$ sudo apt-get upgrade

Step 2: Install Apache Web Server

To transform your Linux OS to a server, you need to install Apache. 

$ sudo apt-get install apache2 apache2-utils

Installing Apache on Web Server

Once installed, enable the Apache2 web server to start every time the system boots.

Start or Enable Apache

You’ll see the Apache HTTP server running if everything is installed correctly. You also need to allow HTTP traffic to go through the UFW firewall.

$ sudo ufw allow in “Apache”

$ sudo ufw status

Allow HTTP traffic to go through the UFW firewall

Now type “localhost” in your web browser, and it’ll open the Apache2 default page.

Default Welcome Page Apache2

Step 3: Installing MySQL Database Server

Our next step is to install MySQL by using the following command.

$ sudo apt-get install mysql-client mysql-server

Installing Mysql Server

If you want to work with MariaDB instead of MySQL, you can install it with the following command.

$ sudo apt-get install mariadb-server mariadb-client

To set up MySQL, you need to run the following command.

$sudo mysql_secure_installation

It’ll ask you to validate the password. Press “Y” and then Enter to start validating and then select a strong password.

Mysql Secure Installation

If you get the error, “Failed! Error: SET PASSWORD has no significance for user ‘root’@’localhost'”, then you need to run the following set of commands before re-running sudo mysql_secure_installation command.

$ sudo mysql

$ ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password by ‘my-password’

$ exit

Next, type Y and Enter for all the questions asked during the installation.

Removing Test Database and Privileges

Step 4: Installing PHP

To make WordPress work, we also need to install PHP. Use the following command to do so:

$ sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip 

Installing PHP on Server

Once PHP is installed, you need to restart the Apache server. Do it by running the following command.

$ sudo systemctl restart apache2

To make PHP work with the webserver, we need to create a file inside /var/www/html named “info.php”

$ sudo vi /var/www/html/info.php

And, then add the following code to it.

<?php 

phpinfo();

?>

Next, open the following link in the web browser to see if it works as intended. 

http://localhost/info.php

If everything worked correctly, you should see the following page.

Testing PHP

Step 5: Installing WordPress

Now, it is time to install WordPress. To do so, you need to download the latest WordPress package and extract it.

$ wget -c http://wordpress.org/latest.tar.gz

$ tar -xzvf latest.tar.gz

Installing WordPress on Server

Next move the WordPress files to the Apache default root directory.

$ sudo mv wordpress/* /var/www/html

You also need to set up proper file permission for your website directory.

$ sudo chown -R www-data:www-data /var/www/html/

$ sudo chmod -R 755 /var/www/html/

This will give the webserver access to the WordPress files.

Step 6: Create WordPress Database

Boot the MySQL shell by running the following command to create a WordPress database.

$ sudo mysql -u root -p

Next, type MySQL commands to set your database_name, database_user, and databaseuser_password. Make sure to use unique values for each of them, according to your preference.

mysql> CREATE DATABASE wp_myblog;

mysql> CREATE USER ‘username’@’%’ IDENTIFIED WITH mysql_native_password BY ‘password’;

mysql> GRANT ALL ON wp_myblog.* TO ‘username’@’%’;

mysql> FLUSH PRIVILEGES;

mysql> EXIT;

Creating New Database

As you can see, we used the proper username and password to create our WordPress database.

Now, you need to rename wp-config-sample.php to wp-config.php, located in /var/www/html/ directory.

$ cd /var/www/html/

$ sudo mv wp-config-sample.php wp-config.php

Lastly, remove the default Apache2 web server index file.

$ sudo rm -rf index.html

Step 7: Setting up MySQL

Now open up wp-config.php and update the DB_NAME, DB_USER, DB_PASSWORD and the DB_HOST(if needed).

$ sudo nano wp-config.php

Customizing WP Config File

Restart the web server so that the changes can take place.

$ sudo systemctl restart apache2.service 

$ sudo systemctl restart mysql.service

Step 8: Firing Up the WordPress site and Configuring it

To open your local WordPress installation, type http://localhost in your web browser. It should open the WordPress installation wizard.

Select the WordPress language.

Installing WordPress

Next, enter all the site details and click on “Install”  to start WordPress installation.

WordPress Installation Information

Once done, it’ll redirect you to a Success message where you can click on Login to access the  WordPress dashboard.

Access WordPress Dashboard After Login

Tools for Local Development

With WordPress successfully installed, you’re now free to experiment. However, you need a few more tools to manage local development efficiently. As for editing code, you need a proper text editor. You can choose from Sublime Text, Visual Studio Code, or Atom. You can use WordPress Plugin Boilerplate for custom development to kick-start your plugin development.

What is the alternative to running local servers?

Creating a local WordPress environment is beneficial. However, manually creating one can take a lot of time. This becomes more challenging if you need multiple local WordPress instances to run your tests.

That’s why you need a tool to help you instantly launch WordPress sites.

Meet InstaWP, an excellent tool that lets you create WordPress dev env “online” in less than a second without creating an account.

All you need to do is choose the WP & PHP version, choose a configuration between default, multisite, or eCommerce and finally give your custom site a name. If you create an Instant WP site without any account, it’ll stay live for 8 hours. For the free account, it is extended to 48 hours.

The key InstaWP features that make it a great choice over manually setting up a local WordPress development environment include:

  • Instantly create sites
  • No server management required
  • Free SSL certificates
  • Choose WP and PHP version
  • Automatic domain
  • Access to in-built tools such as automatic login, database editor, view logs, and code editor

So, what’re you waiting for? Create your WordPress dev environment online in just one second by clicking here.

Leave a Reply

Your email address will not be published.

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google
Spotify
Consent to display content from Spotify
Sound Cloud
Consent to display content from Sound
whc6PbkK