Make Windows normal again

Make Windows normal again

An Overview of Developer Tools for Windows - Welldone Software - Medium

WSL Related

Linux’izing your Windows PC into a dev machine – Part 2 | cepa.io

Composer on WSL

https://www.jeffgeerling.com/blog/2018/installing-php-7-and-composer-on-windows-10 http://kizu514.com/blog/install-php7-and-composer-on-windows-10/ https://getcomposer.org/download/

MySQL on WSL

The mysql user folder is not set correctly by default and the server will complain about it when started (No directory, logging in with HOME=/). To fix, change the mysql user’s home directory to /var/lib/mysql:

sudo usermod -d /var/lib/mysql mysql

I had to add protocol=TCP in /etc/mysql/my.cnf

In my app living in WSL, changing the host from localhost to 127.0.0.1 in also helped.

# /etc/mysql/mysqld.conf.d/mysqld.conf
[client]
protocol=tcp

https://www.reddit.com/r/bashonubuntuonwindows/comments/78z18d/mariadb_server_on_wsl/

sudo add-apt-repository ppa:mysql-ubuntu/mariadb-10.1
sudo apt-get update
sudo apt-get install mariadb-server

grep socket -R /etc/mysql/


## /etc/mysql/mysql.conf.d/mysqld.cnf

Go to the file /etc/mysql/debian.cnf which has as the format:

[client]
host     = localhost
user     = debian-sys-maint
password = XXXXXXXX
socket   = /var/run/mysqld/mysqld.sock 
Take from there the password, that is randomly generated when installing MySQL (e.g. it differs between servers);



mysql -udebian-sys-maint -p02cShQo3PUHOFfzY



mysql -udebian-sys-maint -p02cShQo3PUHOFfzY --protocol TCP -h 127.0.0.1

[WSL 2] NIC Bridge mode 🖧 (Has Workaround🔨) · Issue #4150 · microsoft/WSL · GitHub


Find the IP address of your WLS2 Ubuntu host (use ifconfig) and connect to that IP using your Web browser.

sudo usermod -aG docker $USER

You will need to log out for this change to take effect.


wget https://github.com/lando/lando/releases/download/v3.0.0-rc.18/lando-v3.0.0-rc.18.deb


Install WSL 2 on Windows 10

You will need to start PowerShell as an Administrator, you might need a restart of your computer afterwards.

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

Download and install WSL Linux distribution based on Ubuntu 18.04 from the Microsoft Store. After that, type:

# if you don't have WSL 2 this command will not recognize "-v" switch
wsl -l -v

When you get WSL 2, you can do the following:

# to convert existing distribution (in my case: Ubuntu-18.04) to WSL 2
wsl --set-version Ubuntu-18.04 2

# to set WSL 2 as default for future distros
wsl --set-default-version 2

I also suggest to install Windows Terminal (Preview) from Microsoft Store, and Docker Desktop WSL 2 Tech Preview. Don’t forget docker context use wsl.

Best explanation so far: WSL2, zsh, and docker. Linux through Windows Docker Desktop version for WSL2 and was very slow compared from installing Docker by command line inside WSL2.

Nice resource for WSL2 Tricks: shayne/wsl2-hacks. For example, to access IP of WSL2: hostname -I | awk '{print $1}' but localhost also should work. Also sudo sysctl -w fs.inotify.max_user_watches=524288 is needed for Visual Studio Code.

Finally, test with this:

docker run --rm -p 80:80 tutum/hello-world (or nginxdemos/hello)

or even smaller:

docker run --rm -p 80:8000 crccheck/hello-world

localhost:80 should work from host.

Exoscale CLI tool on native Windows

Download cli_xxx_windows_amd64.zip from releases and extract exo.exe from zip into c:\bin\exoscale\

Open the command-line shell (cmd.exe) and type the following commands

1
2
mkdir \bin\exoscale
setx path "%path%;c:\bin\exoscale;"

Invoking setx can lead to error involving size limit and thus truncating your environment variable. I suggest using a special tool for manipulating Windows PATH variables, like pathed or RapidEE.

Install pathed:

1
2
3
4
powershell.exe -Command "Invoke-WebRequest -OutFile ./gtools-current.exe http://www.p-nand-q.com/download/gtools/gtools-current.exe"
start /wait gtools-current.exe /S /D=c:\bin\gtools && echo Install finished
del gtools-current.exe
\bin\gtools\pathed /MACHINE /APPEND C:\bin\gtools

Install wget if needed in future, and add that dir to the path:

1
2
3
mkdir \bin\tools
\bin\gtools\pathed /MACHINE /APPEND C:\bin\tools
powershell.exe -Command "Invoke-WebRequest -OutFile /bin/tools/wget.exe https://eternallybored.org/misc/wget/1.20.3/64/wget.exe"
I had a problem wiping my environment variables, so here they are:

