PHP Framework Laravel installation and configuration instructions

Source: Internet
Author: User
Tags mcrypt php framework php web development
This article mainly introduces the PHP framework Laravel installation and configuration instructions, interested in a friend's reference, I hope to be helpful to everyone.

Laravel is a concise, elegant PHP Web development framework that will detail how Laravel is configured

Configuration Instructions

The framework is ready to download, but to use it well, there may be some things we need to know, which is the configuration. The project-related configuration is in the App/config folder, but there are some configurations that we may need in addition to this. As a basic tutorial, I will not introduce each, just choose some of you configure more places to explain.

Configuration instructions in the App/config

Commonly configured in the App/config folder has two files: app.php and database.php two files, one of them is configuration item miscellaneous, one is the configuration database. Below I will explain the common configuration inside:

First app.php file.

app/config/app.php file return Array (/* |------------------------------------------------------------------------- -  | Debug module for Laravel |--------------------------------------------------------------------------| When set to ' true ' is turned on (this setting is the default setting, which is turned on) | ' False ' is off state. When an error occurs when the program is opened, an error message is displayed | And when the program is closed, it jumps to the error page (typically 404 pages) */' debug ' =-True,/* |-------------------------------------------------------- ------------------  | App Address |--------------------------------------------------------------------------| This address is only used when using the Artisan command and needs to be set to the app's root directory.  Well, if you still don't know what I'm talking about, just set it up as below. */' url ' = ',/* |--------------------------------------------------------------------------| Time zone for Apps |--------------------------------------------------------------------------| This is the time zone operation, generally if you do not set the PHP, time zone is the U.S. time zone, | That is ' UTC ', ah, are you going to write for my celestial site?  Then set it to ' Asia/shanghai '. */' timezone ' = ' Asia/shanghai ',/* |--------------------------------------------------------------------------  | Localization of applications |--------------------------------------------------------------------------| The simple word is the multi-language setting, the default is ' en ' if you don't write your own language pack, then that's the value. |  You can see the language pack in the App/lang folder, and if you don't have a multi-lingual idea, don't bother. */' locale ' = ' en ',/* |--------------------------------------------------------------------------| App Key |--------------------------------------------------------------------------| This is the key that will be used when applying the encryption feature of Laravel to ensure encryption security. | If your file is not a random 32-bit string, you can use ' PHP artisan key:generate ' | command to generate a 32-bit random string, ah, remember to do it before you write the page. |  Once you've changed the string, you'll never find it back with a string of encrypted content!! */' key ' = ', ';

In fact, there are some content behind app.php, but those that do not need you to modify. (only need to add a third-party package, we'll talk about it later)

Next introduce the database.php file

app/config/database.php file return Array (/* |-------------------------------------------------------------------- ------  | PDO Type |--------------------------------------------------------------------------| By default, the Laravel database is operated with PDO, which can greatly improve database compatibility. | The type returned by the default query is an object, which is the default setting below. If you need to return an array, you can set it to ' PDO::FETCH_ASSOC ' */' FETCH ' = pdo::fetch_class,/* |-------------------------------------- ------------------------------------  | Default database connection Name |--------------------------------------------------------------------------| The name here corresponds to the name in the following ' connections ', not what database you are using | For your better understanding, I changed a name here. */' default ' = ' MEINV ',/* |---------------------------------------------------------------- ----------  | Database connection Name |--------------------------------------------------------------------------| This is where the configuration of the various databases is set, and the ' driver ' in each array indicates the type of database you want to use | The same database type can be configured in a variety of configurations, the name area is separated, just like the following ' MySQL ' and ' MEINV ' | Other, I think there is no need to explain, it is the literal meaning, I believe that your English ability (in fact, my English is not good) */' connections ' = + Array (' sQlite ' = = Array (' Driver ' = ' sqlite ', ' database ' = __dir__. /.. /database/production.sqlite ', ' prefix ' = ', ', ', ' mysql ' = = Array (' Driver ' = ' mysql ', ' H ost ' + ' localhost ', ' database ' = ' database ', ' username ' + ' root ', ' password ' = ', ' CharSet ' + ' UTF8 ', ' collation ' = ' utf8_unicode_ci ', ' prefix ' = ', ', ' meinv ' = = Array (/ /Here is the default connection database name in the example above, actually MySQL database ' driver ' = ' mysql ', ' host ' = ' localhost ', ' database ' and ' d ' Atabase ', ' username ' = ' root ', ' password ' = ', ' charset ' = ' utf8 ', ' collation ' = ' UT F8_unicode_ci ', ' prefix ' = ', ', ', ' pgsql ' = = Array (' Driver ' = ' pgsql ', ' host ' = = ')  localhost ', ' database ' = ' database ', ' username ' = ' root ', ' password ' = ', ' CharSet ' ' UTF8 ', ' prefix ' = ', ' schema ' = ' publi 'C ',), ' sqlsrv ' = = Array (' Driver ' = ' sqlsrv ', ' host ' = ' localhost ', ' database ' = ') Database ', ' username ' = ' root ', ' password ' = ' ', ' prefix ' = ', ', ');

Amount ~, you understand, I certainly will not all say, for the beginning of you, the database settings know that this is enough.

Configuring the development environment

Sometimes we need to specify that the development environment is "local" (the local environment generally refers to the virtual server on our own computer, is not published to the Internet) or "production" (production environment generally refers to the online environment, is on the official server), or there are other environments (some development companies will be divided into test environments, etc.), In order to make a configuration change, such as "local" environment can open debug and so on, and "production" environment will not open debug, otherwise it will let people know some of our server information, this is a secret, will cause unsafe. Then let's introduce the environment configuration in Laravel.

Environment configuration in bootstrap/start.php, we open this file and find the following code in it

The code is as follows:

$env = $app->detectenvironment (Array (    ' local ' = = ' Array (' your-machine-name '));

The ' your-machine-name ' here refers to the hostname of your computer (what is hostname?). Well, I've been checking it for a long time, that's your server name. There are children's shoes asked: How to know my computer hostname it?


Open cmd Input in Windows

The following "host name" is hostname,

Open Terminal input in Ubuntu


It shows hostname.

For example, my computer's hostname is admin, so that's it.

The code is as follows:

$env = $app->detectenvironment (Array (    ' local ' = = Array (' admin '));

System Environment Requirements

Apache,nginx or other Web server;
Laravel uses some of the strong and powerful features of PHP, so it needs to be executed on PHP5.3 or higher;
Laravel using FileInfo library ( book.fileinfo.php) to detect the MIME type of the file, this library is included by default in PHP5.3, but in Windows users need to open the module in php.ini, if not understand can look here: manual/en/fileinfo.installation.php;
Laravel uses the MCrypt library ( to encrypt and generate hash, before using this framework, you need to ensure that the extension is installed, you can phpinfo (); Check the Web server for proper installation, if it is not viewable:;

Installing Laravel

Download laravel:;
Unzip the package file and upload it to the Web server;
Set the value of key in config/application.php, you can set a random content of 32 strings;
Verify that the storage/views is writable;
Access your app in a browser;

You've completed a Laravel installation here, and there's more to learn.
Additional content
Install some additional extensions below so you can take full advantage of Laravel

SQLite, MySQL, PostgreSQL, or SQL Server PDO drivers.
Memcached or APC.


If you have an installation problem, try the following:
Make sure the public directory is the root directory of your site (see Server configuration below)
If you are using Mod_rewrite, set the index entry in application/config/application.php to null.
Verify that your storage folder is writable.
Server Configuration
Here we guarantee a most basic Apache configuration, our Laravel root directory in:/users/jonsnow/sites/mysite

The configuration information is as follows:

The code is as follows:

<virtualhost *:80>    documentroot/users/jonsnow/sites/mysite/public    ServerName</ Virtualhost>

Note: We install to/users/jonsnow/sites/mysite, our documentroot to/users/jonsnow/sites/mysite/public.

Laravel Getting started with a Windows environment, but doesn't require you to also use Windows, you can do it under your favorite system.

The installation of the PHP runtime environment is beyond the scope of this tutorial, and here are just the basic requirements.
Web server:
PHP 5.3 and later
PDO module
MCrypt Module
MySQL Database
The environment used in this tutorial:
PHP 5.4.5
MYSQL 5.0.45
To install the Laravel frame:
Download Laravel framework: Laravel Official Download | GitHub download
Unzip the framework to the server directory
The simple two-step laravel framework is installed and is accessed in the browser in order to test if the installation is successful:


The public directory is the folder that comes with the framework, and if you see the initial interface of Laravel, it means that the installation was successful.

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related Article

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: 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.