Author • Georgi Marokov

WordPress with WP-CLI on Bash on Ubuntu on Windows 10

  • PHP
  • WordPress
  • WP-CLI
  • Windows
  • WSL


This sounds like a clickbait at first but it’s not, if you heard of the new Microsoft feature — Bash on Ubuntu on Windows.

Windows 10’s Anniversary Update offered a big new feature for developers: A full, Ubuntu-based Bash shell that can run Linux software directly on Windows. This is made possible by the new “Windows Subsystem for Linux” Microsoft is adding to Windows 10.

In this blog post, I'll guide you through setting up fully functional WordPress installation with WP-CLI on top of LAMP server which will be installed on my Linux Subsystem through Windows 10.

Let's dive in!

First we need to install Bash on Ubuntu on Windows

  1. You can find a detailed tutorial on how to install Bash on Ubuntu on Windows here.
  2. After the installation is completed, run the app as administrator. If you would like to use different user than root, you can read this.

Next, let's set up the LAMP Stack

  1. WordPress requires PHP, MySQL and HTTP server. We can go with Apache, so LAMP toolset is all we need. This command will install PHP, MySQL and Apache with a single command:
    $ sudo apt-get install lamp-server^

Install command-line interface for WordPress

When we have our server ready we can start with the fun part.
Note that you must have PHP 5.3.29 or later and the WordPress version 3.7 or later.

  1. Download the wp-cli.phar file via curl:
    $ curl -O

  2. Now lets check, if it is running:
    $ php wp-cli.phar --info

  3. To use WP-CLI from the command line with the wp command, you'll need to make the file executable and move it to a location within your PATH. Here's how you can do it:
    $ chmod +x wp-cli.phar $ mv wp-cli.phar /usr/local/bin/wp

  4. You can verify that it's working by running:
    $ wp --info

If everything went smoothly, you should see something like this:

$ wp --info
PHP binary: /usr/bin/php5 PHP version: 5.5.9-1ubuntu4.14
php.ini used: /etc/php5/cli/php.ini
WP-CLI root dir: /home/wp-cli/.wp-cli
WP-CLI packages dir: /home/wp-cli/.wp-cli/packages/
WP-CLI global config: /home/wp-cli/.wp-cli/config.yml
WP-CLI project config: WP-CLI version: 0.23.0$

Set up your local WordPress installation

Once your environment and tools are ready, creating a new local WordPress installation using WP-CLI is just a few commands away.

  1. Navigate to the directory where your WordPress site will live:
    $ cd ../var/www/html

  2. Remove the default index.php file. It's also a good time to start Apache and MySQL services:
    $ rm index.html
    $ service apache2 start
    $ service mysql start

  3. Now, let's download the core WordPress files:
    $ wp core download

This will download the latest version of WordPress in English (en_US). If you want to download another version or language, use the --version and --locale parameters. For example, to use the Bulgarian localization and 4.2.2 version, you would type:
$ wp core download --version=4.2.2 --locale=bg_BG

  1. Once the download is complete, you can create the wp-config.php file using the core config command. Pass your database access details as arguments here:
    $ wp core config --dbname=databasename --dbuser=databaseuser --dbpass=databasepassword --dbhost=localhost --dbprefix=prfx_

  2. The wp db create command will use the arguments from wp-config.php to create your database:
    $ wp db create

  3. Finally, to install WordPress, use the core install command:
    $ wp core install --title=WordPress Website Title --admin_user=admin_user --admin_password=admin_password [email protected]

  4. Once you receive the success message, restart Apache:
    $ service apache2 restart

After the restart is completed, open your browser and go to http://localhost/ and enjoy your brand new WP installation.

Note: Remember that every time you start the application, you must first start the MySQL and Apache services:
$ service mysql start|restart|stop
$ service apache2 start|restart|stop

Final words

I truly appreciate WP-CLI for saving me time on routine tasks. This setup may seem like a workaround, and in some ways, it is. However, nothing beats working in a real Linux environment. Yet, let's acknowledge the remarkable fact that we're running native Linux software on Windows. The possibilities are endless.

Keep in mind that the Bash on Ubuntu on Windows feature is still in beta, so let’s hope that Microsoft will keep up with the good news.

Further readings

How to access your Ubuntu Bash files in windows and your Windows system drive in Bash
How to create and run Bash shell scripts on Windows 10
WP-CLI Documentation