System:
C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\PROGRAMDATA\ORACLE\JAVA\JAVAPATH;C:\PROGRAM FILES (X86)\COMMON FILES\INTEL\SHARED FILES\CPP\BIN\INTEL64;C:\PROGRAM FILES\DELL\DW WLAN CARD;C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\PROGRAM FILES\IDM COMPUTER SOLUTIONS\ULTRAFTP;C:\PROGRAM FILES (X86)\MICROSOFT EMULATOR MANAGER\1.0\;C:\WINDOWS\SYSTEM32\OPENSSH\;C:\PROGRAM FILES\INTEL\WIFI\BIN\;C:\PROGRAM FILES\COMMON FILES\INTEL\WIRELESSCOMMON\;C:\PROGRAM FILES\GIT\CMD;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\AOMEI Backupper;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;C:\Program Files (x86)\ZeroTier\One\;c:\bin\php7;C:\ProgramData\ComposerSetup\bin;c:\bin\exoscale 

User:
%HomeDrive%%HomePath%\cvladan\.babun;%LocalAppData%\Microsoft\WindowsApps;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;%LocalAppData%\atom\bin;%LocalAppData%\Programs\Microsoft VS Code\bin;C:\Program Files (x86)\Nmap;%LocalAppData%\Microsoft\WindowsApps;%LocalAppData%\Programs\Microsoft VS Code Insiders\bin;%AppData%\Composer\vendor\bin

(ignore) Make systemd permanent on WSL2

This is needed for snaps to work

sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig

cat << EOF | sudo tee /etc/profile.d/00-wsl2-systemd.sh
SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')
if [ -z "$SYSTEMD_PID" ] || [ "$SYSTEMD_PID" != "1" ]; then
    exec sudo /usr/sbin/enter-systemd-namespace
fi
if [ -n "$PRE_NAMESPACE_PATH" ]; then
    export PATH="$PRE_NAMESPACE_PATH"
fi
EOF

cat << EOF | sudo tee /usr/sbin/enter-systemd-namespace
#!/bin/bash

if [ "$UID" != 0 ]; then
    echo "You need to run $0 through sudo"
    exit 1
fi

SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')
if [ -z "$SYSTEMD_PID" ]; then
    /usr/sbin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
    while [ -z "$SYSTEMD_PID" ]; do
        SYSTEMD_PID=$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')
    done
fi

if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then
    exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a env \
        DISPLAY="$DISPLAY" \
        PRE_NAMESPACE_PATH="$PRE_NAMESPACE_PATH" \
        WSL_INTEROP="$WSL_INTEROP" \
        WSL_DISTRO_NAME="$WSL_DISTRO_NAME" \
        WSLENV="$WSLENV" \
        WSLPATH="$WSLPATH" \
        /bin/login -p -f "$LOGNAME"
fi
EOF

sudo chmod +x /usr/sbin/enter-systemd-namespace

cat << EOF | sudo tee /etc/sudoers.d/wsl2-systemd
Defaults        env_keep += WSLENV
Defaults        env_keep += WSL_INTEROP
Defaults        env_keep += WSL_DISTRO_NAME
Defaults        env_keep += LOGNAME
Defaults        env_keep += PRE_NAMESPACE_PATH
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/enter-systemd-namespace
EOF

sudo chmod 0440 /etc/sudoers.d/wsl2-systemd

Now every time you start the terminal/bash it will automatically put you inside a pid namespace with snapd running.

Multipass is WSL2 alternative

Multipass - Orchestrates virtual Ubuntu instances

That’s Ubuntu take on WSL2. Creating an instance is much slower, but much more things work (snaps without hacks). Is also supports cloud-init (as Hetzner Cloud and Exoscale also do). In essence, it is what Vagrant used to be.

multipass launch --name mpass
# or even without name

# enter the instance shell
multipass shell mpass

Working with Multipass instances

To be honest, Vagrant does do that. For sure, just like in theory KVM or Vmware can be used for that too. You can also set up a build farm and a Jenkins server to try to run “hello world”. The advantage of multipass is that to use it, all you have to do is:

snap install multipass


Snaps won’t work on WSL2

snaps don’t work on WSL2 as you need them for every command installed in that way!

The easiest way is to use snap (it is cross-distribution packager):

Using snapd in WSL2 - WSL2 - Ubuntu Community Hub Snapd on WSL2 (Insiders only for now) - snapd - snapcraft.io arkane-systems/genie: A quick way into a systemd “bottle” for WSL

sudo apt install -y daemonize

# this must be done on reboot
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target 

# this must be done on every login to WSL
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME 

snap version
sudo snap install kubectl --classic

Compiling kernel on WSL2 is easy: k3s on WSL2


How to register JetBrains PhpStorm

  1. Add the line 0.0.0.0 account.jetbrains.com to hosts file
  2. Enter activation key (mine worked from https://gist.github.com/MartirosyanMurad/54029eff68f02b31fcf5fc3e77635c3c#gistcomment-3037948)
  3. We can host our own jetbrains-license-server

Use PhpStorm for WordPress Development

date 01. Jan 0001 | modified 28. May 2021
filename: Windows » Dev Environment » Dump