Search

How to Install Laravel on MAMP Mac OS X

How to Install Laravel on MAMP Mac OS X
Laravel is a powerful, robost and fast PHP framework used for web development, MAMP is a handy database GUI to allow quick and easy access to database on OS X.  Smash them together and you get quick and easy web development on Mac OS X. I received a tip to try Laravel, a framework for building database-driven sites using PHP. The key features that made me fall in love with the framework  was the Eloquent ORM for managing database models, blade templating and integration with Composer for dependency management. I've been using Mac OS for a couple of years now. So I needed a neat tool for running a web server with PHP and MySQL on OS X. I've been using MAMP for this purpose for a few years now, which provides a full Apache/MySQL/PHP stack. MAMP basically is free but the Pro version gives you a heap of tools for configuring multiple sites. Getting laravel and MAMP to work together, I must confess can most times be a little tricky, primarily due to one of Laravel's strengths, it's integration with Composer. This post is intended as a simple guide for getting a Laravel site up and running on MAMP. These instructions assume you already have MAMP up and running and know how to set up a site.
How to Configure and install Laravel on Mac OS X with MAMP/MAMP PRO
Laravel is an open-source PHP framework, follows the MVC (model–view–controller) pattern. Laravel reduces the time of web development and helps to make web application secure. Some key features make Laravel more powerful for building large and robust web application. Using MAMP is a handy GUI to allow quick and easy testing of websites on OS X. Using them together and you will get quick and easy web development on OS X. In this Laravel tutorial, we will go through installation and configuration process of Laravel 5. Our step by step guide will help to install and configure Laravel framework on Mac using MAMP Server.

Step 1: Install MAMP on Mac OS X

  1. Download the free version MAMP & MAMP PRO file on your system
  2. Click to install it and then follow the instruction to complete installation and use all the default setting.
  3. Test MAMP
You should be able to see the default MAMP/ MAMP RRO page.  

Step 2: Check which version PHP is running

Before starting anything make sure you have quit MAMP and it’s not running. Mac OS X already has a default Apache and PHP version installed which are required to install Laravel. So we need to make sure if PHP needs updating or not, since Laravel 5 needs a minimum of PHP 5.6 upwards. So start by opening the terminal and add the following to make sure Apache is up and running.
sudo /usr/sbin/apachectl start
Then Check the version of PHP
php -v
The first line of the data output should show the php version. If the output is lower than 5.6 then add the following to the terminal, or jump to Step 3.
curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
It will then ask for your password and the installing process will start which may take a while to complete. Once done restart apache via the terminal (You can’t run both versions of this Apache and MAMP’s Apache).
sudo /usr/sbin/apachectl restart

Step 3: Download and Install Composer

Now Laravel uses composer to manage its dependencies. So at first let’s locate the htdocs folder by entering the following in the terminal.
cd /Applications/MAMP/htdocs
Then download and install the composer inside the MAMP htdocs folder by entering the following.
curl -sS http://getcomposer.org/installer | php
or Run the following commands to get the latest Composer version. This 4 lines commands will do the 4 things.
  • Download the installer
  • Verify the installer
  • Run the installer
  • Remove the installer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
To test Composer installation, use the following command:
composer

Step 4: Download and install Laravel

Okay now it’s time to install Laravel. Again still in the terminal input the following.
php composer.phar create-project laravel/laravel --prefer-dist
Or if you want to define a folder name use this instead
php composer.phar create-project laravel/laravel folder-name
Or if you want to define a folder name and the version of Laravel – for this example 5.6.
php composer.phar create-project laravel/laravel folder-name "5.6.*" --prefer-dist
Then, Laravel installation will start, wait for complete  

Step 5: Download and install Laravel Forms and HTML Components

One thing to note when installing Laravel 5.6, that by default it doesn’t install the ‘Forms and HTML components‘. So if you want to do this (which I would suggest you do) then you will need to do the following. Go to the root folder which contains the app folder and resources folder etc. Open the composer.json file and edit the following
"require": {
    "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0"
},
to
"require": {
    "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0"    
        "laravelcollective/html": "5.2.*"
},
Now back in the terminal type the following to get the new Laravel folder installation directory.
cd /Applications/MAMP/htdocs/laravel
Then input this, which will update the version of Laravel with our amended composer.json file.
php /Applications/MAMP/htdocs/composer.phar update
The terminal should show the following output to show its complete.
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing laravelcollective/html (v5.6.1)
    Downloading: 100%         
 
Writing lock file
Generating autoload files
 

Step 6: Start MAMP and preview Laravel

Before running MAMP you will need to stop the other version of Apache so input the following, which will require a password.
sudo /usr/sbin/apachectl stop
So now its okay to start MAMP. In order to run Laravel 5, MAMP needs to be running a minimum version of php 5.6. If you have installed the latest version of MAMP it should have this by default.   But here is how to check which version is running. Open MAMP or MAMP PRO and choose the Preferences tab. Then press the PHP tab and see which checkbox is highlighted. By default is should be set to Version 5.6.23 – this should be okay for Laravel. Enter the following in the browser window which opens. Either http://localhost:8888/your_projet-name/public/ or http://localhost/your_projet-name/public/.   You should now see the default Laravel install page. So as you can see it wasn’t hard… Enjoy.

Step 7: Download and Install Sublime Text

In order to build your first Laravel Application you needed to download and use source code text editor. There are many available of text editors, which are free versions such as Sublime TextNotepad ++NetbeansTextWrangleZend StudioVim and so on. My suggestion for this tutorial is Sublime Text
  1. Download Sublime Text
  2. Click to install it and then follow the instruction to complete installation and use all the default setting.
To open or edit the application you previously created in Sublime Text, Go to File and select Open – Application/MAMP/htdocs/your-project-name: You should now see the default Laravel installed files. So as you can see it is well organised … Happy coding.

Leave a comment

0 Comments