Add Laravel to Path on Mac OSX

I have been playing around learning the Laravel, the PHP framework for web artisans.

It really is an awesome framework, however I did find getting up and running with the framework to be not as simple as I’d hoped.

I ran into a couple of installation niggles that I thought I would document in order to save others time and frustration.

Install PHP

The best way to set up a development environment or even to manage the packages installed on Mac OSX is to use Homebrew

Homebrew – The missing package manager for macOS

Check out the instructions to install Homebrew on MacOsx

If you have Homebrew installed, installing PHP is very simple, in the example below we will be installing PHP 7.2, which at the time of writing is the most current version.

If you would like to install any other version of PHP i.e PHP 5.6 you simply need to use brew install php56

Install Composer

In order to install and easily use the Laravel framework we will need to install composer

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

If you would like to install composer without making use of Homebrew you can so by

I recommend installing composer via Homebrew

Once the install has completed you can test it out by simply executing composer

Install Laravel

We can now install Laravel using composer we will add it to the global composer

We can also generate new Laravel web applications using

Add Laravel to path

The Laravel Documentation refers to an alternate method of creating a new Laravel project by using a the laravel new , but it requires an additional configuration step to make it work.

Make sure to place composer’s system-wide vendor bin directory in your $PATH so the Laravel executable can be located by your system.

In my opinion, this does not clearly explain what this means or provides sufficient detail on how to do this.

What is PATH

*nix Operating Systems and Microsoft Windows use Environment variables hold values related to the current environment.

PATH is an environment variable which is used for specifying a set of directories where executable programs are located.

In general, each executing process or user session has its own PATH setting.

How to Edit PATH

There are 2 approaches you can take to edit your PATH on MAC OSX.

Approach 1

Open your $HOME/.bash_profile using any Text editor of your choice. Typically, nano or Vim. In this example I will use nano.

The you can just copy and paste the following commands towards the end of the file

After completing that then you can CTRL + X to exit and save the file.

You will then also need to refresh your current terminal window with updated bash_profile.

Approach 2

If you want it to be automatically edit bash_profile all in one line you can do so by :

You will then also need to refresh your current terminal window with updated bash_profile.

Once you have completed either of the steps above you can now create a new projects using the laravel new [project name] commands.

Example of using Laravel new

We can create a new project named notepad using laravel new notepad.

Change into the new notepad directory cd notepad and start the project php artisan serve

Install Laravel Homestead

Laravel Homestead is pre-packaged Vagrant box that provides a development environment without you having to install everything on your local machine. Enabling you to create a complete environment for your laravel application.

In order to install this you will need to install

  • Virtual Boxbrew install caskroom/cask/virtualbox
  • Vagrant brew install caskroom/cask/vagrant

After you have completed the installation of the above you can install Laravel Homestead by running the following

It will take sometime for the installation to complete.

Once complete you will have the latest copy of a complete Ubuntu Lamp stack server set up, which you can directly SSH into. The project files on your local machine will be synced with the VM.

Once the installation of Homestead completes, you will need to create a homestead.yaml file that will hold all the configuration for your VM.

YAML is a human friendly data serialization standard for all programming languages.

Configure Homestead Per Project

Homestead is configured using a YAML file, which contains configuration information regarding sites & files on your computer, databases to create etc. When you start a new project, you have to add an entry to this file and re-provision.

When using Homestead on a per-project basis, you keep this file with your project and it contains only that project’s settings. Enabling you to quickly clone a project if it’s under source control, and quickly boot a Homestead instance for that project.

This is especially helpful when setting an existing project up on a new computer, as you don’t need to manually set up Homestead and configure it for your project.

To create a Homestead.yaml for your project, first we need to add Laravel/Homestead development dependency to our project.

To do this cd into your project directory then execute

Once complete we can now use this package to initialize files Homestead will require and create the Homestead.yaml

If you check your directory now you will notice the Homestead.yaml has been created.

We are now almost ready to run our project, all we need to do now is add an entry to our Host file for the website.

Then we add an entry for our new website and save the file

We can now just execute vagrant up and browse to out site http://sourcelink.test

Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me
%d bloggers like this: