Laravel Development on Windows 10 Using Linux Subsystem

This is a guide on how to configure Windows 10 using the Fall Creators Update released in October 2017. I will be using Ubuntu for the Linux Subsystem.

Ubuntu

  1. Turn on Windows Subsystem for Linux in the Windows Feature
    windows_feature_wsl
  2. Restart Windows so it fully installs it
  3. Then go to the Windows Store app and download and install Ubuntu
    ubuntu_windows_store
  4. Launch it from the Windows Store screen. Terminal will open and will ask you questions to configure the environment such as username and password.
  5. You should update Ubuntu with the usual commands
    sudo apt-get update
    sudo apt-get upgrade -y
  6. Install build essentials
    sudo apt-get install build-essential -y

PHP7

Now your environment is up to date. The next step is to get PHP7 installed. Depending on the version of Ubuntu, you may not have access to the latest version of PHP. Just add a repository and install it. For this guide, I will be install PHP7.1.

  1. sudo apt-get install -y python-software-properties
  2. sudo add-apt-repository -y ppa:ondrej/php
  3. sudo apt-get update -y
  4. sudo apt-get install -y php7.1 php7.1-cli php7.1-common php7.1-mbstring php7.1-gd php7.1-mysql php7.1-mcrypt php7.1-zip php7.1-xml

NodeJS

  1. curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash –
  2. sudo apt-get install -y nodejs

Composer

Instructions can be found at https://getcomposer.org/download/. Please note, step 2 below changes. The hash value is generated automatically. Step 5 will move and rename the command so it is accessible throughout the environment. Step 6 will test it if it works.

  1. php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”
  2. php -r “if (hash_file(‘SHA384’, ‘composer-setup.php’) === ‘[this is where the hash goes – do not copy this verbatim – go to the link above’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”
  3. php composer-setup.php
  4. php -r “unlink(‘composer-setup.php’);”
  5. sudo mv composer.phar /usr/local/bin/composer
  6. composer about

Laravel

Please be careful with copying and pasting. The quotes sometimes gets pasted with a different font – thus ending in a different result. After installation, make sure you add the path to your profile file (~/.profile) with step 3. If there’s already a line that exist, just add it. Keep in mind that each path is separated by a colon (:) and ends with $PATH.

  1. composer global require “laravel/installer”
  2. pico ~/.profile
  3. export PATH=~/.config/composer/vendor/bin:$PATH
  4. source ~/.profile

MySQL Server

Install MySQL server and follow the on-screen instructions. If the server is not started or you get a mysqld.sock error, you probably need to start the service. The command is in step 3.

  1. sudo apt-get install mysql-server -y
  2. sudo service mysql start
  3. sudo mysql_secure_installation

To help manage your database, download MySQL Workbench from https://dev.mysql.com/downloads/workbench/. You may need to download some prerequisite software from Microsoft.

mysql_workbench_requirements
Click the OK button
mysql_workbench_download_prerequisites
Click the Download Prerequisites button

Click on the Download Prerequisites button and it will take you to https://dev.mysql.com/resources/wb62_prerequisites.html. This page will list a couple of software but all I download is the Visual C++ Redistrubatble for Visual Studio 2015. Meeting that requirement seems to be enough for me. I download the 64bit version to match my operating system. Once installed, run the MySQL Workbench installer again and you should have no problem.

Create a new connection. The default values should work. All you have to do is provide the password.

mysql_connection_test
Connect to your new MySQL Server

Make sure that Ubuntu is running and that the MySQL service is also running or you won’t be able to connect.

That’s about it. I’m glad WSL is out of beta. So far it’s been running well.

I tried Virtualbox with Ubuntu workstation and after the Creator’s Update, it stopped working. I can log in but it won’t load the desktop on the console window. Oddly enough, the preview window shows the desktop loaded.

I also tried Homestead but I get an error with the shared folder. I run npm commands and it tells me that it can’t delete and write because of permission denied. I also tried Hyper-V and Ubuntu workstation is horrible on it. Moving the mouse lags. I’ve given it 2 CPU and 6GB of ram. I used different drivers – nothing.

I also posted a different way to develop Laravel on Windows check it out here. It works for the most part but it’s not as clean with SSH keys and GIT repositories. That article is actually pretty popular based on my analytics. I’m a bit surprised since I don’t really recommend using Windows for development unless you’re using Microsoft technology. It’s just a huge headache. We’ll see how well this environment last. Fortunately for me I have Apple computers and can run Ubuntu on spare hardware. This guide is just for my curiousity and to help others. Also, I like being able to use “better” hardware than my Apple devices.

Similar Posts

2 Comments

  1. I changed the order in the Mysql installation. I first started mysql and then I ran the “mysql_secure_installation” command. So the command worked.

    1. @Luan ah yes, you are correct. by default the service is not started, therefore the command won’t work. thanks for the feedback. i have made the changes.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.