PHP framework laravel installation and configuration instructions

墨辰丷
Release: 2023-03-31 19:24:02
Original
1427 people have browsed it

This article mainly introduces the installation and configuration instructions of the PHP framework laravel. Interested friends can refer to it. I hope it will be helpful to everyone.

Laravel is a simple and elegant PHP web development framework. This article will introduce in detail how to configure Laravel

Configuration instructions

Download the framework , but if we want to use it well, we may still need to know something, which is configuration. The configuration related to the project is in the app/config folder, but there are some configurations besides here that we may need. As a basic tutorial, I will not introduce them one by one. I will just choose some places where everyone has more configurations to explain.

Configuration instructions in app/config

There are generally two files that are often configured in the app/config folder: app.php and database.php Files, one of them is for configuring miscellaneous projects and the other is for configuring the database. Let me explain the common configurations inside:

First is the app.php file

// app/config/app.php 文件
return array( 
  /*
  |--------------------------------------------------------------------------
  | Laravel 的 debug 模块
  |--------------------------------------------------------------------------
  | 当设置为 'true' 的时候为开启状态(下面这种设置是默认设置,为开启状态)
  | 'false' 为关闭状态。开启的时候当程序出现错误会显示错误信息,
  | 而关闭的时候,程序一旦错误,则会跳转到错误页面(一般为404页)
  */
  'debug' => true,

  /*
  |--------------------------------------------------------------------------
  | 应用地址
  |--------------------------------------------------------------------------
  | 这个地址只有在使用 Artisan 命令的时候才会用到,需要设置为应用的根目录。
  | 额,如果你还是不清楚我在说什么,那就和下面一样设置成空吧。
  */
  'url' => '',

  /*
  |--------------------------------------------------------------------------
  | 应用的时区
  |--------------------------------------------------------------------------
  | 这个就是时区操作了,一般如果你没有对 PHP 进行设置的话,时区是美国时区,
  | 也就是 'UTC' ,啊,你是要写面向我天朝网站么?那就设置成 'Asia/Shanghai' 吧。
  */
  'timezone' => 'Asia/Shanghai',

  /*
  |--------------------------------------------------------------------------
  | 应用的本地化
  |--------------------------------------------------------------------------
  | 简单的说就是多语言设置,默认是 'en' 如果你没有自己写语言包的话那就还是这个值吧。
  | 你可以在 app/lang 文件夹中看到语言包,如果你没有多语言想法的话,那就不用管这个了。
  */
  'locale' => 'en',

  /*
  |--------------------------------------------------------------------------
  | 应用密钥
  |--------------------------------------------------------------------------
  | 这是在应用 Laravel 自带的加密功能时会用到的密钥,是为了保证加密安全性的。
  | 如果你的文件这里不是一个随机的 32 位字符串的话,你可以用 'php artisan key:generate'
  | 命令生成一个 32 位随机字符串,啊,记住要在你写网页之前做这个事情。
  | 一旦你变更这个字符串,那么用上一个字符串加密过的内容就找不回来了!!
  */
  'key' => '',
);
Copy after login

In fact, there is some content behind app.php, but those basically don’t need you to modify. (It is only needed when adding third-party packages, we will talk about it then)

Next, introduce the database.php file

