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

There is an alternate method to 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. This directory exists in different locations based on your operating system;

It does not clearly explain what this means or provides sufficient detail on how to do this. In order to achieve this we need to put this folder on the PATH environment variable type, just copy and paste the following commands into your terminal window

If you want it to be automatically set For bash you can append this line to $HOME/.bashrc using your favourite editor or type the following on the shell

Once complete ensure your refresh the source by executing

Once you have completed the steps above we can now create a new project.

We can create a new notepad project by 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 wil 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.

Installing Homestead

Install Homestead by cloning the GIthub repository.

Clone the repository into a Homestead folder within your $HOME directory, as the Homestead box will serve as the host to all of your Laravel projects.

Check out a stable tagged version of Homestead. You can find the latest stable version on the Homestead GitHub Release Page

We can now run the Initialization script, which will create the homestead.yaml configuration file, which will be located in ~/Homestead

Configuring Homestead

Open your homestead.yaml in which ever text editor you prefer.

Setting the Provider

The provider key in your Homestead.yaml file indicates which Vagrant provider should be used:

  • virtualbox
  • vmware_fusion
  • vmware_workstation
  • parallels
  • hyperv
  • .

    set this to the provider you’re using. In my case it’s virtualbox:

    Configure shared folders

    The folders property of the Homestead.yaml file lists all of the folders you wish to share with your Homestead environment.

    When Files within these folders are changed, Edited etc. they will be kept in sync between your local machine and the Homestead environment.

    A sort of convention among Laravel developers is to create a folder name code in your $HOME folder where you’ll store your projects.

    Create a project using laravel new sourcelink using what ever name you want to call your project.

    Once the project has been created you can now edit your homestead.yaml file

    You can create as many projects as you like, but you have to remember to edit your homestead.yaml to add your new project mapping.

    You should map every project to its own vagrant folder.

    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

    Latest posts by Gary Woodfine (see all)

π
%d bloggers like this: