Installing WordPress on Windows Subsystem for Linux (WSL/Ubuntu)

Developers in Windows environments have traditionally used XAMP or other similar installations for WordPress development. In more recent setups Vagrant, Virtual Box and Docker have become popular. But with the release of Windows 10 Anniversary Update developers can run WordPress in a Linux shell right in Windows.

With Windows 10 Anniversary Update launched on August 2nd 2016 WordPress developers now have the capability to run a Linux shell within Windows. This feature is known as the Windows Subsystem for Linux and it allows running all command line Linux applications. The Linux version installed is the Ubuntu Linux from Canonical and is great for custom PHP development or Drupal.

When using the WSL environment you don't need a separate Virtual Machine running, instead you open a command line that runs Linux via a transparent translation layer. When in this console you can use all the tools that you have access to in a regular Ubuntu machine, but without the overhead of a VM. You also have native access to you files, so it is fast.

Installing WordPress to Windows Subsystem for Linux

First of all you will need to get Windows Subsystem for Linux running on your computer:

Make sure you are running the Windows 10 Anniversary Update Enable Developer Mode from the Control Panel Go to Windows features to find and enable "Windows Subsystem for Linux" Reboot your computer After login run the "Bash" command Accept and install installation of Ubuntu Linux from Canonical Set Linux username and password

After this you have got access to a Ubuntu Linux shell right on your Windows Machine! The next step is to update it with the latest upgrades. Issue the commands:

sudo apt-get update

sudo apt-get upgrade

The upgrade will take a few moments, but after that you have got all the latest updates from Canonical to your Ubuntu installation. Next you will need to install all the LAMP environment components to get WordPress up and running on Windows (thinking it's on Linux).

Issue this command to install the Apache Web Server, the MySQL database server and the PHP language and some additional utilities to get you started:

sudo apt-get install apache2 php5 libapache2-mod-php5 php5-mcrypt mysql-server php5-mysql unzip

Next up we will need to start Apache2 and MySQL servers:

/etc/init.d/apache2 start

/etc/init.d/mysql start

Once you have these steps you've got all it takes to run WordPress up and running:

Linux (not really, but close enough)

Apache (web server)

Mysql (database)

PHP (Programming language)

Before downloading WordPress, now is a great time to setup a MySQL database for WordPress:

Run: "mysql -uroot -p"

Enter your password

Run: "create database wordpress"

In our case we will use the mysql root user to access the database. This is ok as this environment is for local development only.

Now that we have a database we can continue with WordPress installation. You can use your Windows desktop browser to head over to WordPress.org to download the latest version. We will assume it is downloaded to the standard download environment.

Once the download is complete return to the Ubuntu Bash shell and execute:

cd /var/www/html/

sudo cp /mnt/c/Users\[YOUR-USERNAME-]\Downloads\wordpress-4-5-3.zip (depending on your username and wordpress version)

unzip wordpress-4-5-3.zip

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

Now you have the WordPress files in your document root. Because the Apache process is running on your local machine and you can return to your browser and open up http://localhost/wordpress/ and start WordPress installation.

After the installation you've got WordPress thinking running on Linux, right in Windows:

Windows Subsystem for Linux can be used to run WordPress and other PHP applications