PHP Development Framework Laravel installation and configuration tutorial

Source: Internet
Author: User
Tags manual mcrypt pack php file php and php web development sqlite mysql database

Laravel is a concise, elegant PHP Web development framework, this article will describe in detail how Laravel is configured

Configuration Instructions

The framework is ready to download, but for good use, maybe we still have something to know, and that's the configuration. The configuration associated with the project is in the App/config folder, but there are some configurations that may be needed except here. As a basic tutorial, I will not introduce each one, just select some of you configure more places to explain.

Configuration instructions in the App/config

Typically two files are commonly configured in the App/config folder: app.php and database.php two files, one for the configuration project miscellaneous and one for the metabase. Below I will explain the common configuration inside:

First app.php file

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 app/config/app.php file return Array (//* |------------------------------------------------------------------------- - | Laravel Debug Module |--------------------------------------------------------------------------| When set to ' true ' for the open state (this setting is the default setting, for the Open state) | ' False ' is off state. When the error occurs when the program is turned on, the error message is displayed | When the procedure is closed, the program will jump to the error page (typically 404 pages)/' debug ' => true,  //*-------------------------------------------------- ------------------------ | Application Address |--------------------------------------------------------------------------| This address is only used when using the Artisan command, and needs to be set to the root directory of the application. | Well, if you still don't know what I'm talking about, then set it to empty. /' URL ' => ',  /* |--------------------------------------------------------------------------| Time Zone of application |--------------------------------------------------------------------------| This is the time zone operation, generally if you do not set the PHP, the time zone is the United States time zone, | That is, ' UTC ', ah, are you going to write to my celestial website? Then set it as ' Asia/shanghai '. * * timezone ' => ' Asia/shanghai ',  /* |-------------------------------------------------------------------- ------ | Localization of applications |--------------------------------------------------------------------------| The simple language is multi-language settings, 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 lot of language ideas, don't worry about it. * * ' locale ' => ' en ',  /* |--------------------------------------------------------------------------| Apply Key |--------------------------------------------------------------------------| This is the key that is used when applying Laravel's own encryption function 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 this before you write the page. | Once you change this string, the content encrypted with the previous string cannot be returned!! * * ' key ' => ',);

In fact, there are some things behind the app.php, but those basically do not need you to modify. (only need to add a third party package, we will speak later)

Next, introduce the database.php file

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 The 67 68 69 70 71 72 73 74 75 76 77 78 79 80 app/config/database.php file return Array (//* |-------------------------------------------------------------------- ------ | PDO Type |--------------------------------------------------------------------------| By default, laravel databases are operated with PDO, which can greatly improve database compatibility. | The type returned by the default query is an object, which is the default setting as follows. | 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 mentioned here corresponds to the name in the ' connections ' below, not to what database you use | For your better understanding, I changed a name here./' Default ' => ' MEINV ',  /* |---------------------------------------------------------- ---------------- | Database connection Name |--------------------------------------------------------------------------| Here is the configuration of the various databases, 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, and the name area is separated, just like the following ' MySQL ' and ' MEINV ' | The other, I think do not need to explain it, is literal meaning, I believe 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 ', ' host ' => ' Loca Lhost ', ' database ' => ' database ', ' username ' => ' root ', ' password ' => ', ' CharSet ' => ', ' UTF8 ', ' collation ' =&G T ' Utf8_unicode_ci ', ' prefix ' => ',),   ' MEINV ' => array (//This is the default connection database name in the above example, in fact, the MySQL database ' driver ' => ' m Ysql ', ' host ' => ' localhost ', ' database ' => ' database ', ' username ' => ' root ', ' password ' => ', ' CharSet ' =&gt ; ' UTF8 ', ' collation ' => ' utf8_unicode_ci ', ' prefix ' => ',),   ' Pgsql ' => array (' Driver ' => ' pgsql ', ' ho St ' => ' localhost ', ' database ' => ' database ', ' username ' => ' root ', ' password ' => ', ' CharSet ' => ' UTF8 ', ' Prefix ' => ', ' schema ' => ' public ',   ' sqlsrv ' => array (' Driver ' => ' sqlsrv '), ' host ' => ' Localho St ', ' database ' => ' database ', ' username ' => ' root ', ' password ' => ', ' prefix ' => ',),  );

Well, you know, I certainly will not all say, for the beginning of you, database settings know this is enough.

Configuring the development environment

Sometimes we need to specify that the development environment is "local" (the local environment typically refers to a virtual server on our own computer, is not published online) or "production" (the production environment generally refers to the online environment, is on the official server), or there are other environments (some development companies will also be divided into test environment, etc.), To facilitate a configuration change, such as "local" environment can be turned on 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. The following is an introduction to the environment configuration in Laravel.

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

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?) OK, I also checked for a long time, is your server name. Have children's shoes asked: How to know my computer hostname it?

Ipconfig/all

Open cmd Input in Windows

The following "host name" is hostname,

Open Terminal input in Ubuntu

Hostname

The show is 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 '),
));

OK, the configuration is here, more configuration content, I will continue to introduce in the Advanced tutorial:

Reprinted from http://www.golaravel.com/

System Environment Requirements

Apache,nginx or other Web servers;
Laravel uses some of the powerful features of PHP, so it needs to be performed on PHP5.3 or higher versions.
Laravel uses FileInfo library (http://php.net/manual/en/ book.fileinfo.php) to detect the MIME type of the file, which is contained by default in PHP5.3, but users in Windows need to open the module themselves in PHP.ini, if you don't understand, you can look here: http://php.net/ manual/en/fileinfo.installation.php;
Laravel uses the MCrypt library (http://php.net/manual/en/book.mcrypt.php) to encrypt and generate the hash, before using this framework, you need to ensure that the extension is installed, you can pass Phpinfo (); View the correct installation in the Web server if it is not visible: http://php.net/manual/en/book.mcrypt.php;

Install Laravel

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

Here you have completed a Laravel installation, and there is more to know.
The extra content
Install some additional extensions below so you can make full use of laravel

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

Problem?

If you have an installation problem, try the following:
Make sure that the public directory is the root directory of your site (see Server configuration below)
If you use the 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 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 Mysite.dev
</VirtualHost>

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

Laravel is a Windows environment, but does not require you to use Windows, you can do it under a favorite system.

The installation of the PHP run environment is outside the scope of this tutorial, and here is the basic requirement.
Web server:
PHP version 5.3 and above
PDO module
MCrypt Module
MySQL Database
The environment used in this tutorial:
PHP 5.4.5
MYSQL 5.0.45
To install the Laravel framework:
Download Laravel frame: Laravel Official Download | GitHub download
Unzip the frame to the server directory
The simple two-step laravel framework is installed and is accessed in the browser in order to test the success of the installation:

http://localhost/public/

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

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