If you are into web development, then I know you already familiar with LAMP stack that contains Apache, MySQL, PHP and PhpMyAdmin (optional) on a Linux platform. Yes, there are a couple of applications that provide LAMP in single install package to test various kinds of web applications on Windows 10/8/7 such as XAMPP and WAMP. However, if you are on Windows 10 then you don’t need them, you can get the native performance of Linux with command line interface to download, install and manage LAMP packages. And here in this tutorial, we let you know how to install MySQL, PHP and phpMyAdmin on Windows 10 using Windows Subsystem for Linux.
The Windows Subsystem of Linux which is basically Linux compatibility layer on Windows 10 to run various kind of minimal Linux distro images with command line interface. Such as Debian, Ubuntu, Kali, Arch Linux, OpenSUSE, CentOS and more… Some of them are officially available on the Windows 10 Microsoft Store such as Ubuntu. Here first, we will download Windows 10 WSL Ubuntu and in further steps, we will understand how to set up Apache, MySQL, PHP and phpMyAdmin (LAMP stack) on it. Thus, let’s start the tutorial.
Step 1: Enable Windows 10 WSL for LAMP installation
Installing Windows Subsystem for Linux is not a big deal, we don’t have to download some third-party packages at all. Just search for “Turns Windows features on or off” in the search box of Windows 10. Then find an option Windows subsystem for Linux, select and click the OK button.
On this topic, you can see our step by step article on how to activate Windows 10 WSL.
Step 2: Download WSL Linux Distro
The second thing we need is the Linux Distro on our WSL to install MySQL, PHP and phpMyAdmin. Although there are various Linux apps are available on Microsoft Store but here we are installing the Ubuntu 18.04 WSL. So, in the Windows 10 search box, type Microsoft Store and there search for Ubuntu. When it appears, click on the Get button to install it.
Step 3: Run Ubuntu 18.04 WSL
After installing, the Ubuntu will available in Windows 10 applications, click on it to run. To start properly it needs to download some extra packages, thus it will take some time, hence, be patient.
Step 4: Run system update command
So, what we have now is exactly the Linux Ubuntu server in command line interface, thus the command will also be the same to install any Linux packages as we use in standard Ubuntu OS.
Although we have recently, installed the Ubuntu WSL distro, there will be a possibility of updates, thus first run the system update command:
sudo apt-get update sudo apt-get upgrade
Step 5: Install Apache on WSL
The first thing in a Linux based LAMP stack is Linux OS itself which already have setup above, now what we need is Apache web server. It is a light open source web server to run different web apps and websites. To install it on Windows 10 subsystem for Linux use the below command:
sudo apt-get install apache2 sudo service apache2 start
Step 4: Installing MySQL on Windows 10 WSL
To install MySQL on Ubuntu Windows 10 WSL, here is the command:
sudo apt-get install mysql-server mysql-client sudo service mysql start
Create a root user to use with phpMyAdmin later
sudo mysql -u root
CREATE USER 'h2s'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'h2s'@'localhost'; FLUSH PRIVILEGES;
Note: Change the green colour text i.e Username and password with whatever you want to assign.
Step 5: PHP installation in Ubuntu Windows 10 WSL
Here we are installing PHP along with some important PHP extensions that you might need for your web projects.
sudo apt-get install php libapache2-mod-php php-mysql php-gd php-json php-curl php-xml php-mbstring
sudo apt-get update
Step 6: Install phpMyAdmin
Its time to download and install phpMyadmin on Windows WSL. We already have installed the main components of a LAMP stack that we need to install and run most of the PHP based projects on Linux. However, if you not much profound in database commands to manage it you should install phpMyAdmin too. Here is the command for that:
sudo apt-get install -y phpmyadmin
While installing the installer will ask for a couple of things.
Give some password for phpMyAdmin to register with the database server.
Choose the web server that you want to configure automatically with phpMyAdmin. As we have installed Apache thus use the Spacebar key to select the option apache2 and then press the Enter button.
Congifure the database for phpmyadmin.
When it asks for database user then simply type the one we have created above. In our case, it is h2s and you have to enter your created one.
Step 7: Test Apache and phpMyadmin
After performing all the above steps, its time check whether everything is working or not. For that first, we have to know what is our Ubuntu WSl IP address. Use the below command:
ifconfig
Now open your browser and type your system IP which you find in the above step. In our case, it is 192.168.43.93 and must be different in yours.
Test and Login to phpMyAdmin
To access the installed phpMyAdmin, type your system IP along with phpMyAdmin directory name as:
localhost/phpmyadmin
or
127.0.0.1/phpmyadmin
or using the local IP address, in our case it is:
192.168.43.93/phpmyadmin
When the login screen appears then type the root user for Database created above along with its password.
Here is the Dashboard phpMyAdmin.
When I initially left a comment I appear to have clicked on the
-Notify me when new comments are added- checkbox and from now on each time a comment is added I recieve four emails with the exact same comment.
Is there a way you can remove me from that service?
Appreciate it!
getting: The mbstring extension is missing. Please check your PHP configuration.
You can simply use
sudo apt install php-mbstring
and it will install this extension.I get an error when starting the MySql command? sudo service mysql start
tonyb@DESKTOP-VVQFMDN:~$ sudo service mysql start
* Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory
[ OK ]
tonyb@DESKTOP-VVQFMDN:~$
Try out these commands:
sudo service mysql stop
sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start
One more question, when running this WSL for Lamp on Windows 10 with Apache2, MySql and phpmyadmin, does the IIS have to be installed as well from the turn features on/off for the WSL to work?
No, there is no need to install or turn on IIS on Windows 10 to run WSL LAMP. As WSL is an independent feature to run Linux, thus the webserver created on it will also be. Even we can run IIS and WSL side by side if we want.
Working after the previous cmd’s you posted. Thanks for the help.