LAMP Dev Stack in Windows

Tech Tips, Web Dev Tips

Right away, just a note that this tutorial of course assumes you’ve already installed WSL on your Windows 10 machine. Also, another note, this is not a fancy polished tutorial. We’re not going to have a bunch of screenshots, instead just info you need to get the job done. With that out of the way, let’s go…

STEP 1 – Initial prep work

First, make sure you are running Ubuntu 18 not Ubuntu 16 using this command: lsb_release -a

If you aren’t on Ubuntu 18, you’ll need to either install the Ubuntu 18 app or if you are using the general Ubuntu app, you have to use this command to upgrade: sudo do-release-upgrade. More details here on how to upgrade.

Side Step! Update your bash theme. If you do, it’ll now be easier on the eyes and look like so:

Now run this command to make sure your Ubuntu install is all up to date:

sudo apt update && sudo apt upgrade

Now before we proceed, you should know you could just skip almost all of the step below and just do: sudo apt install lamp-server^ phpmyadmin. However really it’s not much more work to do this properly and have full control over everything. With that caveat out of the way, let’s get rolling….


Step 2 – Install Apache2

sudo apt install apache2
sudo service apache2 start

If you encounter error / warning message…use this command and add the following to the bottom of this file.

sudo nano /etc/apache2/apache2.conf
# fix error in WSL (Protocol not available: AH00076: Failed to enable APR_TCP_DEFER_ACCEPT)
AcceptFilter http none
AcceptFilter https none

Enable Apache modules you need, such as SSL rewrite and SSL

sudo a2enmod rewrite
sudo a2enmod ssl
sudo service apache2 restart

Now we need to create a symlink to your main web dev (websites) folder in your Windows file system to your Linux system. So do something like this:

sudo ln -s /mnt/c/websites /var/www/devroot


Step 3 – Install MySQL Server + PHP

sudo apt install mysql-server

Note: You will not be asked to create a password, but on a local install that should be fine.

sudo usermod -d /var/lib/mysql mysql
sudo apt install libapache2-mod-php php php-curl php-gd php-mbstring php-mysql php-xml php-zip
sudo phpenmod mbstring

Now we need to make changes to the default PHP settings. Search and find these three items and put in whatever value you want (if you want to change them at all):

sudo nano /etc/php/7.2/apache2/php.ini
  • max_execution_time = 120
  • post_max_size = 64M
  • upload_max_filesize = 64M

In your Windows file systems (specifically in your “websites” folder we talked about above and created a symlink for), create a root localhost folder called “htdocs”, or whatever you want to call it.

sudo nano /etc/apache2/sites-enabled/000-default.conf

In this file above, update document root to the above symlink and add in the code below to enable htaccess file processing. So it should look something like this:

DocumentRoot /var/www/devroot/htdocs

AllowOverride All
Require all granted

Lastly, we need to start up the MySQL server like so:

sudo service mysql start


Step 4 – Install PHPMyAdmin

sudo apt install phpmyadmin

– Make sure apache2 is selected for configuration
– Yes, configure db. Setup a password.

Add the phpMyAdmin configuration to apache2. Edit apache2.conf file (like so if you recall, sudo nano /etc/apache2/apache2.conf and add the following line at the bottom:

Include /etc/phpmyadmin/apache.conf

Now, restart Apache2, with a command you’ll end up being familiar with:

sudo service apache2 restart

Unfortunately we’re not done yet since MySQL 5.7, MySQL root login requires some permissions edits, so run this command, changing password as to what you want:

sudo mysql --user=root mysql

Then enter this on the MySQL command line:

CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;

Great news!! We can now login at: http://localhost/phpmyadmin/ -> using username: phpmyadmin + password you just edited above.

Step 4.5 – Virtual Hosts and SSL

First create this file:

sudo nano /etc/apache2/sites-available/mysitename.localhost.conf

Now paste this in and edit as need be. Note: this is for an SSL site, if you aren’t using SSL on a particular local site, you can take some things out.

ServerName tester.localhost

ServerAdmin webmaster@localhost
DocumentRoot /var/www/devroot/tester

SSLEngine On
SSLCertificateFile "/mnt/c/Users/onetr/.localhost-ssl/tester.localhost.crt"
SSLCertificateKeyFile "/mnt/c/Users/onetr/.localhost-ssl/tester.localhost.key"

Options Indexes FollowSymLinks
AllowOverride All
Require all granted

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

With are the prep work done, you just need to know how to enable / disable your virtual host site. You do that like so, but NOTE you do not included .conf part of the filename, so something like “mysitename.localhost” is the filename.
Enable a site:

sudo a2ensite filename

Disable a site:

sudo a2dissite filename

Then you just need to restart Apache. You should know this command by now, but just in case here it is!

sudo service apache2 restart


Leave a Reply

Your email address will not be published. Required fields are marked *