Moment For Technology

Introduction to Laravel installation and startup

Posted on Sept. 27, 2022, 12:06 p.m. by Ross Brown-Anderson
Category: The back-end Tag: php

Introduction to Laravel

Laravel is a simple and elegant PHP WEB development Framework with expressive and concise syntax. Laravel is easy to understand and powerful. It provides powerful tools for developing large, robust applications. Common tools and functions such as automatic validation, routing, session, caching, database migration tools, unit testing, etc.

Most of the current frameworks have common features: 1. Single entry, all requests must start from a single entry, mainly for the convenience of management (unified parameter filtering) 2. MVC idea (hierarchical idea, mainly for collaborative development, to achieve the convenience of maintenance in the later period) AR Pattern Note: The Laravel framework has a feature that all URl accesses must be routed in advance.

Ii. Configuration and requirements of development environment

The Laravel framework is environmentally demanding to run. The Laravel framework has a few requirements for servers. Of course, Laravel Homestead already meets all of these requirements, so Homestead is recommended as laravel's native development environment. However, if you're not using Homestead, make sure your development environment meets the following requirements:

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

The php.ini configuration file needs to have the following extensions enabled:

extension=php_openssl.dll extension=php_pdo_mysql.dll extension=php_mbstring.dll extension=php_fileinfo.dll Extension =php_curl. DLL (for sending requests)

The httpd.conf configuration file needs to be opened in the following modules:

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

3. Introduce Composer

3.1 What is Composer:

Composer is a tool for managing dependencies in PHP. You can declare dependencies in your own project, and composer will help you install them. Installation of Composer

getcomposer.org/download/

Note: 1. Open the OpenSSL extension in PHP; 2. Specify the path of php.exe file to install Composer; 3

After the installation is complete, enter composer -v on the terminal. The installation is successful:If you enter composer -v to show that composer is not an internal or external command, the environment variables were not automatically added during the installation. You can only add them in the configuration environmentC:\ProgramData\ComposerSetup\bin;That will do.

3.2 Switching Composer Image Install the Laravel frame

3.2.1 Switching between Mirrors

Ali Cloud mirror:

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

3.2.2 Laravel project is deployed with Composer

Command: composer creation-project laravel/laravel --prefer-dist./

Creation-project: indicates that a project needs to be created by composer. Laravel /laravel: indicates that a laravel project needs to be created by composer. / or another name: indicates the path to be created for the project. (Make sure the path directory is empty when creating the project.)

For example, you need to create a Laravel projectcomposer create-project laravel/laravel --prefer-dist ./The effect

3.2.3 Laravel Directory Structure Analysis

App directory: the core directory of the project. The home page is used to store the core code, including controllers, models, and middleware.

Bootstrap directory: Laravel bootstrap directory

Config directory: the configuration directory of the project. The home page holds configuration files, such as database configuration

Database directory: Database migration tool

Pubilc directory: Directory of entry files

Resources directory: Resources directory (view, language pack)

Routes Directory: Route file directory

Storage directory: storage (project storage files, frame storage files, log storage files)

Tests directory: tests directory

Vendor directory: third-party extension library directory

Env file: project environment configuration file

Artisan file: scaffolding file, mainly used to generate code (automatic generation), such as controller, model file, etc. Run the command: # PHP artisan the command to execute. (Requirement 1: PHP must add environment variables and ensure version; Requirement 2: artisan must exist in the current working path of the command line;)

Json file: Specifies the third-party libraries that will be used by the current project.

Serve.php file: also an entry file

3.3 Boot Mode

Method 1: Laravel framework provides a simpler way to start the project (compared to configuring Apache (no need to configure Apache)). Run the following command: PHP Artisan Serve Not recommended: 1. 2. If you have changed the configuration of the project, the env will take effect only after you restart it. 3. If you use the command line to start the system, do not close the command line if you want to continue to access the page.

(Virtual host ≠ virtual machine) Add or modify the vhost configuration file of Apache:

VirtualHost *:80
  The email address of the site administrator, which is displayed when the site generates an error of 500 (internal server error)
  ServerAdmin 136072944@qq.com
  # Site to bind to the domain name
  ServerName learnlarevel.com
  ServerAlias localhost
  # The root directory of the site
  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
Copy the code

Restart Apache

Modify the hosts file: C: / Windows/System32 / drivers/etc/hostsThe next effect is as follows:This approach does not have the three disadvantages of the first approach.

On the way to learning PHP, if you find this article helpful to you, then please pay attention to like comment 3 times, thank you, your must be another support of my blog.

Search
About
mo4tech.com (Moment For Technology) is a global community with thousands techies from across the global hang out!Passionate technologists, be it gadget freaks, tech enthusiasts, coders, technopreneurs, or CIOs, you would find them all here.