Traduction proposée par creasitenet le 03-07-16

Installation


Installation

Configurations serveur requises

Laravel nécessite certaines configurations serveurs spécifiques. Configurations que la machine virtuelle préconfigurée Laravel Homestead propose:

  • PHP >= 5.5.9
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension


Installer Laravel

Laravel utilise Composer afin de gérer ses dépendences. Il est donc nécessaire d'avoir Composer d'installer sur votre machine.

Via l'installeur Laravel

Téléchargez et installer Laravel via Composer :

composer global require "laravel/installer=~1.1"

Assurez-vous d'ajouter le répertoire  ~/.composer/vendor/bin à votre PATH pour permettre à votre système de localiser l'éxecutable laravel.

Une fois installé, la commande laravel new va créer automatiquement un nouveau projet Laravel dans le répertoire spécifié. Par exemple, laravel new blog va créer un répertoire nommé blog contenant votre nouveau projet incluant l'ensemble des dépendances nécessaire au framework déjà pré-installées. Cette méthode est plus rapide que la simple installation par Composer:

laravel new blog

Via Composer Create-Project

Une deuxième méthode utilisant simplement composer vous permet de faire le même travail:

composer create-project laravel/laravel --prefer-dist


Configuration


Configuration de base

Les fichiers de configurations du framework Laravel sont tous situés dans le répertoire config . Chacun d'entre eux étant documentés, n'hésitez pas à y jeter un oeil pour vous donnez une idée de ce qu'il vous est possible de configurer.

Permissions

Après l'installation, il vous sera peut-être nécessaire de configurer certaines permissions. Les répertoires tels que  storage ou bootstrap/cache doivent être ouvert un mode écriture pour votre serveur. En utilisant l'environnement Homestead , ces permissions sont déjà configurées.

Application Key

Prochaine chose importante à faire après une installation est de configurer la clé de l'application. En installant les bases de son projet via Composer ou l'installeur Laravel, cette clé a déjà été générer pour vous grâce à la commande suivante : key:generate . Cette clé doit être représentée par une chaîne de 32 caractères et présente dans le fichier d'environnement.env . Si vous n'avez pas encore renommer .env.example en .env, vous devriez désormais le faire. Si la clé d'application n'est pas configurée, les sessions utilisateur et autres données encryptées ne seront pas sécurisée !

Configuration supplémentaires

Laravel n'a besoin que de ces configurations "out of the box". Vous pouvez donc d'ores et déjà commencer le développement ! Cependant, certaines options du fichier config/app.php peuvent encore être modifiées comme timezone et locale . N'hésitez donc surtout pas à regarder la documentation associée à ce fichier.

Certains autres composants vous seront peut-être utiles lors de votre développement comme les suivants :

Une fois installé, vous devriez également configurer votre environnement local.


Pretty URLs

Apache

The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.

If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Nginx

On Nginx, the following directive in your site configuration will allow "pretty" URLs:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

Of course, when using Homestead, pretty URLs will be configured automatically.


Environment Configuration

It is often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver locally than you do on your production server. It's easy using environment based configuration.

To make this a cinch, Laravel utilizes the DotEnv PHP library by Vance Lucas. In a fresh Laravel installation, the root directory of your application will contain a .env.example file. If you install Laravel via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually.

All of the variables listed in this file will be loaded into the $_ENV PHP super-global when your application receives a request. You may use the env helper to retrieve values from these variables. In fact, if you review the Laravel configuration files, you will notice several of the options already using this helper!

Feel free to modify your environment variables as needed for your own local server, as well as your production environment. However, your .env file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration.

If you are developing with a team, you may wish to continue including a .env.example file with your application. By putting place-holder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application.

Accessing The Current Application Environment

The current application environment is determined via the APP_ENV variable from your .env file. You may access this value via the environment method on the App facade:

$environment = App::environment();

You may also pass arguments to the environment method to check if the environment matches a given value. You may even pass multiple values if necessary:

if (App::environment('local')) {
    // The environment is local
}

if (App::environment('local', 'staging')) {
    // The environment is either local OR staging...
}

An application instance may also be accessed via the app helper method:

$environment = app()->environment();


Configuration Caching

To give your application a speed boost, you should cache all of your configuration files into a single file using the config:cache Artisan command. This will combine all of the configuration options for your application into a single file which can be loaded quickly by the framework.

You should typically run the php artisan config:cache command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.


Accessing Configuration Values

You may easily access your configuration values using the global config helper function. The configuration values may be accessed using "dot" syntax, which includes the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exist:

$value = config('app.timezone');

To set configuration values at runtime, pass an array to the config helper:

config(['app.timezone' => 'America/Chicago']);


Naming Your Application

After installing Laravel, you may wish to "name" your application. By default, the app directory is namespaced under App, and autoloaded by Composer using the PSR-4 autoloading standard. However, you may change the namespace to match the name of your application, which you can easily do via the app:name Artisan command.

For example, if your application is named "Horsefly", you could run the following command from the root of your installation:

php artisan app:name Horsefly

Renaming your application is entirely optional, and you are free to keep the App namespace if you wish.


Maintenance Mode

When your application is in maintenance mode, a custom view will be displayed for all requests into your application. This makes it easy to "disable" your application while it is updating or when you are performing maintenance. A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, an HttpException will be thrown with a status code of 503.

To enable maintenance mode, simply execute the down Artisan command:

php artisan down

To disable maintenance mode, use the up command:

php artisan up

Maintenance Mode Response Template

The default template for maintenance mode responses is located in resources/views/errors/503.blade.php.

Maintenance Mode & Queues

While your application is in maintenance mode, no queued jobs will be handled. The jobs will continue to be handled as normal once the application is out of maintenance mode.