Step-by-Step Guide to Install phpMyAdmin on WSL Ubuntu 22.04


This guide will walk you through installing phpMyAdmin on your WSL (Windows Subsystem for Linux) running Ubuntu 22.04.
However, before we dive into phpMyAdmin, we'll need to ensure we have a functioning LAMP stack (Linux, Apache, MySQL, PHP) set up.
phpMyAdmin is a tool that provides a user-friendly interface for managing and administering MySQL databases. So the prerequisites are:
WSL2 inside Windows and running Ubuntu 22.04 Apache (or Nginx) web server MySQL/MariaDB PHP with required modules (for PHP processing) Apache or NGINX or mysql is already installed or notApache dpkg -l | grep apache2NGINX dpkg -l | grep nginxmysql mysql -vBegin by updating your package lists to ensure you have the latest information:
sudo apt updateApache web-server (if not already installed):Install the Apache web-server using the following command:
sudo apt install apache2Once installed, verify that Apache is up and running:
sudo systemctl status apache2
If Apache is running correctly, the output should show its status as active
In case systemctl malfunctions (which can sometimes happen in WSL), you can start Apache using the service command:
sudo service apache2 startNow, let's test if Apache is running by opening a web browser and navigating to:
http://localhostYou should see the default Apache Ubuntu page. This confirms that Apache is installed and functioning successfully.

Since systemctl might not always work as expected on WSL, we'll recommend adding a configuration line to ensure Apache automatically starts when your WSL instance launches.
Here's how to edit your .bashrc file and add the line:
nano ~/.bashrcAdd the following line at the end of the file:
sudo service apache2 startSave the changes and exit the editor.
mysql is available and password is set:mysql is InstalledRun the following command:
mysql -vIf
mysqlis installed, this command will display the version information. Move to STEP 6
Run these commands to install MySQL:
sudo apt update
sudo apt install mysql-serverAfter installation, ensure the MySQL service is running:
sudo systemctl start mysql
sudo systemctl enable mysqlMySQL Requires a PasswordTry logging in as the root user:
sudo mysql -u rootpassword, this means, no password is set for the root user If you want to set a password for the root user:
sudo mysql -u rootALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
FLUSH PRIVILEGES;Replace
your_new_passwordwithpassword.
Exit MySQL:
EXIT;Log in again with the new password:
mysql -u root -pYou will be prompted to enter the password. If the login succeeds, the password is set correctly.

Use the following command to install phpMyAdmin:
sudo apt install phpmyadminDuring the installation, you'll encounter prompts for:
apache2 by pressing SPACE, then TAB, and finally ENTER.
Yes and press ENTER.
password for your MySQL root user.
sudo systemctl status mysql
If MySQL is running correctly, the output should show its status as active. Ensure all required PHP extensions are enabled. You might need to install and enable extensions like mbstring if not already active:
sudo apt install php-mbstring php-zip php-gd php-json php-curl
sudo phpenmod mbstringIn some cases, additional configuration might be required for Apache to recognize phpMyAdmin. Here's how to set it up:
Create a symbolic link of phpMyAdmin's Apache configuration file to the conf-enabled directory:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.confIt provide better security
or
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadminIt is simple but not fully secure
Restart Apache to apply the changes:
sudo service apache2 restartFinally, open a web browser and access phpMyAdmin using your WSL localhost followed by /phpmyadmin:
http://localhost/phpmyadmin
If you encounter error like this, where the code is print as text.

sudo apt install libapache2-mod-php sudo a2enmod php sudo systemctl restart apache2 sudo service mysql start