Installing Laravel on a Mac — a newbie’s insights

I am new to using a Mac, so forgive me if you spot something I should have known better.

Also, I’m a Laravel newbie, so don’t take what I say seriously

I just managed to get Laravel up and running because I’ll need to know how to work with it for my next project.

While I have heard good things about the framework, the ease of use, etc, I am yet to see what the fuss is all about. Setting up wasn’t entirely easy and I had to reach out to the PHP community on DevCenter for help in the process.

Shout out to ibrahimlawal and @acekyd for the assistance.

It started with PHP …

Laravel wasn’t so difficult to install. I had to learn about composer which is like the NPM for PHP.

For some reason, Mac OS installations come bundled with PHP (and ruby, so I saw), which is well … still don’t know what to make of that. In my case, it was PHP 5.6.0

I decided to use HomeBrew to install PHP 7.0 which Laravel 5.5 runs on and it wasn’t so bad. It was a bunch of commands which:

  • Updated HomeBrew (always update, ehn?)
  • Attempted to unlink PHP 5.6 which didn’t work because it was not installed with HomeBrew
  • Installed PHP 7.0

Now, there was a problem. I had both PHP 7.0 and PHP 5.6 installed on my system, because the brew unlink php56 command didn’t work.

php artisan serve in my newly created laravel app kept giving

Parse error: parse error in ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 233

The errant line of code:

return app(‘cache’)->get($arguments[0], $arguments[1] ?? null);

Took a while to figure out what was going on … Apparently, ?? is a new operator that was introduced to PHP 7.0. It’s called the null coalesce operator and we’ve had it in C# for years. Lol!

Figured out that php —- version was returning 5.6 because the PATH was still pointing to the php56 installation.

Unfortunately, either Mac OS does not have the flair of windows and provide you with a sweet GUI for editing environment variables, or I just still don’t know how to use it well enough.

So with the help of sudo nano /etc/paths, and some fiddling with the directory to figure where brew saved the php70 installation, I was able to add /usr/local/cellar/php70/7.0.24_16 to my PATH.

Now, php --version returns 7.0 which is awesome!

php artisan serve now actually serves my app. Yaaay!(?)

But I get a Whoops! Something has gone wrong!

What’s up again?

Apparently, there’s no .env file.

Where is that supposed to come from?

I was supposed to copy the generated .env.example file to .env and enter a value for the APP_KEY which is supposed to be a base64 string.

How was I supposed to know that?

The laravel new command was supposed to have handled that, but it didn’t, I think.

So, I do run the:

php artisan key:generate #to generate a new APP_KEY
php artisan config:clear #just in case the empty key is in cache

Then I run php artisan serve and finally, it’s up.


We have joined the guild of PHP devs!!!

Again, all I see is the Laravel homepage, which I must say is a little disappointing. There’s a whole lot of generated PHP for it to just say:

The “Hello World” of Laravel

I mean, where’s all the power of Laravel at? Show me something cool! Authentication, Cool Routing features, etc.

I know I am a newbie at this, and it’ll get cooler soon, at least I hope it does. But till then, I’ll be working on figuring out how Laravel is put together.

Bye, I have work to do.

Update: for php artisan to work, you need to run composer update — no-scripts first.

Like what you read? Give Ikechi Michael a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.