Installing Laravel 5.1 on OSX with MAMP

1) Install Composer #

If you don’t yet have composer installed, you will need to do that. You can test weather you have composer installed by simply typing in the composer command into mac’s terminal. You should see a list of available commands if composer is installed.

Screen Shot 2015-08-17 at 1.34.05 PM.png

If you don’t yet have composer installed, you can see Getting Started with Composer

2) Install Laravel #

Laravel has good documentation in installing Laravel. I’ll walk through exactly what steps I took to get Laravel up and running on OSX Yosemite.

Install via Laravel Installer. Type the following into terminal.

cd ~/
composer global require "laravel/installer=~1.1"

Add the composer executable to the Path environment, so to that the laravel executable can be found.

PATH=$PATH:~/.composer/vendor/bin

Install a fresh Laravel instance, and give it a name. In our case we’ll name the project saas.

laravel new saas

I’m using MAMP PRO to run sites locally on my mac. So I just need to create a new host in MAMP, and point it to the saas/public directory.

laravel_mamp.png

Then, visiting http://saas:8888 will show you Laravel’s beautiful welcome screen.

laravel5_1.png

3) Create Database #

I like to use Navicat to manage my databases. With Navicat for MySQL, I create a new local database.

Then, define it’s connection in the .env file.

 DB_HOST=localhost
 DB_DATABASE=saas
 DB_USERNAME=root
 DB_PASSWORD=xxxxxxx

The trigger the migration with the following command:

php artisan migrate

Since I’m using MAMP, I got this error when trying to migrate.

[PDOException]                                    

SQLSTATE[HY000] [2002] No such file or directory

Solution was to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
        'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
    ],

4) Wrap-UP #

Directories within the storage and the bootstrap/cache directories should be writable. We’ll do that with the following?

chmod -R 777 storage
chmod -R 777 bootstrap/cache

Rename the environment file.

mv .env.example .env

5) PHP Path #

Since were using MAMP, we have multiple version of PHP installed on our machine. So if we try to run php artisan, we will be given an error.

Mcrypt PHP extension required

If you also receive that error, first check to see what version of PHP your using with MAMP. You can check that through MAMP’s Main Window > PHP. In my case, were using version 5.6.10.

Then we can edit our ~/.bash_profile file, by adding the following line:

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

Restart terminal, and you should then be able to run the php artisan command.

And that’s it. Create something awesome!

 
6
Kudos
 
6
Kudos

Now read this

OOP Basics

I’ve been a self-taught “developer” for 8 years now, and I realized that I still don’t have a very good grasp of OOP. I find myself just floundering around OOP frameworks, trying different things until something works. Probably not the... Continue →