// app/config/database.php 文件
return array( 
  /*
  |--------------------------------------------------------------------------
  | PDO 类型
  |--------------------------------------------------------------------------
  | 默认情况下 Laravel 的数据库是用 PDO 来操作的,这样能极大化的提高数据库兼容性。
  | 那么默认查询返回的类型是一个对象,也就是如下的默认设置。
  | 如果你需要返回的是一个数组,你可以设置成 'PDO::FETCH_ASSOC'
  */
  'fetch' => PDO::FETCH_CLASS,

  /*
  |--------------------------------------------------------------------------
  | 默认的数据库连接名
  |--------------------------------------------------------------------------
  | 这里所说的名字是和下面的 'connections' 中的名称对应的,而不是指你用的什么数据库
  | 为了你更好的理解,我在这里换了一个名字
  */
  'default' => 'meinv',

  /*
  |--------------------------------------------------------------------------
  | 数据库连接名
  |--------------------------------------------------------------------------
  | 这里就是设置各种数据库的配置的,每个数组里的 'driver' 表明了你要用的数据库类型
  | 同一种数据库类型可以设置多种配置,名字区分开就行,就像下面的 'mysql' 和 'meinv'
  | 其他的么,我觉得不需要解释了吧,就是字面意思,我相信你英文的能力(其实是我英文不好)
  */
  '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',
      'collation' => 'utf8_unicode_ci',
      'prefix'  => '',
    ),

    'meinv' => array( //这里就是上面例子里的默认连接数据库名,实际上是 mysql 数据库
      'driver'  => 'mysql',
      'host'   => 'localhost',
      'database' => 'database',
      'username' => 'root',
      'password' => '',
      'charset'  => 'utf8',
      'collation' => 'utf8_unicode_ci',
      'prefix'  => '',
    ),

    'pgsql' => array(
      'driver'  => 'pgsql',
      'host'   => 'localhost',
      'database' => 'database',
      'username' => 'root',
      'password' => '',
      'charset' => 'utf8',
      'prefix'  => '',
      'schema'  => 'public',
    ),

    'sqlsrv' => array(
      'driver'  => 'sqlsrv',
      'host'   => 'localhost',
      'database' => 'database',
      'username' => 'root',
      'password' => '',
      'prefix'  => '',
    ),

  ),
);
Copy after login

Well~, you know, I definitely don’t Enough said, for you who are just starting out, it is enough to know the database settings.

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 and is not published to Online) or "production" (the production environment generally refers to the online environment, that is, on a formal server), or there are other environments (some development companies will also divide into test environments, etc.) to facilitate a configuration For example, in the "local" environment, you can turn on debug, etc., but in the "production" environment, you cannot turn on debug, otherwise people will know some information about our server, which is secret and will cause insecurity. Then let’s introduce the environment configuration in Laravel.

The environment is configured 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'),
));
Copy after login

'your-machine here -name' refers to the hostname of your computer (what is hostname? Well, I checked it for a long time, it is your server name). Someone asked: How do I know the hostname of my computer?

ipconfig /all

Open cmd in Windows and enter

The "host name" below is hostname,

Open the terminal in Ubuntu Enter

hostname

and the displayed hostname

For example, the hostname of my computer is admin, then this is the code

As follows:

$env = $app->detectEnvironment(array(
    'local' => array('admin'),
));
Copy after login

System environment requirements

apache, nginx or other web servers;
laravel uses some powerful features of PHP, so it needs to be It can only be executed on PHP5.3 or higher;
Laravel uses the FileInfo library (http://php.net/manual/en/book.fileinfo.php) to detect the mime type of the file. This library is available in PHP5 .3 is included by default, but in Windows users need to enable this module in php.ini themselves. If you don’t understand, you can take a 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 hash. Before using this framework, you need to ensure that this extension is installed. You can use phpinfo (); Check whether it is installed correctly in the web server. If not, you can check: 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 32-character string Random content;
Verify whether storage/views is writable;
Access your application in the browser;

At this point you have completed a Laravel installation, there is more here need to know.
Extra Content
Install some of the following additional extensions so you can take full advantage of Laravel

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

question?

If you have installation problems, 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 application/config/application The index item in .php is empty.
Verify that your storage folder is writable.
Server configuration
Here we guarantee the most basic apache configuration. Our Laravel root directory is:/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>
Copy after login

Note: We installed it to /Users/JonSnow/Sites/MySite, and our DocumentRoot goes to /Users/JonSnow/Sites/MySite/public.

Getting started with Laravel It is a Windows environment, but you are not required to use Windows. You can do it under your favorite system.

The installation of the PHP running environment is beyond the scope of this tutorial. Here we only explain the basic requirements.
Web server:
PHP 5.3 and above
PDO module
Mcrypt module
MYSQL database
The 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
Extract the framework to the server directory
The Laravel framework is installed in a simple two-step process. In order to test whether the installation is successful, Visit in the browser:

http://localhost/public/

The public directory is the folder that comes with the framework. If you see the initial interface of laravel, it means it has been installed. success.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

How to operate the database in php to determine whether a table exists

##Three common tree traversal techniques in php

php uses curl to connect to the website and obtain information

The above is the detailed content of PHP framework laravel installation and configuration instructions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template