Installing and configuring Laravel

The latest up-to-date instructions to install Laravel can always be found at the Laravel website, http://laravel.com. To begin using Laravel in a development environment, the current best practices suggest using the following:

  • Vagrant: This provides a convenient way to manage a virtual machine, such as Virtualbox.
  • PuPHPet: This is an excellent tool that can be used to create a virtual machine of various types. For more information about PuPHPet, visit https://puphpet.com.
  • Phansible: This is an alternative to PuPHPet. For information about Phansible, visit http://phansible.com.
  • Homestead: This is maintained by the Laravel community, and is a virtual machine that is created specifically for Laravel and which uses NGINX instead of Apache. For more information about Homestead, visit https://github.com/laravel/homestead.

Installation

The basic process involves downloading and installing Composer and then adding Laravel as a dependency. An important detail is that the storage directory, which is located parallel to the /app directory, needs to be set in such a way that it is writable by the web server user in order to allow Laravel 5 to do things like writing the log files. It is also important to make sure that $ php artisan key:generate is used to generate a 32-character key that is used for hashing because, since the release of PHP 5.6, Mcrypt is more strict as regards its requirements. For Laravel 5.1, OpenSSL will replace Mcrypt.

Configuration

In Laravel 4, the environments were configured in a manner that relied on the hostname of the server or a development machine, and this was rather contrived. Laravel 5 instead uses a .env file that sets up the various environments. This file is included in .gitignore. Thus, each machine should receive its configuration from a source outside the source code control.

So for example, something like the following code can be used to set up a local development:

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=localhost
DB_DATABASE=example
DB_USERNAME=DBUser
DB_PASSWORD=DBPass
CACHE_DRIVER=file
SESSION_DRIVER=file

Namespacing

A nice new feature of Laravel is that it allows you to set the highest level namespace to something such as MyCompany through the app:name command. This command will actually change the namespace of all the relevant files inside the /app directory from App to MyCompany, for example. This namespace then lives inside the /app directory. This builds namespacing right into virtually every file whereas previously, in version 4.x, it was optional.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset