Skip to content

Instantly share code, notes, and snippets.

@markf3lton
Created October 27, 2019 00:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markf3lton/1bc0f8c7a41038464b2c5500f2706eec to your computer and use it in GitHub Desktop.
Save markf3lton/1bc0f8c7a41038464b2c5500f2706eec to your computer and use it in GitHub Desktop.

Drupal and Acquia BLT on Windows 10

This tutorial provides you with a (minimal) dev environment that you can use to start developing Drupal and use Acquia BLT.

Most corporate users are running a managed laptop, which admin access, but this tutorial should still work.

If you're behind a corporate firewall, you may need to get on the real Internet to run Composer and install dev tools.

Install WSL (Windows Subsystem for Linux)

You will need to run a one-liner PowerShell command as an admin. Call your corporate IT Help Desk to facilitate this. See https://docs.microsoft.com/en-us/windows/wsl/install-win10 _

From the Microsoft App Store, download and install Ubuntu.

Follow the setup instructions to create a non-root user (markfelton) with a password. This should be different than Windows user (mfelton001).

Homebrew is recommended on WSL/Ubuntu

Install Clang, and add it your PATH. See https://solarianprogrammer.com/2017/12/13/linux-wsl-install-clang-libcpp-compile-cpp-17-programs/

Follow the "Install and Configure brew" instructions on this page: https://medium.com/@edwardbaeg9/using-homebrew-on-windows-10-with-windows-subsystem-for-linux-wsl-c7f1792f88b3

Test it with brew install hello and brew install wget.

Follow the Linux instructions to install the drush-launcher Phar: https://github.com/drush-ops/drush-launcher

Install the BLT pre-requisites like composer

Acquia's BLT on Windows documentation covers useful pre-requisites but you can skip it and run these commands:

sudo add-apt-repository ppa:ondrej/php sudo apt-get update ("update" not "upgrade") sudo apt-get install -y php7.2-cli php7.2-curl php7.2-xml php7.2-mbstring php7.2-bz2 php7.2-gd php7.2-mysql mysql-client unzip git php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php sudo mv composer.phar /usr/local/bin/composer curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs

Set your git config

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

Add "prestissimo" to your global composer.json

composer global require "hirak/prestissimo:^0.3"

Install the LAMP stack

Although we installed Homebrew, we will install the LAMP stack the old-fashioned way.

I use this guide as my reference: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04

By installing your LAMP stack the old-fashioned way ouc an avoid fussing with Docker, Lando, DDEV, VirtualBox, or Vagrant (these can be hard to install if you are not an admin on your system).

For installation help with Docker, Lando, DDEV, etc, check out the guides on Acquia's website as well as on Jeff Geerling's blog (e.g. https://www.jeffgeerling.com/blog/2018/installing-php-7-and-composer-on-windows-10) and https://thinktandem.io/blog/2017/12/09/lando-blt-acquia.

Once you have LAMP, it is easy to start or restart services.

sudo service apache2 start  <== start, stop, or restart)
sudo service mysql start   <== start, stop, or restart)

MySQL

As noted in the LAMP guide from Digital Ocean, you will start with sudo mysql_secure_installation and set a root password but you can say "No" to everything else. Do not enable the VALIDATE PASSWORD PLUGIN.

Change the auth method from auth_socket to mysql_native_password. (This is covered in the guide above.)

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;

Create a "drupal" user for your projects. The convention is to have username "drupal" and password "drupal". Here's an example:

markfelton@USZ8X3OP60:~$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'drupal';
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL PRIVILEGES ON * . * TO 'drupal'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

You will know that MySQL is ready on your system, when you can run either of the follow commands without sudo!

mysql -u root -p
mysql -u drupal -p

File system

For your Drupal projects, it will be important to install them (or download them) to your C drive. I recommend you create a "Sites" folder within your existing Windows "Documents" folder.

Then, in your WSL/Ubuntu environment, the path to some-project would be /mnt/c/Users/mfelton001/Documents/Sites/some-project

You can also add a symlink from your Linux web root to your project on the C drive. For example, navigate to /var/www/html in your WSL environment, then create a symlink back to your codebase on your C drive using

sudo ln -s /mnt/c/Users/mfelton001/Documents/Sites/some-project/docroot some-project

I also made a symlink from Ubuntu back to my Sites folder, just to make getting around easier:

sudo ln -s /mnt/c/Users/mfelton001/Documents/Sites/ c_drive

In order to make sure that WSL files can be read by Apache, add yourself to the www-data group:

sudo /usr/sbin/usermod -a -G www-data markfelton

VirtualHosts

So far, everything has pretty straightforward. The VirtualHosts however are a nuisance. If you use Lando, DDEV, Docker etc. those programs take care of this nonsense. But we're doing this minimally here...

You will have to edit the sites-enabled file in Ubuntu (Be sure to back it up, first!)

sudo vi /etc/apache2/sites-enabled/000-default.conf

The changes to make include:

  • Uncomment ServerName and make it, ServerName localhost
  • Uncomment the DocumentRoot and make it match your symlink, DocumentRoot /var/www/html/some-project
  • Add this before </VirtualHost>
      <Directory /var/www/html/some-project>
           Options Indexes FollowSymlinks
           AllowOverride All
           Require all granted
      </Directory>
      <Directory /var/www/html/some-project>
           RewriteEngine on
           RewriteBase /
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteCond %{REQUEST_FILENAME} !-d
           RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
      </Directory>

Is everything working?

Now can test that your LAMP stack is working by adding a phpinfo.php to your docroot. It should load at "localhost" in your browser.

<?php
  phpinfo();
?>

At this point you can use composer to start any Drupal project on your C drive. Or go ahead and go to the BLT installer and run blt setup when it completes.

composer create-project --no-interaction acquia/blt-project

https://docs.acquia.com/blt/install/creating-new-project/

Now may be a good time to read my BLT Hands On Tutorial

Useful resources

https://www.drupal.org/docs/develop/local-server-setup/linux-development-environments/set-up-a-local-development-drupal-0-4

https://www.drupal.org/docs/7/configuring-clean-urls/clean-urls-with-apache-2-on-ubuntu

Troubleshooting

If you mess up on the PHP or MySQL install you can just uninstall them completely and start over:

sudo apt-get purge 'php*'
sudo apt-get purge 'mysql*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment