search
HomeBackend DevelopmentPHP TutorialPHP framework laravel installation and configuration instructions

PHP framework laravel installation and configuration instructions

Jun 12, 2018 pm 03:29 PM
laravelphp development framework

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' => '',
);

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'  => '',
    ),

  ),
);

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

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

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>

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!

Statement
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
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment