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?

Steve V's picture
Steve V
Sun, 02/18/2018 - 16:15

Thanks for the article and thanks in advance for any advice you can provide. This is exactly what I am trying to do but ran into some issues because you published a while ago. If you have any ideas, I am a (fairly) noob to this and Drupal (< 4 months). Also I have used Acquia Dev Desktop 2 with some advanced problems using DRUSH. I am hoping this will get me close to the same functionality even if it is command line. Is that true?
---------------------------------- Steps ----------------------
I am running this version in WSL
This is the WSL version I am running:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

1) Had to install PHP 7.0 instead of 5.0 because the other builds could not be found I am used to using PHP7 so I thought this was best and seemed successful:
sudo apt install apache2 php7.0 libapache2-mod-php7.0 mariadb-server php7.0-mysql php7.0-cli php7.0 gd
2) php check did not pass - probably because the checksums are different so I skipped this step and ran the next step - thought this would be OK
3) Apache steps went fine
I had problems with the original syntax for MYSQL so I used this instead (also had to reset my root password):
$ sudo mysql --user=root --password=MYPASSWORD
- Instructions say to run as root, PHP Composer said not to do this, but I tried both ways.
- Some of the error samples are shown below -
4) MariaDB steps went fine.
------- ERRORS -----------
Composer steps had these errors (First line went off screen) - I tried more than once.

Detail
- phpunit/phpunit 4.8.36 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 2
- Installation request for squizlabs/php_codesniffer 2.8.1 -> satisfiable by squizlabs/php_codesniffer[2.8.1].
- squizlabs/php_codesniffer 2.8.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
Problem 3
- squizlabs/php_codesniffer 2.8.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
- drupal/coder 8.2.12 requires squizlabs/php_codesniffer >=2.8.1 <3.0 -> satisfiable by squizlabs/php_codesniffer[2.8.1].
- Installation request for drupal/coder 8.2.12 -> satisfiable by drupal/coder[8.2.12].

To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gd.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-mbstring.ini
- /etc/php/7.0/cli/conf.d/20-mysqli.ini
- /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

When I check localhost I get the Apache screens, not Drupal

Steve V's picture
Steve V
Sun, 02/18/2018 - 16:26

Pasted the same content twice.

Steve V's picture
Steve V
Sun, 02/18/2018 - 16:18

Thanks for the article and thanks in advance for any advice you can provide. This is exactly what I am trying to do but ran into some issues because you published a while ago. If you have any ideas, I am a (fairly) noob to this and Drupal (< 4 months). Also I have used Acquia Dev Desktop 2 with some advanced problems using DRUSH. I am hoping this will get me close to the same functionality even if it is command line. Is that true?
---------------------------------- Steps ----------------------
I am running this version in WSL
This is the WSL version I am running:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"

1) Had to install PHP 7.0 instead of 5.0 because the other builds could not be found I am used to using PHP7 so I thought this was best and seemed successful:
sudo apt install apache2 php7.0 libapache2-mod-php7.0 mariadb-server php7.0-mysql php7.0-cli php7.0 gd
2) php check did not pass - probably because the checksums are different so I skipped this step and ran the next step - thought this would be OK
3) Apache steps went fine
I had problems with the original syntax for MYSQL so I used this instead (also had to reset my root password):
$ sudo mysql --user=root --password=MYPASSWORD
- Instructions say to run as root, PHP Composer said not to do this, but I tried both ways.
- Some of the error samples are shown below -
4) MariaDB steps went fine.
------- ERRORS -----------
Composer steps had these errors (First line went off screen) - I tried more than once.

Detail
- phpunit/phpunit 4.8.36 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 2
- Installation request for squizlabs/php_codesniffer 2.8.1 -> satisfiable by squizlabs/php_codesniffer[2.8.1].
- squizlabs/php_codesniffer 2.8.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
Problem 3
- squizlabs/php_codesniffer 2.8.1 requires ext-simplexml * -> the requested PHP extension simplexml is missing from your system.
- drupal/coder 8.2.12 requires squizlabs/php_codesniffer >=2.8.1 <3.0 -> satisfiable by squizlabs/php_codesniffer[2.8.1].
- Installation request for drupal/coder 8.2.12 -> satisfiable by drupal/coder[8.2.12].

To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gd.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-mbstring.ini
- /etc/php/7.0/cli/conf.d/20-mysqli.ini
- /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

When I check localhost I get the Apache screens, not Drupal

Add new comment