0%

Install Laravel 5 on OS X

If you’re like me, you’ve probably spent countless hours on the web trying to figure out how to install the dev-develop version of Laravel on your machine. As of today, the latest Laravel version 4.2 but if you want to see the awesome Laravel 5 features, you need to upgrade.

In this article, you will learn how to setup Laravel 5 from scratch on OS X.

Requirements

Here are some things you must have:

  • A Terminal
  • XAMPP / MAMP (I will show you how to set it up using both of them)

That’s pretty much it. Let’s get started.

Step 1: Installing Composer

According to their website,

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.

In short, it is awesome.

Composer allows you to scaffold out a Laravel project and you also have the flexibility of specifying which version of Laravel your want.

To install composer, run the following commands in the terminal:

1
2
3
curl -sS https://getcomposer.org/installer | php
sudo mkdir -p /usr/local/bin/
sudo mv composer.phar /usr/local/bin/composer

This will install Composer globally for you. To verify that your composer installation is successful, try running:

1
composer

…and you’ll see a bunch of composer commands flow down your terminal screen. Hurray!

You can also update composer by running:

1
composer self-update

For more information, check out the in-depth guide on their website for Getting Started with Composer.

Step 2: Configuring XAMPP/MAMP

So you’ve installed either XAMPP or MAMP on your machine. Great.

When installing Laravel for the first time, more than 90% of the people face this dreaded PHP error:

MCrypt PHP extension not installed.

…and then they spend countless hours on the internet trying to figure out how to solve this and most of them will tell you to install MAMP. But what if you have XAMPP installed?

It’s pretty simple.

For XAMPP users

Home page : https://www.apachefriends.org/download.html

I’m using XAMPP 1.8.3–2 on my Mac and it comes with the MCrypt extension out of the box. All you need is to include it’s path in your .bash_profile

Open your .bash_profile by running:

1
vim ~/.bash_profile

…and paste the following line at the end:

1
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"

Save the file by pressing : and typing wq and then press enter to quit out.

Remember to reload the .bash_profile by running:

1
source ~/.bash_profile

And you’re done!

For MAMP users

Home page : https://www.mamp.info/en/downloads/

The procedure is pretty much the same. You start out by opening your .bash_profile and pasting the following line at the end:

1
export PATH=/Applications/MAMP/bin/php/php5.6/bin:$PATH

Important note: This assumes that you have PHP 5.6 installed on your machine.

Remember to reload the .bash_profile by running:

1
source ~/.bash_profile

And you’re done!

Step 3: Installing Laravel 5

To create a new Laravel 5 project, run the following:

1
composer create-project laravel/laravel dev-develop

This will pull in the latest dev branch from the Github repo. If you want the latest stable version, run the following:

1
composer create-project laravel/laravel --prefer-dist

If everything goes well, try running:

1
php artisan -V

and if it says:

1
Laravel Framework version 5.0-dev

then you’re good to go!

To see your new shiny Laravel installation in action visit the public directory in the project to see the awesome new Laravel 5 home page.

Step 4: Installing Laravel Homestead

If you have XAMPP/MAMP installed, you can actually browse to your project’s public directory to see the app in action.

To be honest, I’ve moved on from software like XAMPP and MAMP. They are good if you are just getting started, but for you to get better at deploying apps via the command line and really understand how things work, you need to let it go.

According to their website:

Laravel Homestead is an official, pre-packaged Vagrant “box” that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine.

In other words, Laravel Homestead provides a complete environment for your Laravel project. It’s like having your own Rackspace or Digital Ocean server.

It uses Vagrant which allows you to create lightweight, reproducible, and portable development environments locally.

Before installing Laravel Homestead, you need to install 2 things:

For more information on Vagrant, check out their website.

Once you have installed Vagrant on your machine, it is time to install Homestead.

To install Laravel Homestead, run the following:

1
vagrant box add laravel/homestead

It might take some time to install depending on your internet connection.

What it is essentially doing is installing a copy of the latest Ubuntu version with a complete LAMP stack setup so you have your own server that you can SSH into.

In fact, the files on your local machine are synced with the VM so essentially, if you make any change on your local machine, it is synced back to the VM. Note that everything is happening locally.

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

You can do that by running:

1
homestead init

By default, this will create a Homestead.yaml file in your root directory.

1
~/.homestead/Homestead.yaml

Open up the file and let’s discuss what’s relevant:

1
authorize: ~/.ssh/id_rsa.pub

You need to setup an SSH key on your machine that will allow you to SSH into your VM.

For more information on setting up SSH keys, Github has an awesome article.

1
2
3
folders:
 — map: ~/path/to/project
to: /home/vagrant/project-name

The above code maps the project on your machine to the project on the VM. For example, if your project directory is:

1
~/Documents/LaravelProjects/laravel-test

It’s going to map to the following in the VM:

1
/home/vagrant/laravel-test

Let’s look at the most important part:

1
2
3
sites:
— map: project.app
to: /home/vagrant/project-name/public

The above code provides you with a handy alias to enter in the browser that points to your project’s public directory which is how Laravel serves your app.

For example, you can enter something like:

1
http://personal.app

…and see your Laravel project. You can also use the following:

1
http://localhost:8000

Okay, so we are ready to start Homestead. To do that, run the following:

1
homestead up

It will spit out a bunch of commands in your terminal. Once it’s done, you can SSH into your shiny new server by:

1
homestead ssh

…and if everything is setup correctly, you’ll see the following prompt:

1
vagrant@homestead:~/project-name

Step 6: Done

Phew. That was a lot.

Congratulations though! You just set up a new Laravel 5 project from scratch.

Build something awesome! ☺

Here is a puppy pile to make your day better. Why? Cuz.

via. https://medium.com/@kunalnagar/install-laravel-5-on-os-x-23f3578386f1