Home > Article > Development Tools > Will this create-project command be used in composer?
This article is introduced by the tutorial column of composer on how to use composer create-project. I hope it will be helpful to friends in need!
Using composer create-project
Preface
Today I used composer create-project to install thinkphp6, which I knew before How to use the create-project command to install the project? It has not been used for a long time. Fortunately, I am not too old yet and can still use my brain, so I just read the document and write down notes.
What to do
When will the composer create-project command be used? Generally speaking, composer require is used to introduce the library, which is very difficult. Use less create-project to install the project. I remember the last time I used this command was when I was writing a project using thinkphp5.1. So what exactly does this sentence do? Here is a quote from the Composer official website
You can use Composer to create a new project from an existing package. This is equivalent to executing a git clone or svn checkout command to install the package's dependencies into its own vendor directory.
We can read this information from the above, it will do two operations:
Create a new project from an existing package
Install the dependencies in this package to the vendor
That is to say, a new project will be created and the dependencies in this project will be downloaded to the vendor directory. So where does this package come from? Composer said that it will search for the package you specified on packagist.org.
How to use it
If you know what to do, you need to How to use it. The conventional use is composer create-project topthink/think think 5.1.*. Let’s talk about this command in detail. It is divided into four parts.
The first part is composer create-project, which tells composer that we want to create a project. ;
The second part topthink/think is the package name. This package name can be searched on the packagist.org website. If it cannot be found and the project cannot be created, composer will report an error;
The third part think, this is to give the created project a name, which is actually a directory name. If the directory exists, the directory must be empty, otherwise the project creation will fail. If the directory does not exist, it will be automatically created. When choosing an English name, you will encounter some indescribable problems in Chinese
The fourth part is the version of the created project, because the project we created comes from the package in the packagist library, and the package has different versions, so I For example, the created topthink\think has 5.1.* and 5.0.*. If we do not specify a version number, the new version will be created by default. Of course, the specified version 5.1.38 can also be used. You can also use wildcards 5.1.*, assignment operators ~5.1, etc.
parameters
composer create-project This command has some parameters, such as --prefer- dist When there are available packages, install the project from dist, --prefer-source When there are available projects, install from source
Not only the parameters I mentioned above, but also some parameters, but they are always useless at work However, I have not studied it carefully. Even if I read it, I forgot about it at the time. So my first step is to learn the composer create-project command and then learn how to use its parameters.
Others
It does not mean that you can only use composer create-project to create a project with composer. You can also use git clone to clone the project to your computer. There are many methods, just see Which one do you use, for me I prefer using composer create-project to install a thinkphp project
The above is the detailed content of Will this create-project command be used in composer?. For more information, please follow other related articles on the PHP Chinese website!