Table of Contents
1. What is Composer
2. Install laravel
2. Create a new project
1. Enter the directory
3. Check the project directory
4. The backend pays attention to the composer.json file (located directly in the blog directory)
5. The front-end pays attention to package.json
6. Install nmp
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
9. Check the nginx configuration (nginx is not responsible for parsing php)
4. Q&A
Home Development Tools composer Detailed explanation of composer's process of creating a new laravel project

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

Feb 07, 2021 pm 03:13 PM
composer

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!

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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Solve caching issues in Craft CMS: Using wiejeben/craft-laravel-mix plug-in Apr 18, 2025 am 09:24 AM

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Improve Doctrine entity serialization efficiency: application of sidus/doctrine-serializer-bundle Improve Doctrine entity serialization efficiency: application of sidus/doctrine-serializer-bundle Apr 18, 2025 am 11:42 AM

I had a tough problem when working on a project with a large number of Doctrine entities: Every time the entity is serialized and deserialized, the performance becomes very inefficient, resulting in a significant increase in system response time. I've tried multiple optimization methods, but it doesn't work well. Fortunately, by using sidus/doctrine-serializer-bundle, I successfully solved this problem, significantly improving the performance of the project.

How to view the version number of laravel? How to view the version number of laravel How to view the version number of laravel? How to view the version number of laravel Apr 18, 2025 pm 01:00 PM

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

Use Composer to solve dependency injection: application of PSR-11 container interface Use Composer to solve dependency injection: application of PSR-11 container interface Apr 18, 2025 am 07:39 AM

I encountered a common but tricky problem when developing a large PHP project: how to effectively manage and inject dependencies. Initially, I tried using global variables and manual injection, but this not only increased the complexity of the code, it also easily led to errors. Finally, I successfully solved this problem by using the PSR-11 container interface and with the power of Composer.

Title: Use Composer to solve the problem of unified representation of complex data types Title: Use Composer to solve the problem of unified representation of complex data types Apr 18, 2025 am 08:33 AM

Summary Description: When dealing with complex data types, you often encounter problems of how to uniformly represent and operate. This problem can be easily solved with Composer using the phrity/o library. It provides encapsulation classes and traits for various data types, making data processing more consistent and efficient.

How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library How to use Composer to improve the security of Laravel applications: Applications of wiebenieuwenhuis/laravel-2fa library Apr 18, 2025 am 11:36 AM

When developing a Laravel application, I encountered a common but difficult problem: how to improve the security of user accounts. With the increasing complexity of cyber attacks, a single password protection is no longer enough to ensure the security of users' data. I tried several methods, but the results were not satisfactory. Finally, I installed the wiebenieuwenhuis/laravel-2fa library through Composer and successfully added two-factor authentication (2FA) to my application, greatly improving security.

How to quickly build Fecmall advanced project templates using Composer How to quickly build Fecmall advanced project templates using Composer Apr 18, 2025 am 11:45 AM

When developing an e-commerce platform, it is crucial to choose the right framework and tools. Recently, when I was trying to build a feature-rich e-commerce website, I encountered a difficult problem: how to quickly build a scalable and fully functional e-commerce platform. I tried multiple solutions and ended up choosing Fecmall's advanced project template (fecmall/fbbcbase-app-advanced). By using Composer, this process becomes very simple and efficient. Composer can be learned through the following address: Learning address

See all articles