Skip to content

Instantly share code, notes, and snippets.

@brettsmason
Last active December 23, 2021 08:19
Show Gist options
  • Save brettsmason/2f7f504d8935cb4936c833feca359c51 to your computer and use it in GitHub Desktop.
Save brettsmason/2f7f504d8935cb4936c833feca359c51 to your computer and use it in GitHub Desktop.
WSL Setup

Prerequisites

Update

sudo apt-get update && sudo apt-get upgrade

Shell

Fish

sudo apt-add-repository ppa:fish-shell/release-3
sudo apt-get update
sudo apt-get install fish

Set Fish as default shell

From bash:

chsh -s $(which fish)

Starship (for nice prompt)

sh -c "$(curl -fsSL https://starship.rs/install.sh)" (from bash)

Then in ./.config/fish/config.fish add:

starship init fish | source

Remember key

sudo apt install keychain

Then in ./.config/fish/config.fish add:

eval (keychain --quiet --eval --agents ssh id_rsa)

Fisher and plugins

curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher

Node/Yarn

nvm install lts
nvm use lts
npm install -g yarn

Composer

wget https://getcomposer.org/installer
php installer
sudo mv composer.phar /usr/local/bin/composer

Set the path in the ~/.config/fish/config.fish file.

set -x PATH ~/.config/composer/vendor/bin $PATH 

WP CLI

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Git setup

git config --global user.name "Brett Mason"
git config --global user.email "[email protected]"

Valet

Permissions

sudo visudo
ALL ALL = (root) NOPASSWD: /usr/sbin/service
username ALL=(ALL) NOPASSWD: ALL
sudo add-apt-repository ppa:ondrej/php.
sudo apt-get update && sudo apt-get upgrade

Dependencies

sudo apt-get install libnss3-tools jq xsel libssl-dev zip unzip pkg-config libmemcached11 libmemcachedutil2 imagemagick memcached redis-server
sudo apt-get install network-manager dnsmasq

Lemp

sudo apt-get install nginx mysql-server php-fpm php-cli php-mysql php-sqlite3 php-intl php-zip php-xml php-curl php-mbstring php-redis php-pear php-dev

MySQL Password

In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password. To do this, open up the MySQL prompt from your terminal:

sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
FLUSH PRIVILEGES;
exit
sudo service mysql restart

To test logging in as a normal user run mysql -u root -p and enter the password from step 4.

Finish Valet setup

valet install

Make a directory to store sites, eg mkdir ~/sites and run valet park from this directory, as well as valet secure to generate the SSL certificate for installing in the browser.

Errors and issues

Permissions error in VSCode

sudo chown -R myuser /path/to/folder

Imagick

https://gist.github.com/danielstgt/dc1068e577bbd8b6e9a6050a6db1f9c3#gistcomment-3212174

Autostarting services in WSL

https://askubuntu.com/questions/1355633/how-to-start-a-specific-service-when-ubuntu-is-started-on-wsl2

You can now execute an arbitrary command line when starting an instance by creating/editing /etc/wsl.conf (via sudo) with the following:

[boot]
command="service postgresql start"

This command runs as root and generates no output. If you need to run multiple commands, they should be semicolon separated (or something like &&) inside the command= string.

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