Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between require and install vs create-project in composer

Tags:

I don't get how the create-project works in composer. Lets take Laravel as example.

I can install this PHP framework with the following command:

composer create-project laravel/laravel --prefer-dist 

This command installs the framework for me leaving me with a few folder in the root of my dir:

  • app
  • bootstrap
  • public
  • vendor

Plus some files.

But when I simply use the following composer command:

composer require laravel/laravel --prefer-dist composer install 

Then this only installs the vendor folder. No other files and folders are downloaded by composer.

How come? What is so different? How does composer know what other files to get when I use the create-project laravel/laravel command and why do I only get the vendor folder when I do require laravel/laravel?

like image 259
Vivendi Avatar asked Apr 08 '14 17:04

Vivendi


People also ask

What is difference between require and require Dev in composer?

require: These are must packages for the code to run. It defines the actual dependency as well as package version. require_dev: It defines the packages necessary for developing the project and not needed in production environment. Note: The require and require_dev are important parameters available in composer.

What is the difference between composer require and composer update?

composer update is mostly used in the 'development' phase, to upgrade our project packages. composer install is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer.

What does composer install do?

Composer: Enables you to declare the libraries you depend on. Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project). You can update all your dependencies in one command.

What is require in composer json?

The require key# The first thing you specify in composer. json is the require key. You are telling Composer which packages your project depends on. { "require": { "monolog/monolog": "2.0.*" } } As you can see, require takes an object that maps package names (e.g. monolog/monolog ) to version constraints (e.g. 1.0.


1 Answers

require will add a dependency to the composer.json file and load it into the vendor directory as you have correctly noticed.

create-project on the other hand will clone the dependency, i.e. use the dependency as a template for a new project. Take a look at the repository behind laravel/laravel: https://github.com/laravel/laravel

like image 194
hanzi Avatar answered Oct 18 '22 21:10

hanzi