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
- Install WSL Windows Subsystem Linux.
- Install Visual Studio code
- Install Mysql Workbrench
- Install Composer
- Install Laravel 5.7
- Install WP-CLI
- Install Acrylic DNS Proxy.
- Download WSL Startup Scripts.
- Install VirtualBox(optional).
- Install Vagrant (optional).
Open a windows power shell and run as admin:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
- Reboot the system
Setting up WSL
- Open a bash instance in a terminal, type
sudo add-get install php7.2.
sudo apt-get update && sudo apt-get upgrade
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
sudo usermod -d /var/lib/mysql/ mysql
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh.
sudo bash nodesource_setup.sh.
sudo apt-get install nodejs.
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -.
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list.
sudo apt-get update && sudo apt-get install yarn.
sudo mv composer.phar /usr/local/bin/composer.
- Install Laravel run
composer global require "laravel/installer"
First, download wp-cli.phar using
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.
composer global require valeryan/valet-wsl.
- Also if you want to use Gui application via Xming add
export DISPLAY=:0.0. (optional)
Acrylic Setup (Windows)
- In Windows hit the windows key and search for Acrylic and find Edit Acrylic Host File.
127.0.0.1 *.devto bottom of file and save.
- Hit the windows key again and search for Stop Acrylic Service.
- Search again for Start Acrylic Service.
Valet Setup (WSL)
valet domain dev. (optional: defaults to .test and my preference is .dev)
- Browse to a laravel project folder and run
- To test, browse to folder.dev.
- In WSL and in project folder run
Valet Setup (Windows)
- 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.
- 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)
- Move the WSL startup scripts you downloaded earlier to C:/tools/wsl-startup/.
- Make any adjustments to services.sh.
- Create a Task Scheudule to run bash-start.vbs at logon.
- 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:
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
- Install Virtualbox (I’m using version 5.2.18)
- Download the Windows 10 install package for Virtualbox and run it in Windows.https://www.virtualbox.org/wiki/Downloads
- 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.
Install Vagrant (I’m using version 2.2.0)
- 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
- Open Ubuntu, locate the file you just downloaded, and install it.
sudo dpkg -i vagran_t2.2.0_x86_64.deb
- Download the Vagrant Windows package and install that as well. Make sure it’s the same version!
- Connect the two https://www.vagrantup.com/docs/other/wsl.html
Install Diff Tool (didn’t try yet)
sudo apt-get install dbus-x11 meld.
Setup Cron For Projects (didn’t try yet)
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/
Written by: Fabio
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.