PHP development framework laravel installation and configuration tutorial

Source: Internet
Author: User
Tags php web development
Laravel is a simple and elegant PHP Web development framework. This article will introduce how Laravel configures Laravel as a simple and elegant PHP Web development framework. This article will introduce how Laravel configures

Configuration instructions

The framework has been downloaded, but we still need to know something to use. this is the configuration. Project-related configuration is in the app/config folder, but there are some other configurations that may be needed here. As a basic tutorial, I will not introduce it one by one. I just want to explain it in some scenarios where you have many configurations.

Configuration instructions in app/config

In the app/config folder, two files are often configured: app. php and database. php. one of them is the configuration item miscellaneous, and the other is the configuration database. Below I will explain the common configurations below:

First, the app. php file

// App/config/app. php file return array (/* | release | Laravel debug module | enabled | enable when set to 'true' (the following settings are default and enabled) | 'false' is disabled. When the program is enabled, an error message will be displayed when an error occurs. | when the program is closed, the page will jump to the error page (usually 404 pages) */'debug' => true,/* | used | application address | used | this address is used only when the Artisan command is used and must be set as the application root directory. | Yes. if you still don't know what I'm talking about, set it to null like below. */'URL' => '',/* | runtime | time zone of the application | runtime | this is the time zone operation. if you have not set PHP, the time zone is the United States time zone, | that is, 'utc'. do you want to write a website targeting China's Tianchao website? Set it to 'Asia/Shanghai. */'Timezone '=> 'Asia/Shanghai',/* | ---------------------------------------------------------------- | Application localization | generally, you can set multiple language settings, the default value is 'en'. if you do not have your own language pack, you should leave this value alone. | You can see the language pack in the app/lang folder. if you don't have any multilingual idea, you don't need to worry about it. */'Locale' => 'en',/* | secret | application key | secret | this is the key used when Laravel's built-in encryption function is applied, to ensure encryption security. | If your file is not a random 32-bit string, you can use 'php artisan key: generate' | the command generates a 32-bit random string, remember to do this before you write a webpage. | Once you change this string, the contents encrypted with the previous string cannot be found !! */'Key' => '',);

In fact, there is still some content behind app. php, but it basically does not need to be modified. (This is only required when a third-party package is added. we will talk about it later)

Next we will introduce the database. php file

// App/config/database. php file return array (/* | bytes | PDO type | bytes | by default, Laravel databases are operated by PDO, which greatly improves database compatibility. | By default, the returned type is an object, that is, the following default settings. | If you want to return an array, you can set it to 'pdo: FETCH_ASSOC '*/'fetch' => PDO: FETCH_CLASS, /* | connections | default database connection name | -------------------------------------------------------------------------- | the name here corresponds to the name in the following 'connections, instead of the database you are using | for your better understanding, I changed a name here */'default' => 'meinv ', /* | database connection name | ------------------------------------------------------------------------------ | the configuration of various databases is set here, the 'driver 'in each array indicates the type of the database you want to use | you can set multiple configurations for the same database type, just name them separately, like the following 'mysql' and 'meinv' | others, I don't think I need to explain them. it is literal. I believe your English skills (in fact, my english is poor) */'connections' => array ('sqlite '=> array ('driver' => 'sqlite ', 'database' => _ DIR __. '/.. /database/production. sqlite ', 'prefix' => '',), 'mysql' => array ('driver' => 'mysql', 'host' => 'localhost ', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8 ', 'colation' => 'utf8 _ unicode_ci ', 'prefix' => '',), 'meinv' => array (// Here is the default connection database name in the above example. it is actually the mysql database 'driver '=> 'mysql ', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'colation' => 'utf8 _ unicode_ci ', 'prefix' => '',), 'pgsql' => array ('driver '=> 'pgsql', 'host' => 'localhost', 'database' => 'database ', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'prefix' => '', 'scheme' => 'public',), 'sqlsrv' => array ('driver '=> 'sqlsrv', 'host' => 'localhost ', 'database' => 'database', 'username' => 'root', 'password' => '', 'prefix' => '',),),);

Amount ~, You know, I certainly won't even finish it all. for you at the beginning, it is enough to know about database settings.

Configure 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 and has not been released to the Internet) or "production" (the production environment generally refers to the online environment, that is, the formal server), or other environments (some development companies will also test the environment ), to facilitate configuration changes, such as opening debug in the "local" environment, but not in the "production" environment, otherwise, some information about our servers will be known, which is a secret and will cause insecurity. Next we will introduce the environment configuration in Laravel.

The environment is configured in bootstrap/start. php. open this file and find the following code:

The code is as follows:


$ Env = $ app-> detectEnvironment (array (
'Local' => array ('your-machine-name '),
));

Here, 'Your-machine-name' refers to your computer's hostname (what is hostname? Okay, I have also checked it for a long time, that is, your server name ). Some children's shoes asked: how do I know my computer's hostname?

Ipconfig/all

Open cmd input in Windows

The following "host name" is hostname,

Enable terminal input in Ubuntu

Hostname

The hostname is displayed.

For example, if my computer's hostname is admin

The code is as follows:


$ Env = $ app-> detectEnvironment (array (
'Local' => array ('admin '),
));

Now, the configuration will be introduced here. For more configuration content, I will continue to introduce it in the advanced tutorial :)

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

System environment requirements

Apache, nginx, or other web servers;
Laravel uses some strong PHP features, so it can be executed only in PHP5.3 or later;
Laravel uses FileInfo library (http://php.net/manual/en/book.fileinfo.php) to detect the mime type of the file, which is included by default in PHP5.3, but in Windows users need to own in php. enable this module in ini. if you do not understand it, please refer to the following link: 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 hash, and before using this framework, you need to ensure that this extension is installed, you can use phpinfo (); check whether the web server is correctly installed. if not, check http://php.net/manual/en/book.mcrypt.php;

Install laravel

Download laravel: http://laravel.com/download;
Decompress the compressed package and upload it to the web server;
Set the key value in config/application. php. you can set a random content consisting of 32 strings;
Verify whether storage/views can be written;
Access your application in a browser;

Now you have installed Laravel. you need to know more about it.
Additional content
Install the following additional extensions so that you can make full use of Laravel.

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

Question?

If you have any installation problems, try the following:
Make sure that the public directory is the root directory of your site (see the server configuration below)
If you use mod_rewrite, set the index item in application/config/application. php to null.
Verify that your storage folder is writable.
Server Configuration
Here we guarantee a basic apache configuration. the root directory of Laravel is:/Users/JonSnow/Sites/MySite.

The configuration information is as follows:

The code is as follows:



DocumentRoot/Users/JonSnow/Sites/MySite/public
ServerName mysite. dev

Note: We install/Users/JonSnow/Sites/MySite, and our DocumentRoot to/Users/JonSnow/Sites/MySite/public.

Laravel is started in a Windows environment, but does not require you to use Windows. you can do this in your favorite system.

The installation of the PHP runtime environment is not in the scope of this tutorial. here, only the basic requirements are described.
Web server:
PHP 5.3 and later versions
PDO module
Mcrypt module
MYSQL database
Environment used in this tutorial:
PHP 5.4.5
MYSQL 5.0.45
Install the Laravel framework:
Download the Laravel framework: Laravel official download | Github download
Decompress the framework to the server directory.
The Laravel framework is installed in two simple steps. to test whether the installation is successful, visit:

Http: // localhost/public/

The public directory is the folder that comes with the framework. if you see the initial interface of laravel, it indicates that the installation is successful.

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.