Skip to content

Instantly share code, notes, and snippets.

@ryanmortier
Last active July 13, 2022 11:10
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanmortier/4fb1861e6a3108a8b1ee83d7e23ace6a to your computer and use it in GitHub Desktop.
Save ryanmortier/4fb1861e6a3108a8b1ee83d7e23ace6a to your computer and use it in GitHub Desktop.
WSL Development Environment

WSL Development Environment

Windows

Source: https://docs.microsoft.com/en-us/windows/wsl/install-win10

  1. Elevated PowerShell: wsl --install
  2. Reboot computer when prompted.
  3. Setup will continue automatically and install Ubuntu.
  4. Setup a user and password for Ubuntu when prompted.
  5. Install Microsoft Terminal, configure fonts and theme.
  6. Install Visual Studio Code, configure settings, keybinds, theme, and extensions.

Ubuntu

Update

sudo apt update
sudo apt upgrade

Install Zsh and Oh My Zsh

Source: https://ohmyz.sh/#install

sudo apt install zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Install some utilities

sudo apt install xdg-utils unixodbc-dev zip unzip software-properties-common

Install PHP

sudo apt install php php-dev php-pear php-curl php-bcmath php-mbstring php-gd php-xml php-zip php-intl php-sqlite3 php-mysql php-redis php-ldap

Install multiple versions of PHP (Optional)

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade

The below script will install PHP 8.1, repeat for all the versions you wish to install.

sudo apt install php8.1 php8.1-dev php8.1-curl php8.1-bcmath php8.1-dom php8.1-mbstring php8.1-gd php8.1-xml php8.1-zip php8.1-intl php8.1-sqlite3 php8.1-mysql php8.1-redis php8.1-ldap

You can check your active PHP version with php -v.

To change PHP version:

sudo update-alternatives --config php

Install Composer

Source: https://getcomposer.org/download/

Get latest script from above if following is outdated.

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

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

sudo composer self-update
composer -V

Install NPM

Source: https://github.com/nodesource/distributions

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt update
sudo apt install nodejs
node -v
npm -v

Install Yarn

Source: https://classic.yarnpkg.com/lang/en/docs/install/#debian-stable

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
yarn -v

Install Image Manipulation Utilities (Optional)

Source: https://spatie.be/docs/laravel-medialibrary/v9/installation-setup

sudo apt install jpegoptim optipng pngquant gifsicle
sudo npm install -g svgo

Install Puppeteer (Optional)

Source: https://github.com/spatie/browsershot

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev libxshmfence-dev
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium

Install SQLite

sudo apt install sqlite3

Install MySQL

sudo apt install mysql-server
sudo usermod -d /var/lib/mysql mysql
sudo service mysql start
sudo mysql -u root -p

Hit enter at password prompt with blank password.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secret';
FLUSH PRIVILEGES;
quit
sudo mysql_secure_installation
  • Validate Password Component? No
  • Change root password? No
  • Remove anonymous users? Yes
  • Disallow root login remotely? Yes
  • Remove test database and access to it? Yes
  • Reload privilege tables now? Yes

Install SQLSRV Drivers (Optional)

Source:

Change PHP version from 8.0 to whatever you have installed (php -v) in following script.

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt update
apt install msodbcsql17
pecl install sqlsrv
pecl install pdo_sqlsrv
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.1/mods-available/pdo_sqlsrv.ini
phpenmod -v 8.1 sqlsrv pdo_sqlsrv
php -m | grep sql

Exit root prompt (ctrl+d).

Install Redis

sudo apt install redis-server
sudo service redis-server start

Install Keychain and SSH Keys

sudo apt install keychain

Make sure to add id_rsa and id_rsa.pub files to ~/.ssh/

sudo chmod -R a-rwx ~/.ssh
sudo chmod -R u+rwX ~/.ssh

Update .zshrc

vi .zshrc

Add Composer bin path to $PATH variable. Edit the second line in the .zshrc file:

export PATH=$HOME/bin:/usr/local/bin:$HOME/.config/composer/vendor/bin:$PATH

Add keychain to end of .zshrc file:

# Keychain
/usr/bin/keychain --quiet $HOME/.ssh/id_rsa
source $HOME/.keychain/$HOSTNAME-sh

Note: if $HOSTNAME is not set, manually type the hostname-sh found in ~/.keychain/ that ends with "-sh":

Example:

# Keychain
/usr/bin/keychain --quiet $HOME/.ssh/id_rsa
source $HOME/.keychain/ryan-gaming-sh

Install global Composer packages

composer global require laravel/installer
composer global require beyondcode/expose

Aliases

Add .aliases file to home and source in .zshrc config

~/.zshrc

# Aliases
source $HOME/.aliases

The Silver Searcher

sudo apt install silversearcher-ag

Git

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Notes

Services

After every reboot, you'll have to manually start up MySQL and Redis services.

sudo service mysql start
sudo service redis-server start

Web Server

I use Laravel primarily so I use php artisan serve as a web server. In cases where I'm not using Laravel I use php -S 127.0.0.1:8000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment