Web Tools Setup

The purpose of this section is to help you get up with your command line tools that you will need to work on our Drupal websites. In this section we will give you links and instructions to download tools on your computer to help you do your web development. These tools will include:

  • Visual Studio Code - a free text editor and IDE
  • Notepad++ -  another free text editor that is very useful for cleaning up content
  • Ubuntu - a Windows command line tool that is very helpful for interacting with websites.
  • Pantheon & Ubuntu

As you move through this I have used Bold to indicate commands you use copy and paste into your command line. 

Visual Studio Code

VS works well with WSL2 and does everything we need. Here is what Visual Studio says about itself,

"Learning to code is intimidating, so set yourself up for success with a tool built for you. Visual Studio Code is a free coding editor that helps you start coding quickly. Use it to code in any programming language, without switching editors. Visual Studio Code has support for many languages, including Python, Java, C++, JavaScript, and more. Ready to get started? Check out these introductory videos or check out our coding packs for Java, Python, and .NET."

Install it from here, https://code.visualstudio.com/

Once you have downloaded and installed VS please add these extensions.

  1. Extensions
    1. Easy Less
    2. Symfony Code Snippets (could not find)
    3. Drupal Smart Snippets
    4. drupal-check
    5. Beautify css/sass/scss/less
    6. Remote WSL
    7. PHP Extension Pack
    8. phpfmt
  2. File mappings (I don't understand)
    1. .theme to PHP
    2. .module to PHP

We can still create workspaces for each set of folders so you can group your projects together. That's done like so:

  1. Open VS Code
  2. Select File
  3. Select Open Folder
  4. Navigate to your folder
    1. WSL 2 would be \\wsl$\Ubuntu\home\<user name>\<websites folder name>
  5. Click OK
  6. Voila
  7. Now Select File
  8. Save Workspace As
  9. Enter a name
  10. Click Save
  11. Once the workplace is set up, close VS Code
  12. Open bash
  13. CD into your website folder, the one that you navigated to in step 4
  14. code .
  15. VS code will open and make the connection to WSL
    1. From then on, the quickest way to open the workspace is either
      1. opening VS Code through Windows and selecting a recent location
      2. or opening the parent folder in bash and typing code .
    2. Any valid WSL enabled folder will look like this in File >Open  ecent
      1. /home/<user name>/<folder name> [WSL: Ubuntu]
  16. In VS Code, click on Extensions
  17. Scroll through your enabled list and look for any that have an Enable in WSL button
  18. Click on Enable in WSL for each
  19. You may need to restart VS Code

Notepad++

This simple yet incredibly useful text editor is very helpful when cleaning up content. I sometimes find it easier to copy the content of the page into Notepad++ and use is find and delete or replace function to clean up unneeded HTML. It is also a great tool when you bring content over from Word and want to place it is Drupal. Notepad++ will strip out the excess code that often comes over from Word. Additionally, it has a cool lizard icon as its logo. You can go download a free copy from their download page

notepad++ lizard icon

Getting Ubuntu Set-up with Tools

In this section you will install the tools you will use to update websites. 

Setup Ubuntu

Run Linux SubSystem command in PowerShell as admin 

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 

  1. Install Linux app 
  2. Open the MS Store 
  3. Search for Linux 

Pick Ubuntu 

Start the Linux app 

Installing tools

Setup your Linux account via the terminal (Ubuntu)

Install Git 

Run the following command in Ubuntu to install Git.

sudo apt-get install git 

Verify Git is now installed by running this command:

git --version 

Verify CURL Installation 

CURL is a command line tool to copy data from another server. You already likely have it installed. To verify its installation run this command:

curl --version 

If the curl version command above fails you will need to install CURL. Run the following commands:

sudo apt install curl

curl --version 

Install PHP

Run the following command and this will update all packages tracked.

sudo apt-get update 

Now, to specifically install PHP and its required components run the following commands: 

sudo apt-get update 

sudo apt -y install software-properties-common 

sudo add-apt-repository ppa:ondrej/php 

sudo apt-get update 

sudo apt-get install php7.4 php7.4-cli php7.4-mbstring unzip php7.4-gd php7.4-xml php7.4-curl 

Run the following command to verify that you have successfully installed PHP

php --version 

If the above PHP install fails, run this: 

sudo apt-get --fix-missing 

Install Composer 

To install Composer run the following commands:

curl -sS https://getcomposer.org/installer -o composer-setup.php 

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer 

To verify Composer run the following command:

composer --version 

Install Terminus 

curl -O https://raw.githubusercontent.com/pantheon-systems/terminus-installer/master/builds/installer.phar && php installer.phar install 

Now that you have copied the Terminus files and installed them, you need to tell Ubuntu that you have installed it. You do this by giving it an "alias" in its .bashrc file.  So, to add alias for Terminus execute the following commands in the terminal. Each must be followed by and "Enter". 

cd ~ 

vim .bashrc 

i (no need to press Enter) 

Add the following line to the top of the file under the first lines of comments 

Make sure to change the Linux username to your username. In this case "samh" is my linux username. You need to replace "samh" with your username.

alias terminus=/home/samh/vendor/bin/terminus

terminus alias in ubuntu bashrc 

Press "Esc"

:wq 

Reload the terminal 

Either close and reopen or enter 

cd ~ 

source .bashrc 

Verify Terminus is working 

terminus -v 

Show Git Branch

When you are working with Git it is very helpful to have the branch you are working on display on the Ubuntu command line. To enable this your need to run these command in your Linux terminal (Ubuntu): 

cd ~ 

vim .bashrc 

i (no need to press Enter) 

at the end of the file paste: 

# Show git branch name 

force_color_prompt=yes 

color_prompt=yes 

parse_git_branch() { 

    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' 

if [ "$color_prompt" = yes ]; then  

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' 

else 

    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ ' 

fi 

unset color_prompt force_color_prompt 

 

Press Esc 

:wq 

Ubuntu screen shot showing how to add branch and color coding

Starting Ubuntu in your Web Development Folder

To set Ubuntu so it starts up in your web development folder follow these steps. First of all, in Windows go to your C drive and create a folder called "WaTech". Within that folder create another folder called "Websites". In the future when you start copying project code from websites this is where you will copy your code to. Once you have created these two folders run the following commands:

cd ~

source .bashrc  

To choose the start folder add this line to the top of the .bashrc file that is open from Step 15 

cd /mnt/c/watech 

terminus alias in ubuntu bashrc

Press Esc 

:wq 

Close/reopen your Linux terminal 

Verify you started in the new location. When you open Ubuntu and typ ls you should see the "websites" folder 

Installing Ahoy

In Ubuntu enter the following commands:

sudo wget -q https://github.com/ahoy-cli/ahoy/releases/download/2.0.0/ahoy-bin-`uname -s`-amd64 -O /usr/local/bin/ahoy && sudo chown $USER /usr/local/bin/ahoy && chmod +x /usr/local/bin/ahoy 


ahoy --version 

When all has gone well you will see version 2.0.0

Connecting to Pantheon with Ubuntu

This section of the set up enables you to connect to Pantheon hosted sites using Ubuntu. If you do not yet have a Pantheon account skip this set-up. Without that account you cannot connect with Pantheon. We will give you the account when it is time.

The first step in connecting with Pantheon is to generate a key for Terminus auth. Go to https://dashboard.pantheon.io/users/#account/tokens/ 

Login if necessary 

Create your token 

Enter a token name 

Copy the Terminus command and run it in your terminal 

terminus auth:login --email=<email> --machine-token=<machine_token> 

Test out a Terminus command like cc all on a site. In an open Linux terminal (Ubuntu) enter: 

terminus drush <site name>.<env> -- cc all 

You should see a success message and Exit: 0 

You are now connected to Pantheon via Terminus. Well done.

Build Trust Between your Computer and Pantheon

Now that you are set up with Ubuntu talking with Pantheon, let us take the steps so you can build trust between your machine and Pantheon so you will not longer have to enter your Pantheon password to keep giving commands to Pantheon. So, open your terminal (Ubuntu) and enter these commands:

cd ~ 

ssh-keygen 

  • Keep the default name 
  • No password 

cd .ssh 

vim id_rsa.pub 

Copy all the content of the file 

:q 

Go to your Pantheon dashboard, https://dashboard.pantheon.io 

Select "Account" 

Select "SSH Keys" 

Paste the text copied from above into Add an SSH key 

Click "Add Key" 

Close/reopen your Linux terminal 

Run a terminus command on a Drupal 8 site terminus drush <site name>.<env> -- cr  

screen shot of adding an ssh key on Pantheon

 

Connecting to GitLab

Go to gitlab.com and make an account. Tell Sam your username and he will get someone to send you an invite to the WaTech Web group. Look out for an email! Follow the instruction on the email to get access to the WaTech repositories.

If you haven't done so already follow these instructions for the ssh key.

Open your bash

  • cd ~
  • cat ~/.ssh/id_rsa.pub
  • If, and only if it does not exist:
    • ssh-keygen
    • press Enter a bunch of times
    • Then, cat ~/.ssh/id_rsa.pub
  • Copy the code printed out, all the way from ssh to your ID at the end
  • Open https://gitlab.com/-/profile/keys
  • Paste in the RSA data
  • Enter a name for the key (doesn't matter what really)
  • Leave the date empty
  • Click Add key
  • CD back into a site folder and try again

To connect to GitLab:

  1. Open https://gitlab.com/-/profile/personal_access_tokens
  2. Create a new token, name it what you want
  3. Give it read_api access
  4. Click Create personal access token
  5. Copy the token at the top
  6. In the terminal run: composer config --global --auth gitlab-token.gitlab.com [your_token]