SlideShare a Scribd company logo
1 of 12
Download to read offline
Composer Best
Practices
Abid H. Malik
Composer: Introduction
● Composer is a tool for dependency management in PHP.
● It allows you to declare the libraries your project depends on
and it will manage (install/update) them for you.
Composer: files
❖ composer.json
➢ This file describes the dependencies of your project and may
contain other metadata as well. It typically should go in the
top-most directory of your project
❖ composer.lock
➢ contains all of the packages and their exact versions, locking the
project to those specific versions.
❖ auth.json
➢ ~/.composer/auth.json (Global)
➢ <proj_dir>/auth.json (local)
➢ contains authentication for private repositories
Composer: repositories
❖ A Composer repository is basically a package source: a place
where you can get packages from.
❖ Packagist.org
➢ Is the main Composer repository.
➢ Aims to be the central repository that everybody uses.
❖ Packagist.com
➢ is a commercial package hosting product offering
professional support and web based management of
private and public packages, and granular access
permissions.
❖ Github - (host your private repositories)
❖ Private Repositories - (to be discussed later)
Composer: Frequently used commands
● composer install
● composer update
● composer update vendor/package
● composer require vendor_name/package_name
● composer require vendor_name/package_name:version
Composer: Best Practices
● Do not run composer update on production.
● If you want to run then you have to run composer install.
● You should never use composer updatewithout argument.
● A better approach to do if composer-updateis needed:
○ Checkout on a dev environment and composer update,
○ Ensure the app is thoroughly tested on a dev environment
○ Then install on live/production with composer install
Composer: Important Commands
● composer update --with-dependencies
○ Updates all packages and its dependencies
● composer update vendor/*
○ Updates all packages from vendor
● composer update --lock
○ Updates composer.lock hash without updating any packages
● composer remove vendor/package
○ Removes vendor/package from composer.json and uninstalls it
● composer update --no-dev
○ This causes composer to skip installing packages listed in
“require-dev”. After which the “composer.autoload” file is not
generated
● composer install --dry-run
○ Simulates the install without installing anything
Composer: Important Commands
● composer outdated
○ Shows a list of installed packages that have updates available
● composer dump-autoload --optimize
○ Generates optimized autoload files
● composer self-update
○ Updates the composer.phar file to the latest version
● composer depends vendor-name/package-name
○ Tell you which other packages depend on a certain package.
● composer info
○ Show information about packages.
Composer : Passing Version
● composer require vendor/pkg "1.3.2"
○ Installs 1.3.2
● composer require vendor/pkg ">=1.3.2"
○ Above or equal 1.3.2
● composer require vendor/pkg "<1.3.2"
○ Below 1.3.2
● composer require vendor/pkg "1.3.*"
○ Latest of >=1.3.0 <1.4.0
● composer require vendor/pkg "~1.3.2"
○ Latest of >=1.3.2 <1.4.0
Composer : Passing Version
● composer require vendor/pkg "~1.3"
○ Latest of >=1.3.0 <2.0.0
● composer require vendor/pkg "^1.3.2"
○ Latest of >=1.3.2 <1.4.0
● composer require vendor/pkg "^1.3"
○ Latest of >=1.3.0 <2.0.0
● composer require vendor/pkg "^0.3.2"
○ Latest of >=0.3.2 <0.4.0
● composer require vendor/pkg "2.0.0-3.0.0"
○ All versions above and including 2.0.0 and below and including 3.0.0
Tilde (~) and caret (^) version constraints in
Composer
The tilde sign
● ~4.1.3 means >=4.1.3,<4.2.0,
● ~4.1 means >=4.1.0,<5.0.0 (most used),
● ~0.4 means >=0.4.0,<1.0.0,
● ~4 means >=4.0.0,<5.0.0.
The caret sign is slightly different:
● ^4.1.3 (most used) means >=4.1.3,<5.0.0,
● ^4.1 means >=4.1.0,<5.0.0, same as ~4.1 but:
● ^0.4 means >=0.4.0,<0.5.0, this is different from ~0.4 and is more useful for
defining backwards compatible version ranges.
● ^4 means >=4.0.0,<5.0.0 which is the same as ~4 and 4.*.
Thank you

More Related Content

Similar to Composer Best Practices.pdf

Composer yourself: a reintroduction to composer
Composer yourself:  a reintroduction to composerComposer yourself:  a reintroduction to composer
Composer yourself: a reintroduction to composerEric Poe
 
Introducing composer - a php dependency manager
Introducing composer  - a php dependency managerIntroducing composer  - a php dependency manager
Introducing composer - a php dependency managerDigvijay Tiwari
 
12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboardsDenis Ristic
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with ComposerAdam Englander
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning TalkEric Johnson
 
Magento Docker Setup.pdf
Magento Docker Setup.pdfMagento Docker Setup.pdf
Magento Docker Setup.pdfAbid Malik
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NLRafael Dohms
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composernuppla
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Micah Wood
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guidevjvarenya
 
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerWordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerJeremy Ward
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)iFour Technolab Pvt. Ltd.
 
Leveraging Composer in Existing Projects
Leveraging Composer in Existing ProjectsLeveraging Composer in Existing Projects
Leveraging Composer in Existing ProjectsMark Niebergall
 

Similar to Composer Best Practices.pdf (20)

Composer
ComposerComposer
Composer
 
Composer yourself: a reintroduction to composer
Composer yourself:  a reintroduction to composerComposer yourself:  a reintroduction to composer
Composer yourself: a reintroduction to composer
 
Introducing composer - a php dependency manager
Introducing composer  - a php dependency managerIntroducing composer  - a php dependency manager
Introducing composer - a php dependency manager
 
12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboards
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
 
Composer
ComposerComposer
Composer
 
Magento Docker Setup.pdf
Magento Docker Setup.pdfMagento Docker Setup.pdf
Magento Docker Setup.pdf
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NL
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
 
Dependency Management
Dependency ManagementDependency Management
Dependency Management
 
Composer intro
Composer introComposer intro
Composer intro
 
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerWordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
 
Composer
ComposerComposer
Composer
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
Leveraging Composer in Existing Projects
Leveraging Composer in Existing ProjectsLeveraging Composer in Existing Projects
Leveraging Composer in Existing Projects
 

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Composer Best Practices.pdf

  • 2. Composer: Introduction ● Composer is a tool for dependency management in PHP. ● It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
  • 3. Composer: files ❖ composer.json ➢ This file describes the dependencies of your project and may contain other metadata as well. It typically should go in the top-most directory of your project ❖ composer.lock ➢ contains all of the packages and their exact versions, locking the project to those specific versions. ❖ auth.json ➢ ~/.composer/auth.json (Global) ➢ <proj_dir>/auth.json (local) ➢ contains authentication for private repositories
  • 4. Composer: repositories ❖ A Composer repository is basically a package source: a place where you can get packages from. ❖ Packagist.org ➢ Is the main Composer repository. ➢ Aims to be the central repository that everybody uses. ❖ Packagist.com ➢ is a commercial package hosting product offering professional support and web based management of private and public packages, and granular access permissions. ❖ Github - (host your private repositories) ❖ Private Repositories - (to be discussed later)
  • 5. Composer: Frequently used commands ● composer install ● composer update ● composer update vendor/package ● composer require vendor_name/package_name ● composer require vendor_name/package_name:version
  • 6. Composer: Best Practices ● Do not run composer update on production. ● If you want to run then you have to run composer install. ● You should never use composer updatewithout argument. ● A better approach to do if composer-updateis needed: ○ Checkout on a dev environment and composer update, ○ Ensure the app is thoroughly tested on a dev environment ○ Then install on live/production with composer install
  • 7. Composer: Important Commands ● composer update --with-dependencies ○ Updates all packages and its dependencies ● composer update vendor/* ○ Updates all packages from vendor ● composer update --lock ○ Updates composer.lock hash without updating any packages ● composer remove vendor/package ○ Removes vendor/package from composer.json and uninstalls it ● composer update --no-dev ○ This causes composer to skip installing packages listed in “require-dev”. After which the “composer.autoload” file is not generated ● composer install --dry-run ○ Simulates the install without installing anything
  • 8. Composer: Important Commands ● composer outdated ○ Shows a list of installed packages that have updates available ● composer dump-autoload --optimize ○ Generates optimized autoload files ● composer self-update ○ Updates the composer.phar file to the latest version ● composer depends vendor-name/package-name ○ Tell you which other packages depend on a certain package. ● composer info ○ Show information about packages.
  • 9. Composer : Passing Version ● composer require vendor/pkg "1.3.2" ○ Installs 1.3.2 ● composer require vendor/pkg ">=1.3.2" ○ Above or equal 1.3.2 ● composer require vendor/pkg "<1.3.2" ○ Below 1.3.2 ● composer require vendor/pkg "1.3.*" ○ Latest of >=1.3.0 <1.4.0 ● composer require vendor/pkg "~1.3.2" ○ Latest of >=1.3.2 <1.4.0
  • 10. Composer : Passing Version ● composer require vendor/pkg "~1.3" ○ Latest of >=1.3.0 <2.0.0 ● composer require vendor/pkg "^1.3.2" ○ Latest of >=1.3.2 <1.4.0 ● composer require vendor/pkg "^1.3" ○ Latest of >=1.3.0 <2.0.0 ● composer require vendor/pkg "^0.3.2" ○ Latest of >=0.3.2 <0.4.0 ● composer require vendor/pkg "2.0.0-3.0.0" ○ All versions above and including 2.0.0 and below and including 3.0.0
  • 11. Tilde (~) and caret (^) version constraints in Composer The tilde sign ● ~4.1.3 means >=4.1.3,<4.2.0, ● ~4.1 means >=4.1.0,<5.0.0 (most used), ● ~0.4 means >=0.4.0,<1.0.0, ● ~4 means >=4.0.0,<5.0.0. The caret sign is slightly different: ● ^4.1.3 (most used) means >=4.1.3,<5.0.0, ● ^4.1 means >=4.1.0,<5.0.0, same as ~4.1 but: ● ^0.4 means >=0.4.0,<0.5.0, this is different from ~0.4 and is more useful for defining backwards compatible version ranges. ● ^4 means >=4.0.0,<5.0.0 which is the same as ~4 and 4.*.