Book Image

Laravel 5.x Cookbook

By : Terry Matula, Alfred Nutile
Book Image

Laravel 5.x Cookbook

By: Terry Matula, Alfred Nutile

Overview of this book

Laravel is a prominent member of a new generation of web frameworks. It is one of the most popular PHP frameworks and is also free and an open source. Laravel 5 is a substantial upgrade with a lot of new toys, at the same time retaining the features that made Laravel wildly successful. It comes with plenty of architectural as well as design-based changes. The book is a blend of numerous recipes that will give you all the necessary tips you need to build an application. It starts with basic installation and configuration tasks and will get you up-and-running in no time. You will learn to create and customize your PHP app and tweak and re-design your existing apps for better performance. You will learn to implement practical recipes to utilize Laravel’s modular structure, the latest method injection, route caching, and interfacing techniques to create responsive modern-day PHP apps that stand on their own against other apps. Efficient testing and deploying techniques will make you more confident with your Laravel skills as you move ahead with this book. Towards the end of the book, you will understand a number of add-ons and new features essential to finalize your application to make it ready for subscriptions. You will be empowered to get your application out to the world.
Table of Contents (17 chapters)
Laravel 5.x Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Setting composer and PHP on your local machine for faster Workflows


In this section, we will cover some tips on using PHP and composer outside of the Homestead box to help with your workflow.

Getting ready

As with the preceding sections, you will need to have a terminal and decent internet. I will cover this using a Mac, but Windows and Linux have their systems to install the software. By default, you can install Xcode on a Mac and get pretty far with PHP, but it tends to be an older version of PHP. Here, we will use Homebrew to install PHP 5.6. We will also use Homebrew later on in this book as well.

How to do it...

  1. Visit the http://brew.sh/ site, and run the command they show there to install Homebrew on your Mac.

  2. Follow the instructions at https://github.com/Homebrew/homebrew-php to get the PHP5.6 setup.

  3. After you are done with step 2, add to your ~/.bash_profile so that we can use this version of PHP:

    export PATH="$(brew --prefix php56)/bin:$PATH"
    
  4. Then, update your current session:

    >source ~/.bash_profile
    
  5. Then, we will make sure our PHP is set up properly:

    >which php
    

    You will see the/usr/local/opt/php56/bin/php output and type:

    >php –v 
    

    This will show that you are running 5.6.19 or a higher version.

  6. Set up mycrypt as follows:

    >brew install php56-mcrypt
    
  7. Then, we will install composer as seen at https://getcomposer.org/download/:

    >php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
    >php -r "if (hash('SHA384', file_get_contents('composer-setup.php')) === 
    
    625196afcca95a5abf44391188c695c6c1456e16154c75a211d238cc3bc5cb47') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    >php composer-setup.php
    >php -r "unlink('composer-setup.php');"
    >sudo mv composer.phar /usr/local/composer
    

Tip

What is ~/? That is shorthand for your Home directory. When I use this, for example, >source ~/.bash_profile, your operating system will know it is in your home folder, for example, /Users/alfrednutile/.bash_profile.

How it works...

That was a lot of steps! Let's cover what we did and why. We began by installing Homebrew to make installing packages easier. We will periodically need to install packages such as Wget, Webdriver, and more as we progress through this book. Using the brew command supplied by Homebrew makes installing these packages a snap.

Then, we used Brew to make sure we have a current version of PHP on our Mac. But considering we already have Homestead, why do this? There is some work you do outside of Homestead, for example, getting and installing Laravel using composer, running envoy, and more. And some of these you can run in Homestead, but you will see some speed difference outside of it. So, you still need it on your machine, but in this case, we are not so worried about it being the wrong version for one of our many applications.

The mcrypt part of the installation took care of the extension that we need to run common commands such as php artisan key:generate and other commands in Laravel.

We finalized the PHP setup with Bash shortcuts, so when we open the terminal, we are ready to use PHP and not the version that comes with Xcode on Mac.

We then use PHP to download and install composer, the biggest advancement in PHP since I started 15 years ago in my opinion, and you will see more of composer shortly.

Finally, we are ready to download Laravel!

There's more...

You could, of course, use Brew to install MySQL and more. But for now, we are going to leave all of this inside the Homestead box that we set up earlier.

See also