Laravel 5.3 Installation Configuration user manual

Source: Internet
Author: User
Tags manual time zones php file require

One, install

1, server Requirements
The Laravel framework has a small number of requirements for the server and, of course, Laravel Homestead has met all of these requirements, so we strongly recommend using Homestead as the Laravel Local development environment (Mac can also use valet as a local development environment).

However, if you are not using Homestead, you need to ensure that the development environment meets the following requirements:

PHP version >= 5.6.4
PHP Extensions: OpenSSL
PHP Extensions: PDO
PHP Extensions: mbstring
PHP Extensions: Tokenizer
2. Installation Laravel
Laravel uses Composer management dependencies, so before using Laravel, make sure that Composer is already installed on the machine.

Through the Laravel installer

First, install the Laravel installer via Composer:

Composer global require "Laravel/installer"
Make sure ~/.composer/vendor/bin is in the system path, otherwise you cannot invoke the Laravel command on any path.

Once the installation is complete, a new Laravel application can be created in the current directory with a simple laravel new command, for example, laravel new blog will create an application called a blog and contain all laravel dependencies. This installation method is much faster than through Composer installation:

Laravel New Blog
Through Composer Create-project

You can also install Laravel applications in the terminal via the Composer create-project command:

Composer Create-project--prefer-dist Laravel/laravel Blog
3, configuration
All configuration files for the Laravel framework are stored in the Config directory, and each configuration item is commented, so you can browse any profile to familiarize yourself with these configuration items.

Public directory

After installing Laravel, you need to point the Web root directory of the HTTP server to the public directory, where the index.php file will be the front-end controller, and all HTTP requests will be entered into the application through that file.

Configuration file

All configuration files for the Laravel framework are stored in the Config directory, and all configuration items are commented, so you can easily navigate through the profiles to familiarize yourself with all the configuration items.

Directory Permissions

After installing Laravel, you need to configure some directory read and write permissions: The storage and Bootstrap/cache directories should be writable, and if you use the Homestead virtual machine as the development environment, these permissions are already set.

Apply Key

The next thing to do is to set the applied key (App_key) to a random string, and if you install it through the Composer or Laravel installer, the value of the key is already generated through the PHP artisan key:generate command.

Typically, the string should be 32 bits long, configured with the App_key in the. env file, and if you haven't renamed the. env.example file to. env, do so now. If the application key is not set, user session and other encrypted data will have security implications.

More Configuration

Laravel almost no longer requires any other configuration to work, but you'd better look at the config/app.php file, which includes configurations based on applications that might need to be changed, such as timezone and locale (for configuring time zones and localization, respectively).

You may also want to configure some of the other components of laravel, such as caching, database, session, and so on, which we will explore in subsequent document one by one.

Once the installation is complete, you can go to the next step-configure Laravel.

Second, configure

1. Introduction
All of the configuration files for laravel are stored in the Config directory, and each configuration item is commented to ensure that any configuration item browsing any profile can visually understand the role and usage of the configuration item.

2, Access configuration values
You can access the configuration value at any point in the application using the Global Accessibility function config, which can be a filename + "." + Configuration item to access the default value when the configuration item is not configured:

$value = config (' app.timezone ');
If you want to set the configuration value at run time, pass the array parameter to the Config method:

Config ([' App.timezone ' => ' America/chicago ']);
3. Environment configuration
Depending on the application run environment different settings different configuration values can bring great convenience to us, for example, we usually configure the local and online environment different cache drivers, this mechanism in the laravel is very easy to implement.
Laravel uses Vance Lucas to develop PHP library dotenv to implement this mechanism, in the newly installed laravel, the root directory has a. env.example file, if Laravel is installed through Composer, then the file has been is renamed to. Env, otherwise you will have to manually rename the file yourself.

Get environment variable configuration value

All the configurations and their values listed in the. env are loaded into the PHP hyper-global variable $_env each time the application accepts the request, and then you can get the configuration values in the application by using the helper function env. In fact, if you look at the laravel configuration file, you'll find that many places are already using this helper function:

' Debug ' => env (' App_debug ', false),
The second parameter passed to the ENV function is the default value, which is the default if the environment variable is not configured.

Do not submit a. env file to source control (svn or GIT, etc.) because each developer/server using your application may require a different configuration of the environment.

If you are developing on a team, you need to submit the. env.example file to the source control with your application: Place some of the configuration values in the. env.example file as placeholders, so that other developers will know exactly what environment variables to run your application to configure.

Determining the current application environment

The current application environment is determined by the APP_ENV variable in the. env file, and you can access its value through the environment method of the APP façade:

$environment = App::environment ();
You can also pass parameters to the environment method to determine whether the current environment matches a given value, and you can even pass multiple values if necessary. If the current environment matches the given value, the method returns true:

if (app::environment (' local ')) {
The environment is local
}

if (app::environment (' local ', ' staging ')) {
The environment is either a local OR staging ...
}
Application examples can also be visited via the helper function app:

$environment = App ()->environment ();
4. Configure caching
To speed up the application, you can use the Artisan command Config:cache to cache all configuration files in a single file, which merges all the configuration options into a single file and can be quickly loaded by the framework.

Once the application is online, the PHP artisan Config:cache is run once, but it is not necessary to run the command frequently when developing locally, because the configuration values often need to be changed.

5. Maintenance Mode
When your application is in maintenance mode, all requests for the application return to the same custom view. This mechanism makes it easy to "close" a site when upgrading or maintaining an application. The code for the maintenance mode is located in the application default middleware stack, and if the application is in maintenance mode, the maintenancemodeexception with a status code of 503 will be thrown.
To turn on maintenance mode, simply execute the Artisan command down:

PHP Artisan Down
To turn off maintenance mode, the corresponding Artisan command is up:

PHP Artisan up
Maintenance Mode Response Template

The default maintenance Mode Response View template is resources/views/errors/503.blade.php

Maintenance Mode & Queues

When your site is in maintenance mode, all queue tasks are not executed, and the tasks will continue to function normally when the application exits maintenance mode.

Alternative to Maintenance mode

Since the Maintenance Mode command takes a few seconds to execute, you may consider using Envoyer to implement a 0-second offline as an alternative.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.