Windows 11 WSL - PHP 8.1 Apache2 MariaDB

Windows 10 or WIndows 11, but WSL 2 provides huge support to linux development.

In this article i want to quickly guide you how I have setup PHP 8.1 (latest), Apache2 and MariaDB (alternative to Mysql but works similar) in my Windows 11 computer. It should work on windows 10 also.

First I had to install and enable WSL2

wsl --install
You can pick your favourite Linux Distribution to run with WSL


Then Install Ubuntu or Debian Image. I am Using Debian in this article.

wsl --install -d Debian

Once Installation of Debian is complete you will be prompted to enter user creation details like below


Now All set, how do you start this debian system.

Open the Command Prompt in windows 10/11 and type 

bash
wsl
Both of above commands will open the linux terminal (Debian).
Latest debian Version is 11 bulleye release.
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
Follow this article for Debian Upgrade in WSL (not required for first time installation users)

sudo apt -y install lsb-release apt-transport-https ca-certificates wget
You can install Apache2 Server 
sudo apt install apache2
If you have any previous installation of MYSQL or MARIADB in this you can remove that using following commands. Warning it will clear and remove all existing data.
sudo apt purge mysql*
sudo apt purge mariadb*
sudo apt purge mysql*
sudo apt autoremove
sudo apt autoclean
If you want to see the available package and version for mysql or mariadb in your local

dpkg -l | grep -e mysql -e mariadb
Install Mariadb server in your local 
sudo apt install mariadb-server
You dont have systemd in WSL managed linux. so all the service you installed must be started manually
sudo service mariadb start
sudo apt install php8.1-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.1-fpm
 
If you planning to install mongodb for php then use following
sudo apt install php8.1-mongodb
You must start mariadb in sudo user mode and set password for superuser
sudo mysql

Install most common php 8.1 modules using following command
sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-redis php8.1-intl -y
 
sudo a2dismod php7.4
a2dismod command will help disable a particular version of php, i had both php 8 and 7.4, so i am disabling 7.4 using above command.

You can edi php.ini file and restart apache using following commands
sudo vim /etc/php/8.1/apache2/php.ini
sudo service apache2 restart

Post a Comment

Previous Post Next Post