My Development Environment for Laravel & WordPress

Find out more

1Fabio

My Development Environment for Laravel & WordPress

Coding anywhere with Windows Subsystem Linux.

Windows 10 / Linux 18.04 Development Environment Setup

 

This outlines the steps I take to setup my development environment on a Laptop using windows 10 and the new feature WSL. This requires the latest Windows 10 update  with an Ubuntu 18.04 installed as Subsystem.

 

Warning: Advanced Topic! Using Vagrant within the Windows Subsystem for Linux is an advanced topic that only experienced Vagrant users who are reasonably comfortable with Windows, WSL, and Linux should approach.

 

Windows Setup Prerequisites

  1. Install WSL Windows Subsystem Linux.
  2. Install Visual Studio code
  3. Install Mysql Workbrench
  4. Install Composer
  5. Install Laravel 5.7
  6. Install WP-CLI
  7. Install Acrylic DNS Proxy.
  8. Download WSL Startup Scripts.
  9. Install VirtualBox(optional).
  10. Install Vagrant (optional).

Install WSL

Open a windows power shell and run as admin:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

  • Reboot the system

 


Setting up WSL

  1. Open a bash instance in a terminal, type  bash.
  2. Run sudo add-get install php7.2.
  3. Run sudo apt-get update && sudo apt-get upgrade
  4. Run sudo apt-get install network-manager libnss3-tools jq xsel build-essential libssl-dev dnsmasq nginx mysql-server php-fpm php-cli php-mysql php-sqlite3 php-intl php-zip php-xml php-curl php-mbstring redis-server php-redis
  5. Run sudo usermod -d /var/lib/mysql/ mysql

Node

  1. Run curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh.
  2. Run sudo bash nodesource_setup.sh.
  3. Run sudo apt-get install nodejs.

Yarn

  1. Run curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -.
  2. Run echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list.
  3. Run sudo apt-get update && sudo apt-get install yarn.

Composer

  1. Run wget https://getcomposer.org/installer.
  2. Run php installer.
  3. Run sudo mv composer.phar /usr/local/bin/composer.
  4. Run nano ~/.composer/composer.json.


Laravel

  1. Install Laravel run composer global require "laravel/installer"


WP-CLI

First, download wp-cli.phar using wget or curl. For example:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Then, check if it works:

php wp-cli.phar --info

To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. For example:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Now try running wp --info. If WP-CLI is installed successfully, you’ll see output like this:

OS:  Linux 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64
Shell:   /usr/bin/zsh
PHP binary:    /usr/bin/php
PHP version:     7.1.12-1+ubuntu16.04.1+deb.sury.org+1
php.ini used:   /etc/php/7.1/cli/php.ini
WP-CLI root dir:        /home/wp-cli/.wp-cli
WP-CLI packages dir:    /home/wp-cli/.wp-cli/packages/
WP-CLI global config:   /home/wp-cli/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 1.5.0

Voila! You’re now an official WP-CLI user.

 


Valet WSL

  1. Run composer global require valeryan/valet-wsl.

Bash Config

  1. Run nano ~/.bash_aliases.
  2. Add export PATH=~/.config/composer/vendor/bin:$PATH.
  3. Also if you want to use Gui application via Xming add export DISPLAY=:0.0. (optional)
  4. Run source ~/.bashrc.

Acrylic Setup (Windows)

  1. In Windows hit the windows key and search for Acrylic and find Edit Acrylic Host File.
  2. Add 127.0.0.1 *.dev to bottom of file and save.
  3. Hit the windows key again and search for Stop Acrylic Service.
  4. Search again for Start Acrylic Service.

Valet Setup (WSL)

  1. Run valet install.
  2. Run valet domain dev. (optional: defaults to .test and my preference is .dev)
  3. Browse to a laravel project folder and run valet link.
  4. To test, browse to folder.dev.
  5. In WSL and in project folder run valet secure.

Valet Setup (Windows)

  1. In Windows Explorer browse to C:/tools/valet/certs/ and double click the install_certs.cmd file. This will install any certs in the folder as trusted root certificates.
  2. Refersh your browser and see if HTTPS in enabled and valid. You may need to restart valet and your browser to get everything in sink.

