Detailed explanation of composer's process of creating a new laravel project

藏色散人
Release: 2021-02-07 15:14:39
forward
3410 people have browsed it

The following tutorial column of composer will explain in detail the process of creating a new laravel project with composer. I hope it will be helpful to friends in need!

Detailed explanation of composer's process of creating a new laravel project

1. What is Composer

For a long time, PHP’s open source method has been project-level, which means that as soon as I open source it is a project , such as a set of CMS, a framework such as Codeigniter. why? One of the important reasons is that it is difficult to take them apart. If they are taken apart, there is no effective management tool to combine them, resulting in no one paying attention to the small modules that have been taken apart.
Then Composer appeared. It is responsible for managing the various small modules that everyone has open source, and effectively integrating them together to make them a complete project.
composer is one of the PHP code dependency management tools
For example, if your project needs to use the PHPmail class library, as long as you follow the composer format, composer
can automatically help you download this code library. In your project.

2. Install laravel

First, use Composer to download the Laravel installer:
composer global require "laravel/installer"
Install laravel
composer create-project --prefer-dist laravel/laravel blog
View laravel version
laravel -v

3. Create a new project

1. Enter the directory

cd /data/www/

2. Create a new project

composer create-project --prefer-dist laravel/laravel blog
This line The command will create a project called blog. ps: This line of code has been run once. Running it again will cause the terminal to get stuck and nothing will be displayed.

3. Check the project directory

Enter the project directory
subl .

4. The backend pays attention to the composer.json file (located directly in the blog directory)

composer.json describes the dependencies of this project
In "require" Seeing that this project uses the laravel framework 5.5
and then relying on it layer by layer

5. The front-end pays attention to package.json

describes the main reliance on mpm dependency package
For example
axios is used to initiate front-end business requests
cross-env webpack command
Note: bootstrap is configured with sass source code (/resources/assets/sass/app.scss) by default

6. Install nmp

sudo apt install npm
npm i
After the installation is complete, you can see that the packages that the front-end depends on are placed in the newly generated node_modules directory

7. After the project is created, you can see that the .env file has been generated

8. View the local web page with the browser

First configure the hosts file (hosts file location: /etc /hosts)
127.0.1.1 l.blog.com
Enter l.blog.com in the browser

9. Check the nginx configuration (nginx is not responsible for parsing php)

sudo nginx -t
subl nginx directory address
The nginx configuration file is the entrance to nginx. It configures the basic configuration of http and the configuration of the site. The configuration can be referenced
You need to configure the server in nginx to access the website For example, when setting server_name *.blog.com, when we enter l.blog.com, it will automatically match the server, and then go to the /data/www/blog.com/public directory under the root to find the PHP default page, which is index .php was looking for execution, so we changed it to the laravel framework, and our website can be accessed.
There are two very important files here, enable-php.conf and enable-laravel.conf
enable-php.conf is responsible for configuring communication with php
enable-laravel.conf is handwritten and can Query in the laravel documentation how to make the website a laravel-compliant document
location / {
try_files`$uri`$uri/`/ index.php$is_args$args;
}

4. Q&A

  • Q. unexpectedValueException: the stream or file “/data/www/blog.com/storage/logs/laravel.log”could not be open:failed to open stream:Permission denied

A: Indicates that the laravel framework has been entered Category
Change folder permissions sudo chmod -R 777. Note: R is capitalized here

  • Q. It keeps spinning when loading the website

A: Press F12 to check the website. The network found that one time has been in the pending state, and other tasks have been completed.
When the cursor moves up, it shows fonts.googleapis.com
which has been referenced in views. For Google fonts, find welcome.blade.php
in the views directory. Comment out the raleway font here and it will be ok
Second, the Google fonts referenced by bootstrap cause circles
Find /resources/assets/ sass/app.scss
I found that bootstrap uses the font library of Raleway by default, which is from Google. Just comment it out and it will be ok
Note: What is modified here is the sass source code and needs to be recompiled

npm run prod

  • Q. After entering l.blog.com in the browser, the LNMP one-click installation package page appears

A: This is because the nginx.conf file is not configured Good
subl /usr/local/nginx/conf/nginx.conf
Reconfigure a server ps: It is best to put all projects in one directory to develop good habits. The project path is easy to write here.
After configuring the server, check the configuration file
sudo nginx -s reload
sudo nginx -t
After the check is correct, you can access the project

The above is the detailed content of Detailed explanation of composer's process of creating a new laravel project. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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