Build NativePHP on WSL for Windows (WIP)

First, create a new Ubuntu 22.04 on WSL with an account (not root) – (tips for reset WSL).

sudo su -
apt update && apt upgrade 
apt install php php-zip php-curl php-xml php-mbstring zip unzip acl libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgtk-3-0 libgbm1 libasound2 wine32
dpkg --add-architecture i386 && apt-get update && apt-get install wine32
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

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

exit
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
source ~/.bashrc
nvm install --lts
node -v
sudo mkdir /projets
sudo setfacl -Rm u:arnaud:rwx,d:u:arnaud:rwx /projets
cd /projets/

Create a Laravel project :

composer create-project laravel/laravel wixiweb
cd wixiweb
php artisan serve
composer require nativephp/electron
npm install
# npm install --platform=win32
php artisan native:install
npm install --global yarn
npm update
mkdir vendor/nativephp/php-bin/bin/linux/x86 -p
wget https://dl.zhamao.xin/static-php-cli/php-8.2.8-cli-linux-x86_64.tar.gz
tar -xvzf php-8.2.8-cli-linux-x86_64.tar.gz -C vendor/nativephp/php-bin/bin/linux/x86
rm php-8.2.8-cli-linux-x86_64.tar.gz
mkdir vendor/nativephp/php-bin/bin/win/x86 -p
wget https://windows.php.net/downloads/releases/php-8.2.8-Win32-vs16-x64.zip
unzip php-8.2.8-Win32-vs16-x64.zip -d vendor/nativephp/php-bin/bin/win/x86
cp vendor/nativephp/php-bin/bin/linux/x86/php vendor/nativephp/electron/resources/js/resources/php
cp vendor/nativephp/php-bin/bin/linux/x86/php vendor/nativephp/php-bin/bin/win/x86/
cp vendor/nativephp/php-bin/bin/win/x86/* vendor/nativephp/electron/resources/js/resources -r
cp vendor/nativephp/php-bin/cacert.pem vendor/nativephp/electron/resources/js/resources
sed -i 's/\/bin\/mac/\/bin\/linux/g' vendor/nativephp/electron/src/Commands/DevelopCommand.php
sed -i 's/\/bin\/mac/\/bin\/win/g' vendor/nativephp/electron/src/Commands/BuildCommand.php
sed -i 's/build:mac-arm/build:win/g' vendor/nativephp/electron/src/Commands/BuildCommand.php

For building :

php artisan native:build

For running (on WSL/Ubuntu) :

php artisan native:serve

If you have any suggestions : https://twitter.com/arnolem/status/1683183114099609600

Ressources récentes