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.
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.
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.
Then, visiting http://saas:8888 will show you Laravel’s beautiful welcome screen.
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
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.
SQLSTATE[HY000]  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
Then we can edit our
~/.bash_profile file, by adding the following line:
Restart terminal, and you should then be able to run the
php artisan command.
And that’s it. Create something awesome!