WordPress Development for Windows with WSL (part 2): Installing the LAMP Stack

Home / Web development / WordPress Development for Windows with WSL (part 2): Installing the LAMP Stack

If you have reached this point, you have already completed the part 1 on the WordPress for Windows development guide with WSL. If you haven't done it yet, you're already late.

Once all the WSL stuff is up and running, then it's time to install your development environment. In my case, since all my work is focused on developing WordPress-based products, I'll need a LAMP stack (Linux + Apache + MySQL/MariaDB + PHP).

Although Ubuntu 20 comes with many tools already included, the server web is not one of them, so we are going to have to install it ourselves. Let's get to work, then.

To get started, we just need to open the Ubuntu program that has been installed on our Windows 10 computer:

Step 1: Upgrade software packages

Microsoft is not responsible for the maintenance of the Ubuntu distribution that we have previously installed, so before doing anything else, we must update the repositories that we are going to use to install any software.

In the console, issue the following commands, first one and then the other. To paste them, it doesn't work Ctrl+Vso use the right mouse button.

sudo apt update
sudo apt upgrade -y
sudo apt update
sudo apt upgrade -y

Step 2: Install Apache Server

Now launch the following command to install the Apache server:

sudo apt install -y apache2 apache2-utils

After installation, the server will not start automatically as it would be logical in Ubuntu. This is because WSL does not initialize systemdThe internal control system for startup, shutdown, service monitoring and much more. Take a look at to this post by Jonathan Bowman for more information.

But that shouldn't stop us from using WSL. We just have to start the service ourselves, and check that it is indeed working:

sudo service apache2 start
sudo service apache2 status

Now we can see our server running on localhost:

Step 3: Install MariaDB Database Server

Let's continue. To install MariaDB, we launch the following command:

sudo apt install -y mariadb-server mariadb-client

As before, we must start the service manually and check that it is working:

sudo service mysql start
sudo service mysql status

An important step to do now is to secure the installation, i.e. set the password and remove the root login, as well as remove the test database.

In particular, as I will use this environment for local development, I prefer to allow root access to the database with the root password.

sudo mysql_secure_installation

Here you can see the complete configuration I have applied:

Important: after doing all this, we will not be able to connect with the root user, due to some MariaDB restriction. To be able to do so, we must connect to the MySQL server:

sudo mysql -u root -p

And type the password. Once inside, you have to launch the following command, where password will be the password we used in the previous step

GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '';
FLUSH PRIVILEGES;

Step 4: Install PHP

Finally, let's install PHP version 8.1 with the following command:

sudo apt install -y php8.1  php8.1-xdebug

If you receive the error E: Unable to locate package php8.1 you need to add the relevant package repositories, and run the above command again:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Once the process is finished, enable the Apache module for PHP 8.1 and restart the server:

sudo a2enmod php8.1
sudo service apache2 restart

You can run the command php --version to make sure everything is correct, and you're done.

Finally, I always install a few additional PHP modules that are very common in my WordPress plugin developments:

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

In the next chapter we will see how to migrate a WordPress site from WAMP/XAMPP to Ubuntu in WSL so that everything works as it should without conflicts between them.

<i class="fa fa-angle-up" aria-hidden="true"></i>