Skip to content

Instantly share code, notes, and snippets.

@gabrielsolomon
Last active July 14, 2022 22:00
Show Gist options
  • Save gabrielsolomon/9052aca1abd50c408255469151cfb2fe to your computer and use it in GitHub Desktop.
Save gabrielsolomon/9052aca1abd50c408255469151cfb2fe to your computer and use it in GitHub Desktop.
wsl setup
# Settings apply across all Linux distros running on WSL 2
[wsl2]
# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=4GB
# Sets the VM to use two virtual processors
processors=1
# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwarding=true
guiApplications=false
#!/usr/bin/env bash
sudo apt-get install keychain
mkdir $HOME/.ssh/
chmod 0700 $HOME/.ssh/
ssh-keygen
apt install net-tools
apt install software-properties-common
apt install unzip
#!/bin/bash
# Node
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm install node
npm install -g n
corepack enable
# YARN
# PHP
sudo apt install -y php8.0 php8.0-cli php8.0-common php8.0-xml php8.0-zip php8.0-mbstring php8.0-phpdbg php8.0-intl php8.0-mbstring php8.0-mysql php8.0-curl php8.0-dev php8.0-xdebug php8.0-ast php8.0-sqlite3 php8.0-opcache php8.0-msgpack
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
#[Ports]
#All the ports you want to forward separated by coma
$ports=@(80,443,10000,3000,5000);
#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}
#!/usr/bin/env bash
mysql_apt_deb=mysql-apt-config_0.8.14-1_all.deb
sudo apt-get remove mysql-server mysql-client -y
sudo apt-get autoremove -y && sudo apt-get autoclean -y
wget –c "https://dev.mysql.com/get/${mysql_apt_deb}"
sudo dpkg -i $mysql_apt_deb # select 5.7
sudo apt-get update
sudo apt policy mysql-server #(it will show 5.x is the default candidate)
sudo apt-get -y install mysql-server
# ensure your host windows have no mysql service running
sudo service mysql start
sudo service mysql stop
sudo dpkg -i $mysql_apt_deb # select 8.0
sudo apt-get update
sudo apt policy mysql-server #(it will show 8.x is the default candidate)
sudo apt-get -y install mysql-server
sudo sed -ie 's/\/usr\/share\/mysql\/mysql-helpers/\/usr\/share\/mysql-8.0\/mysql-helpers/' /etc/init.d/mysql
sudo service mysql start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment