Setting up WordPress develop on local

Setting up WordPress development on your local machine is not as simple as downloading a zip file and uploading it to the server. You will need to set up an environment that is similar to what you would find on the production server in order for your code changes to be accepted by the core team.

There are many different ways that you can set up a development environment, but this tutorial will teach you how to set up WordPress locally using VVV and Local by Flywheel.

VVV

VVV (Varying Vagrants Vagrant) is an open-source local development environment focused on WordPress, powered by Vagrant. VVV is ideal for developing themes and plugins as well as for contributing to WordPress core.

Please follow the instructions and install VVV on your development machine.

The default configuration for VVV includes WordPress trunk, if it’s not you can use the following configurations in the config.yml file

sites:
  wordpress-trunk:
    description: "An svn based WP Core trunk dev setup, useful for contributor days, Trac tickets, patches"
    repo: https://github.com/Varying-Vagrant-Vagrants/custom-site-template-develop.git
    hosts:
      - trunk.wordpress.test

Once the configuration has been added run the command vagrant provision

Local by Flywheel

It was created to provide an easy way for developers to work on their projects offline, without the need to use any other tools or frameworks.

The main features of Local by Flywheel are:

– A free local development environment

– Provides an easy way for developers to work on their projects offline

– No need for any other tools or frameworks

You can follow the instructions for creating a WordPress trunk in Local

Step 1: Create a site on local

  • Let’s create wptrunk.local on the local

Step 2: Copy wp-config.php

  • Let’s copy wp-config.php for safekeeping as we are going to delete the public folder and clone the WordPress trunk
  • Open Terminal and go to wptrunk directory inside app
cd Local Sites/wptrunk/app

copy wp-config.php file to app directory

cp public/wp-config.php ./

Step 3: Remove the public directory and Clone the WordPress trunk from GitHub

  • Remove Public directory
rm -rf ./public
  • Clone WordPress trunk / WordPress develop
git clone https://github.com/WordPress/wordpress-develop/ public

Step 4: Restore the wp-config.php

  • Move the wp-config.php file back into the public directory.
mv wp-config.php ./public/

Step 6: Run the build process

  • This is done from within the public directory with npm and grunt.
cd public
npm install && grunt build

Step 7: SSH into the Website

  • At this point, we right-click the site name (“WPCORE”) in the Local by Flywheel User Interface and click the “Open Site SSH” option.

All of the following commands are run over SSH (i.e. within the website).

Step 8: Build a WordPress

  • As mentioned earlier, when developing for WordPress core the files we execute are in the /build directory. To configure our site update both the siteurl and the home options in the database table (wp_options) by appending /build to them.
  • We can do this from the SSH command line using the following WP CLI command.
wp option update siteurl "$(wp option get siteurl)/build";wp option update home 
  • You can also manually update siteurl and home URL using the Adminer tool for MySQL, just update to add /build/ at the end of the URL

You can learn more about setting up PHP unit tests in reference articles

References :