TECH

Vol.55

author

Engineer

Y.M.

Important Points to Keep in Mind When Installing the Popular Framework Laravel on Mac

#WEB#webサイト#開発#HTML
Frameworks are often used for website and application development. This time, we will focus on the PHP framework Laravel and go through the process of installing it on a Mac. From preparation to completion, we’ll explain the steps required for installation on macOS.
stuffstuff

What Is Laravel?

Laravel is a type of open-source PHP framework.
Its popularity has grown rapidly in recent years, and alongside well-known frameworks such as CakePHP and Symfony, it is even expected that Laravel may surpass them in market share and become a global standard in the future.

Before Installing Laravel

We will install Laravel on a Mac in order to set up a test environment.
We will use the macOS package manager called “Homebrew,” but in some cases, issues can occur with Homebrew after upgrading from Mac OS X Mavericks 10.9.5 or earlier to Yosemite.
Unfortunately, this was exactly the situation I encountered.
First, I needed to get Homebrew working properly. My Mac environment was as follows.

Environment Setup

OS Version: Mac OSX 10.11.6 El Capitan
Device: Mac Pro (Mid 2012)
*Updated sequentially starting from Mountain Lion.

Repairing Homebrew

Error 1

First, try running the brew command.

$ brew update

After running the command, the following error appears.

 

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

An error is occurring with the Ruby link. To fix this, edit the following file.

$ vi /usr/local/Library/brew.rb

You can edit the file using the vi editor or the standard macOS TextEdit application.
If using the vi editor, modify the first line shown below.

#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0

Change it to the following.

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0

Error 2

Next, when running the brew command, the following error appears.

Homebrew requires Leopard or higher. For Tiger support, see:
https://github.com/mistydemeo/tigerbrew

To resolve this error, run the following commands.

$ git fetch origin master:refs/remotes/origin/master -n
$ git checkout origin/master -- Library/brew.rb

These commands fetch the latest information from the remote Git repository and check it out.
*Git must already be installed on your Mac.

Error 3

The next error is related to file permissions.

/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Permission denied
/usr/local/bin/brew: line 21: exec: /usr/local/Library/brew.rb: cannot execute: Undefined error: 0

Run the following command to change the file permissions.

$ chmod 754 /usr/local/Library/brew.rb

Error 4

This is the final error.

/usr/local/Library/brew.rb: line 1: syntax error near unexpected token '('
/usr/local/Library/brew.rb: line 1: `std_trap = trap("INT") { exit! 130 } # no backtrace thanks'

To resolve this error, use Git commands once again.
The following command forcefully synchronizes the contents of the local repository with the remote repository.

$ git reset --hard origin/master

This clears all of the errors.

Preparing to Install Laravel

Installing Composer

Next, we will prepare for the Laravel installation.
First, install the PHP package management tool.

The installation method below is primarily based on the following website.
This article focuses on the key points for installing in a MAMP environment, but if you would like a more comprehensive guide, please also refer to the following site.
[PHP] Installing Laravel 5 on a Local Server in OS X (Mac)

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Next, add the path.

$ vi .bash_profile

# Add the following line and save
export PATH=$PATH:/usr/local/bin

$ source ~/.bash_profile
$ composer -V
Composer version 1.2.0 2016-07-19 01:28:52

If the version information is displayed, the installation is complete.

Installing Laravel

Now, install Laravel. This guide assumes you are using MAMP.
MAMP

First, add the MAMP PHP executable to your path so that you can use the PHP version included with MAMP.
The PHP version should be adjusted depending on your installed MAMP version and the PHP version you want to use.

$ vi ~/.bash_profile
# Add the following line and save
export PATH=$PATH:/Applications/MAMP/bin/php/php7.0.10/bin

$ source ~/.bash_profile

Next, install the latest Laravel project.
In this environment, the MAMP document root is used as the installation location.

$ cd /Applications/MAMP/htdocs
$ composer create-project laravel/laravel project-name --prefer-dist

Set the MAMP document root to “htdocs,” then access the following URL:
http://localhost:8888/project-name/public
You should see a start page like the one shown below.

Image after completing all steps

This completes the installation.

Summary

In this case, tuning the Mac environment took more time than installing Laravel itself.
Although there are many reference websites explaining how to repair Homebrew, I could not find one that covered the complete set of steps needed for my particular environment, which is why I decided to write this article.
Not only when installing Laravel, but whenever using Homebrew, repairs like the ones described here may become necessary, so I hope this TIP will be helpful.

Reference: Repairing the Ruby Path in Homebrew

Reference: Repairing Git in Homebrew

Reference: Fixing Homebrew Errors After Upgrading to Yosemite

Reference: Installing Laravel

PREV
Vol.54Create 3D Printer Data with Phot…
NEXT
Vol.56Getting Started with Color Gradi…

MORE FOR YOU