Shares

I come from the world of CodeIgniter, the ailing framework who was once the Zeus of the PHP framework arena. I have written around 20,000 lines of code in CodeIgniter, and developed a marketplace platform back in 2012.

CodeIgniter was love at first sight, but with its slow development pace, Laravel is the natural choice for many. CodeIgniter has hope, but there is no harm trying out Laravel, with its great feature set.

Today, I am going to help you setup Laravel 4 on OS X 10.9 on Mavericks. You should get up and running in no time. It takes a few commands, trust me. Without further ado, let’s get started.

Getting PHP 5.5.11 

Please  go to your terminal and type the following command. If it says PHP 5.4, it is time to update your PHP. If it says 5.5, you are good to go. If you do have an older version of PHP, don’t fall in the trap of downloading and installing PHP using Homebrew. I’ll tell you an easier way. Read on.

 php -v 

XAMPP for Mavericks

We will simply ignore using Homebrew and just install XAMPP for Mac. This is because if I had told you to use Homebrew to install PHP 5.5.12 for instance, then you would have had errors later on as the Laravel setup would have said “error, I need Mcrypt“.

Luckily, the PHP 5.5.11 that comes with XAMPP has everything you need, so this a) saves time and b) makes you happier.  To download XAMPP 1.8.3, click here.

Once you have downloaded XAMPP 1.8.3, follow the installation steps. Proceed to the next step.

Changing Default PHP for OS X

Mavericks comes with PHP 5.3 or maybe 5.4, but since we need to upgrade, it is time to do so using bash_profile. In the next few steps, you will be able to change your Default PHP version from 5.3/5.4 to 5.5.11 to be precise. First, open up the terminal and put the following sequence of commands. At first, we create a new hidden file in the root directory called bash_profile.

 nano ~/ .bash_profile 

The nano command creates and opens it in one instance – it will be blank, of course. Now, we must ask OS X to use the PHP that was installed with the XAMPP, not the default one. To achieve this change in the configuration, you must put in the following lines of code and save the file. Save by pressing Ctrl+X and then by pressing Y and ENTER.

# Swapping from PHP 5.4 to PHP 5.5
export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH

Now, once you have saved the file, do check if it is there again by doing:

 source ~/.bash_profile
cd ~/
ls -la

You should now scroll up and see that you do have a file named .bash_profile. Open it to check it’s contents as you saved. All done? Great. You have sucessfully installed PHP 5.5.11 and configured Mavericks to use that as its default PHP version. Now, for a final check, do:

 php -v 

The result should clearly say this:

PHP 5.5.11 (cli) (built: Apr  9 2014 07:49:22)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

Now, it’s time to install Laravel 4. The beauty of this process is that it is all done via Command Line.

Installing Laravel 4 on Mavericks 

To install Laravel, you must follow the processes in order. At first, we will install Composer, a Dependency Manager for PHP. This allows you to install modules (or gems if you’re from the Ruby world) using the command line. The Composer is like NPM (Node.js world anyone?) for PHP. It’s a sweet little tool that makes your life way easier. It automates things like downloading and installation of dependencies so you can focus on the actual thing, developing your app.We will now use Homebrew to setup Composer on your machine. Homebrew is a world class package manager for Mac. Download Homebrew if you don’t have already.

And trust me, you will never regret this decision. It makes your life so easier. Installing things like Hadoop with a single command line of just 3 words? Isn’t that cool. I know. It’s not cool, it’s freaking magic. Get that bad boy if you don’t have it already. Once you’ve Homebrew, just enter these commands one by one. So, line 1, press enter, let it do its thing, then line 2, press enter, let it do its thing and so on. You get the deal. Be sure to copy these directly from here as you might make an error by typing in a hurry.

brew update
brew tap josegonzalez/homebrew-php
brew tap homebrew/versions
brew install php55-intl
brew install josegonzalez/php/composer

Boom baby, you have just installed Composer on your Mavericks machine. Great, you did a great job being patient and hopefully didn’t get any errors. If you did, just comment below and Mr. Geek is always here to help, as usual.

Creating a new Laravel 4 application

My my, you’ve got this far. Look at you. Well done. Now, it’s time to put Composer to work for you. We will be using the following command create a new Laravel application folder with everything you need to get up and running. The folder laravel-app will be created in the folder or directory you are in currently. In about 2 minutes, you should see the image below.

composer create-project laravel/laravel laravel-app

If you can see the following two lines in the end of the process, congratulations. You have successfully got your Laravel 4 app activated.

Testing Laravel 4

Now, cd into your application directory i.e. laravel-app. Then do ls to see the contents of the folder. It should have this:

Awesome, now it’s time to actually use PHP 5.5.11 built-in web server to serve webpages. We use the artisan command serve.

php artisan serve

Awesome, you should have something like this showing up on localhost:8000. Press Ctrl+C to stop serving at anytime.

What’s next? Nothing. You did it. You just installed Laravel 4 with minimal fuss in just under 5 minutes. Thanks for reading. Let me know if the process went well. If it didn’t, then do comment below. We are here to help. Checking out, bye!

About Ali Gajani

Hi. I am Ali Gajani. I started Mr. Geek in early 2012 as a result of my growing enthusiasm and passion for technology. I love sharing my knowledge and helping out the community by creating useful, engaging and compelling content. If you want to write for Mr. Geek, just PM me on my Facebook profile.