Introduction to Laravel installation and startup

1. Introduction to Laravel

1. Introduction
Laravel is a set of simple and elegant PHP WEB development framework (PHP Web Framework) with expressive and concise syntax. Laravel is easy to understand and powerful. It provides powerful tools for large-scale development. Robust applications, such as automatic verification, routing, session, caching, database migration tools, unit testing and other commonly used tools and functions.

Common features of most of the current frameworks:
1. Single entry, all requests must start from a single entry, mainly for easy management (unified parameter filtering)
2. MVC idea (layered idea, mainly for collaborative development and implementation Convenient maintenance later)
3. ORM operation database (Object Relations Model, association model): AR mode
Note: The Laravel framework has a feature, all URl access must be pre-defined routing rules.

2. Development environment configuration and requirements

The operation of the Laravel framework has strict requirements on the environment. (Only record window here , please click here for mac environment ) The
laravel framework has a few requirements for the server. Of course, Laravel Homestead has met all these requirements, so it is recommended to use Homestead as laravel as the local development environment for Laravel.
However, if you are not using Homestead, you need to ensure that the development environment meets the following requirements:

PHP version>=5.6.4
PHP extension: OpenSSL
PHP extension: PDO
PHP extension: Mbstring
PHP extension: Tokenizer

Extensions that need to be turned on in the php.ini configuration file:

extension=php_openssl.dll extension=php_pdo_mysql.dll
extension=php_mbstring.dll
extension=
php_fileinfo.dll (the verification code depends on the extension)
extension=php_curl.dll (mainly used to send the request)

Modules that need to be enabled in the httpd.conf configuration file:

LoadModule deflate_module modules/mod_deflate.so
LoadModule rewrite_module modules/mod_rewrite.so

Three, composer introduction

3.1 What is composer:

Composer English word meaning: music conductor
composer is a tool used to manage dependencies in PHP. You can declare the external tool libraries you rely on in your project, and composer will help you install these dependent library files.
Install composer address:

https://getcomposer.org/download/

Note:
1. Open the openssl extension in PHP
2. Install composer needs to clarify the file path of php.exe
3. Install composer needs to be connected to the Internet

After the installation is complete, enter composer -V in the terminal, and the installation is successful as follows:
Insert picture description here
If the composer is not an internal or external command after the installation is complete, enter composer -v, that is, the environment variables are not automatically added during the installation, just configure C:\ProgramData\ComposerSetup\bin;Just join the environment .

3.2 Switch composer mirror to install laravel framework

3.2.1, switch mirror

Alibaba Cloud image:

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

3.2.2, composer deploys laravel project

command:composer create-project laravel/laravel --prefer-dist ./

Command meaning:
composer: indicates that composer needs to be executed
create-project: indicates that a project needs to be created through composer
laravel/laravel: creates a Laravel project
–prefer-dist: indicates that downloading using compressed packages is mandatory (time saving)
./ or other names: The path that the flat food project needs to create [make sure that the path directory is empty when creating the project]

For example: the need to create a project Laravel
composer create-project laravel/laravel --prefer-dist ./
effect
Insert picture description here

3.2.3 Analysis of laravel directory structure

Insert picture description here

app directory: the core directory of the project. The home page is used to store the core code, including controllers, models, and middleware.
Insert picture description here

bootstrap directory: laravel startup directory

config directory: project configuration directory, home page stores configuration files, such as database configuration

database directory: database migration tool

pubilc directory: entry file directory

resources directory: resource directory (views, language packs)

routes directory: route file directory

storage directory: storage (project storage files, framework storage files, log storage files)

tests directory: test directory

vendor directory: third-party extension library directory

.env file: project environment configuration file

artisan file: scaffolding file, mainly used to generate code (automatically generated), such as generating controllers, model files, etc. Execution command: #php artisan The command that needs to be executed. (Requirement 1: php must add environment variables and ensure the version; requirement 2: artisan must exist in the current working path of the command line;)

composer.json file: declares the third-party libraries that the current project needs to use.

serve.php file: also an entry file

3.3 Startup method

Method 1: The Laravel framework provides a simpler way to start the project (compared to configuring apache (no need to configure apache)) to
execute the command: php artisan serve is
not recommended:
1. It can run php code, but does not start the database.
2. After this method is started, if the project configuration .env is modified, it will take effect after a restart.
3. If you use the command line to start, if you want to continue to access the page, the command line cannot be closed.

Method 2: Use wamp or lamp environment (common)
virtual host configuration: (virtual host ≠ virtual machine)
add or modify the configuration file of the apache virtual host vhost:

<VirtualHost *:80>
  #站点管理员的邮箱,当站点产生500错误(服务器内部错误)的时候会显示在页面上
  ServerAdmin 136072944@qq.com
  #站点需要绑定的域名
  ServerName learnlarevel.com
  ServerAlias localhost
  #站点的根目录
  DocumentRoot "E:\laraveldemo\laravel\public"
  DirectoryIndex index.php
  <Directory "E:\laraveldemo\laravel\public">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    allow from all
  </Directory>
</VirtualHost>

Restart apache after making changes

Modify the hosts file: C:/Windows/System32/drivers/etc/hosts The
Insert picture description here
next effect is as follows:
Insert picture description here
This method does not have the 3 shortcomings of the first method.

On the way of learning php, if you think this article is helpful to you, then please pay attention to like and comment Sanlian, thank you, you must be another support for my blog.

Guess you like

Origin blog.csdn.net/weixin_44103733/article/details/113204554