WordPress with WP-CLI on Bash on Ubuntu on Windows 10
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!
- You can find a detailed tutorial on how to install Bash on Ubuntu on Windows here.
- After the installation is completed, run the app as administrator. If you would like to use different user than root, you can read this.
- 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^
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.
Download the wp-cli.phar file via curl:
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Now lets check, if it is running:
$ php wp-cli.phar --info
To use WP-CLI from the command line with the
wpcommand, 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
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$
Once your environment and tools are ready, creating a new local WordPress installation using WP-CLI is just a few commands away.
Navigate to the directory where your WordPress site will live:
$ cd ../var/www/html
Remove the default
index.phpfile. It's also a good time to start Apache and MySQL services:
$ rm index.html
$ service apache2 start
$ service mysql start
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
--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
Once the download is complete, you can create the
wp-config.phpfile 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_
wp db createcommand will use the arguments from
wp-config.phpto create your database:
$ wp db create
Finally, to install WordPress, use the
$ wp core install --url=example.com --title=WordPress Website Title --admin_user=admin_user --admin_password=admin_password [email protected]
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
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.