WSL Startup (Windows)

  1. Move the WSL startup scripts you downloaded earlier to C:/tools/wsl-startup/.
  2. Make any adjustments to services.sh.
  3. Create a Task Scheudule to run bash-start.vbs at logon.
  4. Reboot to test startup. You should be able to browse to any valet configured sites after reboot.

Setup you Bash aliases

Inside the bashrc file I have configured some aliases to speed up my workflow.  Adding the following aliases to your bash file will let you run “cdpro” to navigate to your main projects folder.

run nano ~.bashrc

#Bash aliases – FP
alias mysqlstart='sudo /etc/init.d/mysql start'
alias mysqlstop='sudo /etc/init.d/mysql stop'
alias mysqlstatus='sudo /etc/init.d/mysql status'
alias mysqlrestart='sudo /etc/init.d/mysql restart'
alias ngstart='sudo service nginx start'
alias ngstop='sudo service nginx stop'
alias ngstatus='sudo service nginx status'
alias cdpro='cd /mnt/c/Users/FabioHood/projects/'
alias ls='ls -alt'

You can add more if you need by following this pattern:

alisas [aliasName]='[command]’

 


Hands Up! the setup below is actually a bit heavy for my laptop so I have preferred stitch with the one above. I prefer to keep Vagrant and Virtualbox on my desktop machine and use WSL on a laptop.

Alternative setup (optional)

This setup requires a bit more disk space as vagrant deploy a virtual server machine for each website we want to run on our machine. However the Vagrant installation is still a beta release and the setup with WSL has some issues.

Install Virtual Box

  1. Install Virtualbox (I’m using version 5.2.18)
  2. Download the Windows 10 install package for Virtualbox and run it in Windows.https://www.virtualbox.org/wiki/Downloads
  3. Add Virtualbox to your Windows environment variables.
    For me this path was D:\Program\VirtualBox
    tip:  type  Windows Key then search “environment variables” and it’ll take you right to it.
  4. Reboot.

Install Vagrant (I’m using version 2.2.0)

  1. Download the 64-bit Debian package of Vagrant that suits your needs. I’m using version 2.2.0 as it’s the latest release at time of writing.https://www.vagrantup.com/downloads.html
  2. Open Ubuntu, locate the file you just downloaded, and install it.
    sudo dpkg -i vagran_t2.2.0_x86_64.deb
  3. Download the Vagrant Windows package and install that as well. Make sure it’s the same version!
  4. Connect the two https://www.vagrantup.com/docs/other/wsl.html

Other Extras

Install Diff Tool (didn’t try yet)

  1. Run sudo apt-get install dbus-x11 meld.

Setup Cron For Projects (didn’t try yet)

1 Run sudo crontab -e.

Crontab Setup Example

*/5 * * * * php /mnt/c/username/Projects/folder/artisan schedule:run >> /dev/null 2>&1

 


Image credits: laravel-news

Originally posted by https://gist.github.com/valeryan/d071dad5a32ccf94d07e

Alternative setup using Vagrant and Virtual box see also post by http://michaelkant.com/blog/wsl-and-you/

 


The Author

Written by:

I am a senior entrepreneur, full-stack php developer, WordPress, Magento experience with knowledge responsive web design, frameworks and SEO techniques. Several years of experience as CAD Designer and website-eCommerce administrator with digital marketing experience. Analytical mindset with problem solving skills. Productive, self motivated and well organised. I’m a bilingual Italian-English with a strong personality, very flexible, and enthusiastic to work in other Cities or Countries. Loving knowledge and new challenges if there is anything that I don’t know how to do, I’m always likely to learn it. I put passion and care in everything I do. I’ve a strong sense of responsibility, ethics and duty. I’m a friendly, enthusiastic open minded person, always happy to work in a team but also capable of working on my own.


Related Posts

Mobile application development with flutter

Build Mobile Apps With Flutter

Multi-language-laravel

Laravel 5.7 Multi-language | Complete guide

Dashboard Virtualmin

How to build your own web hosting server using Virtualmin, Ubuntu 18.04 and Vitualbox in 40 Minutes.


Comments

Leave a comment

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



1 Comment

    a Laravel Development company
    February 13, 2019

    Nice post! Thanks for sharing this.

Need Help?

Just get in touch! I'm always happy to help.


Get professional advice today on a wide range of solutions for your business.

Contact Fabio