Installing CakePHP 3 on MAMP 5 on Mac OSX Mojave

I spent WAY too much time trying to figure this out. I’m a fairly new Mac user, so some of this was just my own lack of understanding the Mac. I Google’d this for a long time, and wanted to throw together this post for my own reference and maybe it’ll help someone else.

Install MAMP 5

Head over to https://www.mamp.info/en/ and download MAMP. It is a combo install, it has the free version and the pro version in one. That’s okay. I used the free version.

What is MAMP? It’s a fast way to get PHP installed and running on your machine. It includes PHP, Apache and Nginx server, and MySQL.

Install is super easy, download and install it. Then open it up:

MAMP app screen

Press Start Servers and wait for it to turn on. It should open a new browser window running on localhost:

MAMP welcome screen

YAY! You have PHP, Apache and mySQL installed! Pretty easy right?

Confirm it’s running

I have found that confirming steps as we go is best. So, go back to the MAMP app, go to MAMP menu, then Preferences. Go to Web Server. Click Show in finder for the Document Root path. This will open the folder for the web server, located in the MAMP application folder. From here, let’s add an index.php file with the following code:

<?php
phpinfo();
?>

Hop back into the browser, to the Welcome to MAMP site, and click My Website in the top nav. When I do this, I get the following, which is not cool:

site can't be reached mamp my website

If you don’t, good for you. I think this might be some of my “not knowing Mac well enough”. But this is easy, I change the URL from https://localhost to http://localhost:8888/index.php (note it’s not https), then it works:

PHP info

Configure PHP on Mac to use MAMP

Continuing in the trend of “not knowing Mac well enough”, it appears Mac OSX Mojave comes with PHP, but a slightly different configured version. If you tried to install CakePHP right now, you’d get a headache, which is what I cried over for a while. The PHP that comes with Mac doesn’t have the necessary extensions installed. It may be possible to install it all, I trust it is, but this was much easier and faster.

Here’s how we avoid some pain. I came across this lovely blog post which helped. In Terminal, go to your home directory, then edit .bash_profile and add the following line:

export PATH=/Applications/MAMP/bin/php/php7.3.7/bin:$PATH

This will set the php command to be set to MAMP’s PHP instead of the PHP that came with Mac. After you update the file, enter:

source ~/.bash_profile

This will refresh your terminal windows to use this new profile. Then then type the following to confirm the path:

which php

Install CakePHP 3

Installation from here is rather easy, following https://book.cakephp.org/3.0/en/installation.html#installing-composer

But first, Composer

CakePHP uses composer for installation, so we’ll need to install composer first. CakePHP links you to https://getcomposer.org/download/. Hit up this page and you’ll see the following, do it.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

When I ran it, I had to add sudo to the start of each line. I find I have to do that a lot, I suspect I’m missing something on my Mac.

After you run the above, CakePHP points out there is one more command to run:

mv composer.phar /usr/local/bin/composer

Install CakePHP, for real

Now we can install CakePHP into our project, following https://book.cakephp.org/3.0/en/installation.html#create-a-cakephp-project

Head to the folder where you’d like to setup your project, I use username/git. Run the following:

composer create-project --prefer-dist cakephp/app my_app_name

Note, change my_app_name to you project’s name. This will create a subfolder in the folder you’re in.

cakephp installation

Configure MAMP to use CakePHP

Finally, we have to tell MAMP to use the folder you just installed CakePHP into. Super simple, hop back into the MAMP app, click MAMP menu, then Preferences. Go to Web Server, then click Select for the Document Root. Select the folder you just created. Click OK and the web server should restart itself.

Remember, the My Website link on the MAMP home page won’t load it correctly, instead go to http://localhost:8888/index.php.

Viola! CakePHP 3 on MAMP 5 on Mac OSX Mojave

CakePHP installed on MAMP on Mac OSX Mojave

One thought on “Installing CakePHP 3 on MAMP 5 on Mac OSX Mojave

Add yours

Leave a Reply

Up ↑

%d bloggers like this: