Web Tools Setup (MacOS)

 

Preamble

The purpose of this section is to help you install command line tools that you will need to work on our Drupal websites. These tools will include:

  • Visual Studio Code: A popular and powerful Integrated Development Environment (IDE)
  • Sublime:  another free text editor that is very useful for cleaning up content
  • Various tools for your terminal command-line

Text in Bold indicates a command you can copy and paste into your command line. 

To copy and paste, copy text normally and then right-click inside Ubuntu to paste.

    Sublime

    This program can clean up unneeded/excess HTML and other code surrounding text. Additionally, it has a cool lizard icon as its logo. You can go download a free copy from their download page

    Getting Terminal Set-up with Tools

    Installing tools

    Install Git 

    You likely already have Git on your machine. Verify Git is installed by running this command:

    git --version

    If git is not installed, you should be prompted to install it.

    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

    To install PHP, we need to first install Homebrew (a terminal package manager), and to install Homebrew, we need Xcode. Run the following commands to accomplish this. You will be asked for your password while installing homebrew.

    xcode-select --install

    xcode-select -v

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    brew doctor

     

    Now we can install PHP...

    brew tap shivammathur/php

    brew install shivammathur/php/php@8.1

    brew link --overwrite --force shivammathur/php/php@8.3

     

    php -v

     

    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. 

    cd ~

    vim .zshrc

    i (no need to press Enter) 

    Add the following line to the top of the file under the first lines of comments. In this case, "samh" is my Linux username. Replace this with your username.

    alias terminus=/Users/samh/terminus

    Screenshot of bashrc setup ***check to see if your terminus is actually in this spot with file explorer... you may not have a /vendor or /bin.

    Press "Esc"

    :wq

    Reload the terminal 

    Either close and reopen or enter 

    cd ~

    source .zshrc

    Verify Terminus is working 

    terminus -v

    Show Git Branch (this doesn't work with MacOS, will replace soon)

    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 (down arrow to get there) 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

     

    Checking Terminus

    Terminus should work just fine for you as is. We need to update our versions of Terminus, but we will come back to that later. For now, just follow these steps to verify your Terminus install still works.
     
    1. Open your bash
      1. Your path/command should be something like ~/websites$
    2. terminus --version
      1. Should be 3.something
    3. terminus drush samhales.dev -- cc
      1. Exit 0 means success

    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
      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 websites folder
    5. Click OK
    6. Voila
    7. Now select File
    8. Save Workspace As
    9. Enter a name (perhaps "websites")
    10. Click Save
    11. Once the workplace is set up, close VS Code
    12. Open terminal (close and reopen if already open)
    13. CD into your website folder, the one that you navigated to in step 4
    14. code .
    15. VS code will open
      1. From then on, the quickest way to open the workspace is opening the parent folder in terminal and typing code .

    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> -- cache:rebuild

    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 and location (hit enter)
    • No passphrase

    cat ~/.ssh/id_rsa.pub

    Copy all the content of the file 

    S

    eval 'ssh-agent'

    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

    To connect to GitLab:

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