There are a few tips and tricks I found for this installation. Here are the details.
Check Windows Version
First, here’s the entire Microsoft section on WSL. I highly recommend reading through it.
There are various differences between the latest Windows 10 updates, so this might not work for your version!
I’m on Windows 10 Pro, latest edition as of this writing (July, 2018).
Open a CMD and it will be at the top:
Microsoft Windows [Version 10.0.17134.112]
My current Ubuntu version:
root@XXXXXXX:~#lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.4 LTS Release: 16.04 Codename: xenial
Check IIS is not running
Open Services and disable/stop World Wide Web Publishing Service unless you are going to configure Apache to run on a different port (not included here).
Update Ubuntu
I use the handy icon instead of CMD > Bash for command line. It should work the same.
sudo -i (I use this instead of typing sudo all the time) apt-get update apt-get upgrade
Add without new repos
apt-get install apache2 service apache2 start
Note: I am NOT having Apache autostart and I’d recommend against it if you are using both IIS and Apache.
Open a browser and go to http://localhost
You should see a page that looks like this:
Install PHP 7.2
Add whatever you need.
apt-get install php7.2 libapache2-mod-php7.2 php7.2-mysql php7.2-mbstring php7.2-common php7.2-xml php7.2-json php7.2-curl php7.2-zip
Add new repos
This may or may not be needed.
add-apt-repository ppa:ondrej/apache2 add-apt-repository ppa:ondrej/php apt-get update apt-get upgrade
Install PHP 7.2
Add whatever you need.
apt-get install apache2 apt-get install php7.2 libapache2-mod-php7.2 php7.2-mysql php7.2-mbstring php7.2-common php7.2-xml php7.2-json php7.2-curl php7.2-zip apt-get update apt-get upgrade service apache2 restart
Windows Hosts File
Make a local site (don’t forget: .dev is now a real TLD, so you can’t use it anymore). You will need Admin rights to edit this file. Make sure to save it.
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 site.local
Create Windows project folder
Create your project folder. You will creating the VHOST and pointing it to this folder in your Windows file system!
In my case it is:
c:\projects\site.local
which translates to
/mnt/c/projects/site.local/
Create Apache VHOST
Unlike in normal Ubuntu world, you need to specify your Windows folder in /etc/apache2.conf. Although you can create a symlink to /var/www, etc., the /var folder actually doesn’t exist.
Update apache2.conf
cd /etc/apache2/
nano apache2.conf
Add this to the bottom. If you don’t you will get a permissions error in your browser.
<Directory /mnt/c/projects/site.local/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Create your new VHOST
cd sites-available/ cp 000-default.conf site.local.conf nano site.local.conf
Take a look at the configuration. It’s pretty standard. Modify it, or you can use mine below.
Sorry, formatting was lost, but here’s what I ended up with. Note that the default LogLevel has “SSL warn”. Make sure to remove that unless you’ve configured SSL. Also note you’re adding the DocumentRoot again.
<VirtualHost *:80> ServerName noaa.local ServerAdmin webmaster@localhost DocumentRoot /mnt/c/projects/site.local LogLevel info ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /> Options FollowSymlinks AllowOverride All Order Allow,deny Allow from all </Directory> </VirtualHost>
Enable the site
a2ensite site.local.conf service apache2 restart
Add PHPInfo index.php file
Create an index.php in c:\projects\site.local\
<?php phpinfo(); ?>
Now open your browser and go to http://site.local
That’s it!