To install WSL2 in Windows run:
wsl --install
Enter a username and password.
Update and upgrade Ubuntu:
sudo apt update
sudo apt upgrade
Install Apache
sudo apt install apache2
Add PHP repository:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Create this installation sh script: phpsetup.sh
touch phpsetup.sh
vim phpsetup.sh
Press INSERT
to enter in edit mode.
Copy paste this content:
#!/usr/bin/env bash
apt update
apt install vim unzip -y
apt install libapache2-mod-php8.3 php8.3 php8.3-cgi -y
apt install mysql-client libmysqlclient-dev -y
apt install php8.3-mysql php8.3-sqlite3 -y
apt install php8.3-mbstring php8.3-curl php8.3-intl php8.3-gd php8.3-zip php8.3-bz2 -y
apt install php8.3-dom php8.3-xml php8.3-soap -y
apt install php8.3-xdebug
a2enmod php8.3
a2enmod rewrite
a2enmod actions
sed -i '170,174 s/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf
service apache2 restart
cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
composer self-update
Press ESC
, then enter: :qw
and ENTER
to save the file.
Set execute permission:
sudo chmod +x phpsetup.sh
Run the setup script:
sudo ./phpsetup.sh
For development only: give full write access:
sudo chmod -R a+rwx /var/www/html/
Install net-tools:
apt install net-tools
Run hostname -I
to find the local IP address of the VM, e.g. 172.26.131.159
hostname -I
Go back to your host machine and try to open the url using this IP-address, e.g. http://172.26.131.159
You should see the Apache demo website.
To access the files from Windows, create a network share.
Install Samba:
sudo apt install samba
Add a network share:
net usershare add html /var/www/html apache Everyone:F guest_ok=y
On your host machine use the UNC path to open the network share: \\172.26.131.159
\\172.26.131.159
You should see the html
folder.
Optional, mount the network share a drive Z:
on your host machine:
net use Z: \\172.26.131.159
Delete the file index.html
in the www
directory.
Create a new file index.php
in the www
directory.
Copy paste this PHP code:
<?php
phpinfo();
Navigate to http://172.26.131.159 in your browser.
You should see a PHP information page.