How to install Drupal 8 (and Composer) on Windows 10 Bash

Microsoft released Windows 10 Anniversary Update on August 2nd 2016, and this update included a much awaited "Windows Subsystem for Linux", which allows the user to run bash and command line Linux applications. It uses Ubuntu 14.04 as the base and as such is a great platform for local PHP development. In this tutorial I will show you how to install Drupal 8 (and Composer) environment on it.

Roughly speaking, the necessary steps for this are:

  • Enable Linux functionality
  • Install LAMP
  • Install Mysql database for Drupal
  • Install Composer
  • Install Drupal 8

Enable Linux functionality

First, make sure you have the Windows 10 Anniversary Update installed. At the time of this writing, it should be available via Windows Update for all Windows 10 users.

  • Enable Developer mode (in Settings app, or just by searching for it in the Start menu)
  • Enable Windows Subsystem for Linux (Control panel, Programs and features, Enable Windows features)
  • Reboot your PC
  • After rebooting, run "bash" command from the command line
  • Accept and install Ubuntu Linux
  • Set your Linux username and password

Alright, now you have a Linux shell installed, congratulations! Let's update it to be latest version possible.

sudo apt-get update
sudo apt-get upgrade

Install LAMP

Installing and configuring a LAMP (Linux, Apache, Mysql, PHP) system can take a while, so in this tutorial we are just going go with the defaults to get it running fast.

Install the necessary packages:

sudo apt-get install apache2 php5 libapache2-mod-php5 mariadb-server php5-mysql php5-cli php5-gd

The installation will ask some configuration (like mysql password), set those to your liking.

Let's start apache and mysql:

sudo service apache2 start
sudo service mysql start

Awesome, now you have a webserver running at http://localhost!

Let's enable clean URLs for Drupal 8:

sudo a2enmod rewrite
sudo service apache2 restart
sudo nano /etc/apache2/apache2.conf

Under <Directory /var/www..., change: "AllowOverride None" to "AllowOverride All"

Ctrl+X to save and quit

Restart Apache once more:

sudo service apache2 restart

Install Mysql database for Drupal 8

Open Mysql command line with command:

mysql -u root -pYOURMYSQLPASSWORDHERE

And create the database for Drupal 8 by typing:

CREATE DATABASE drupal8;

Type "quit" to exit Mysql command line

Note that we are using the root user for Mysql, NEVER do this in production! In local, it's fine, but not really recommended.

Install Composer

Installing Composer is pretty straightforward, just go to https://getcomposer.org/download/ and follow the Linux instructions. At the time of this writing the instructions are:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Let's make Composer global:

sudo mv composer.phar /usr/local/bin/composer

Alright, now you have Composer available with the command "composer"!

Install Drupal 8

Final step, let's install Drupal 8. Go to the Apache root:

cd /var/www

Remove the html folder (we will replace that with Drupal 8 installation).

sudo rm -rf html

Create a new project based on the latest stable version of Drupal 8 with Composer:

sudo composer create-project drupal/drupal html --stability stable

Set the permission of html folder

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

Now surf on to http://localhost and be greeted with your new Drupal 8 installation! Go through the installation procedure as usual. Remember the Mysql username and password you set! The database is drupal8.

 

 

Comments

clivesj's picture
clivesj
Tue, 08/09/2016 - 15:22

Thanks for this great tutorial.
But please note that there are multiple reports of w10 freezing and requiring restoration after W10UA. My laptop could not be recovered to un earlier and I had to perform a new install. Your milage could differ.

Brandon's picture
Brandon
Mon, 08/22/2016 - 19:15

Thank you for this! Is it possible to show how to set this up with the most recent version of Vagrant? I was working on something in Git Bash and would like to test it out using Vagrant instead.

Thanks for helping me out. I was little confused in installing composer. You made this possible. Highly recommend your website for Drupal developers.

Dee's picture
Dee
Fri, 10/14/2016 - 20:36

Thank you for the instructions.
I followed your instruction and at the end when I did "cd var/www", I got file or directory not found. Looks like Apache didn't create the folder. I went back to look at the installation message and saw the message below a lot.
"initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused"
"runlevel:/var/run/utmp: No such file or directory"

When I tried to restart apache I got the message below.
"AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 198.105.254.228. Set the 'ServerName' directive globally to suppress this message
[Fri Oct 14 13:24:44.654753 2016] [core:warn] [pid 6104] (22)Invalid argument: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT"

I also tried to check my version "apache2 -v " and I got the message below.
"Command 'apache2' is available in '/usr/sbin/apache2'
The command could not be located because '/usr/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with your user account.
apache2: command not found"

I think my installation went wrong and I'm not sure how to fix it.

Kristian Polso
Mon, 10/17/2016 - 13:16

Hmm, it sure looks like your apache didn't get installed correctly. Run this command to install apache2 again: sudo apt-get install --reinstall apache2

Dee's picture
Dee
Fri, 10/21/2016 - 05:29

Thank you for responding. The way I wrote the path was the problem. I didn't add / before var/www.

olivedev's picture
olivedev
Thu, 10/20/2016 - 14:50

There is a much easier way that doesn't involve any use of Composer. If you want to install Drupal 8 on Debian based server, then the best option is to use Cloudways platform. Using this platform, you can install Drupal 8 within few minutes. You just have to login to the platform, select the Drupal app and hosting provider, select server setting and click launch. You can find more info here: https://www.cloudways.com/en/drupal-cloud-hosting.php

Dee's picture
Dee
Fri, 10/21/2016 - 05:27

What is the path to the ubuntu files in windows. I want to access them without bash.

Brett's picture
Thu, 04/20/2017 - 18:02

Thanks, this was a great reference for me.

To add:
- I needed to run the sudo apt-get twice for some reason
- Git is required somewhere in the process so that needs to be installed
- I used this example on an Ubuntu environment at the same time and you need to install mysql-server
This one got me stumped for a while ===>
I got a mkdir(): Permission denied
This resolved it:
sudo groupadd www
$ sudo usermod -a -G www USERNAME

On installation it proceeds without cache (not sure why but not a big issue)

on my Windows environment I copied paste settings.php and its not picking up during the installation, trying ubuntu environment now.... I think it might be a chmod issue....

Thanks for the direction !!!

Brett's picture
Thu, 04/20/2017 - 18:22

update: the windows settings just decided to fix itself, I think it was the powermanagement that rebooted something ?? Question: can I load another drupal into www next to the html folder?

Add new comment