Skip to content

Instantly share code, notes, and snippets.

@Lemmings19
Last active June 20, 2019 09:03
Show Gist options
  • Save Lemmings19/b072aa4af5e0bff5f3332821f4c6b30c to your computer and use it in GitHub Desktop.
Save Lemmings19/b072aa4af5e0bff5f3332821f4c6b30c to your computer and use it in GitHub Desktop.
Set up Laravel 5.4 in an Ubuntu VM on Windows

To setup Laravel inside an Ubuntu virtual machine on Windows

Tested on Windows 10. Probably works in 7 and 8. I wrote this after I went through all of it, so let me know if I forgot a step.

In this guide:

  • VirtualBox (allows you to run a Linux operating system such as Ubuntu while you are running Windows)
  • Ubuntu 16.04 64 (a user friendly Linux installation that will be supported for many years)
  • LAMP stack (Linux, Apache, MySQL, PHP - all of the things that you will run your web application on)
  • Composer (this just manages your PHP dependencies, such as Laravel)
  • Laravel (provides you with a lot of pre-written PHP code to get your web app up and running)

Anywhere you need to run a command inside Ubuntu, I've written it like this:

this is a command you would have to run

Instructions:

Getting a Virtual installation of Ubuntu

Download these files:

http://download.virtualbox.org/virtualbox/5.1.14/VirtualBox-5.1.14-112924-Win.exe

http://releases.ubuntu.com/16.04.1/ubuntu-16.04.1-desktop-amd64.iso

Install both of those... Create a new Ubuntu 64 virtual machine inside VirtualBox. Allocate more than the recommended 8gb as it will run out very fast. I went with 3gb2. I also gave it 4096mb of RAM, but you can use whatever you have available.

When you open the Ubuntu VM for the first time, it will prompt you asking for a file... provide it with the Ubuntu .iso that you just downloaded and you will be guided through the Ubuntu installation process. It's pretty straightforward.

Using Ubuntu

It had been a while for me. Press ctrl+alt+t to open the terminal. That's the only part you really need. You can configure the rest however you want by googling your questions.

Getting copy+paste working between Windows and Ubuntu (optional)

Set these to Bidirectional:

VirtualBox>Settings>General>Advanced>Shared Clipboard + Drag'n'Drop

sudo apt-get install virtualbox-guest-dkms

Restart Ubuntu.

Installing the LAMP stack

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04

Upgrading to php 7.1 (optional)

service apache2 stop

sudo apt-get install php7.1 php7.1-common

sudo apt-get install php7.1-cli

sudo apt-get install php7.1-mbstring

sudo apt-get install php7.1-xml

sudo apt-get install php-zip

sudo apt-get update

php -v (just to make sure it's at 7.1)

sudo apt-get purge php7.0 php7.0-common

service apache2 start

Installing Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

sudo apt install composer

Installing Laravel

sudo composer global require "laravel/installer"

sudo nano /etc/profile

Add this to the top of the file:

# For gaining access to dependencies installed by Composer:
PATH="$PATH:$HOME/.composer/vendor/bin"

Restart Ubuntu.

Check these docs for configuration:

https://laravel.com/docs/5.4#installation

Starting a project

cd to the directory you want the project to be in.

laravel new project-name-goes-right-here

Start developing. Refer to the Laravel docs from here out:

https://laravel.com/docs/5.4

If you're having issues running sudo laravel, make the following change

**Note that this solution isn't the best and is user specific.

sudo visudo

Modify the line that looks like:

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

To have the composer path on the end of it: (edit YOUR_USERNAME)

Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/YOUR_USERNAME/.composer/vendor/bin"

How to make a shared folder between Windows and the Ubuntu VM

https://gist.github.com/Lemmings19/26bc8675c84d86576a92f7366d733f4c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment