blog

Enhance Your Composer Package Upgrades with These PHP Tricks

Share:

Upgrading Composer packages in a PHP project can sometimes be a challenging task, especially when dealing with compatibility issues or dependency conflicts. Here are seven tricks to help smooth the process:

Use Composer’s Interactive Mode: Composer provides an interactive mode (composer update --interactive) that allows you to selectively update packages. This is particularly useful when you want to upgrade specific packages without affecting others. It prompts you to choose which packages to update, providing a more controlled upgrade process.

composer update \ 
laravel/framework:~10.0.0 \ # allows for specific versions # allows for specific versions 
spatie/laravel-ignition:^2.0 \ 
monolog/monolog \ # can only be a reference to allow an upgrade 
spatie/ignition \ # we'll use the --with option to set a specific version
symfony/http-foundation \ 
symfony/mailer \ 
nesbot/carbon \ 
symfony/mime \ 
spatie/flare-client-php \ 
spatie/laravel-package-tools \ 
spatie/laravel-activitylog \
--with spatie/ignition:1.11.3 # our specific version for a sub dependency

Leverage Version Constraints: Specify version constraints in your composer.json file to control which versions of packages your project can use. This allows you to set boundaries for compatibility and stability. For example, you can use ^1.0 to allow updates within the 1.x range while avoiding breaking changes.

Check for Deprecated Packages: Before upgrading, check if any of the packages you’re using are deprecated or have reached end-of-life status. Deprecated packages may have alternative solutions or migration paths you should consider before upgrading.

Review Changelogs and Release Notes: Always review the changelogs and release notes of the packages you plan to upgrade. This helps you understand what changes have been made, including bug fixes, new features, and potential breaking changes. Understanding these changes can guide you in assessing the impact of the upgrade on your project.

Use Composer’s --dry-run Option: Before actually performing the upgrade, use the --dry-run option (composer update --dry-run) to simulate the upgrade process without making any changes. This allows you to see what would be updated and whether there are any potential conflicts or issues.

Find packages blocking updates. Another command that you can use before getting started is simply the why-not command. It’s also called prohibits but honestly why-not just seems more memorable!

Now Laravel 11 is days away so let’s try seeing what it will take to get this current Laravel 10 project update to date.

peterfox@Peters-MBP-2 project % composer why-not laravel/framework 11.0.0
Package "laravel/framework" could not be found with constraint "11.0.0", results below will most likely be incomplete.
laravel/laravel                        dev-main requires laravel/framework (^10.0)                              
laravel/fortify                        v1.19.1  requires illuminate/support (^8.82|^9.0|^10.0)                  
laravel/jetstream                      v4.2.0   requires illuminate/console (^10.17)                            
laravel/jetstream                      v4.2.0   requires illuminate/support (^10.17)                            
laravel/octane                         v2.2.4   requires laravel/framework (^10.10.1)                           
laravel/sanctum                        v3.3.2   requires illuminate/console (^9.21|^10.0)                       
laravel/sanctum                        v3.3.2   requires illuminate/contracts (^9.21|^10.0)                     
laravel/sanctum                        v3.3.2   requires illuminate/database (^9.21|^10.0)                      
laravel/sanctum                        v3.3.2   requires illuminate/support (^9.21|^10.0)                       
laravel/scout                          v10.6.1  requires illuminate/bus (^9.0|^10.0)                            
laravel/scout                          v10.6.1  requires illuminate/contracts (^9.0|^10.0)                      
laravel/scout                          v10.6.1  requires illuminate/database (^9.0|^10.0)                       
laravel/scout                          v10.6.1  requires illuminate/http (^9.0|^10.0)                           
laravel/scout                          v10.6.1  requires illuminate/pagination (^9.0|^10.0)                     
laravel/scout                          v10.6.1  requires illuminate/queue (^9.0|^10.0)                          
laravel/scout                          v10.6.1  requires illuminate/support (^9.0|^10.0)                        
laravel/slack-notification-channel     v3.1.0   requires illuminate/http (^9.0|^10.0)                           
laravel/slack-notification-channel     v3.1.0   requires illuminate/notifications (^9.0|^10.0)                  
laravel/slack-notification-channel     v3.1.0   requires illuminate/support (^9.0|^10.0)                        
laravel/tinker                         v2.8.2   requires illuminate/console (^6.0|^7.0|^8.0|^9.0|^10.0)         
laravel/tinker                         v2.8.2   requires illuminate/contracts (^6.0|^7.0|^8.0|^9.0|^10.0)       
laravel/tinker                         v2.8.2   requires illuminate/support (^6.0|^7.0|^8.0|^9.0|^10.0)         
livewire/livewire                      v3.3.3   requires illuminate/database (^10.0)                            
livewire/livewire                      v3.3.3   requires illuminate/support (^10.0)                             
livewire/livewire                      v3.3.3   requires illuminate/validation (^10.0)                          
openai-php/laravel                     v0.4.3   requires laravel/framework (^9.46.0|^10.7.1)                    
spatie/laravel-ignition                2.3.2    requires illuminate/support (^10.0)                             
spatie/laravel-package-tools           1.16.1   requires illuminate/contracts (^9.28|^10.0)                     
spatie/laravel-ray                     1.33.0   requires illuminate/contracts (^7.20|^8.19|^9.0|^10.0)          
spatie/laravel-ray                     1.33.0   requires illuminate/database (^7.20|^8.19|^9.0|^10.0)           
spatie/laravel-ray                     1.33.0   requires illuminate/queue (^7.20|^8.19|^9.0|^10.0)              
spatie/laravel-ray                     1.33.0   requires illuminate/support (^7.20|^8.19|^9.0|^10.0)            
spatie/laravel-webhook-client          3.2.0    requires illuminate/bus (^8.50|^9.0|^10.0)                      
spatie/laravel-webhook-client          3.2.0    requires illuminate/database (^8.50|^9.0|^10.0)                 
spatie/laravel-webhook-client          3.2.0    requires illuminate/support (^8.50|^9.0|^10.0)                  
teamtnt/laravel-scout-tntsearch-driver v12.5.0  requires illuminate/bus (~5.4|^6.0|^7.0|^8.0|^9.0|^10.0)        
teamtnt/laravel-scout-tntsearch-driver v12.5.0  requires illuminate/contracts (~5.4|^6.0|^7.0|^8.0|^9.0|^10.0)  
teamtnt/laravel-scout-tntsearch-driver v12.5.0  requires illuminate/pagination (~5.4|^6.0|^7.0|^8.0|^9.0|^10.0) 
teamtnt/laravel-scout-tntsearch-driver v12.5.0  requires illuminate/queue (~5.4|^6.0|^7.0|^8.0|^9.0|^10.0)      
teamtnt/laravel-scout-tntsearch-driver v12.5.0  requires illuminate/support (~5.4|^6.0|^7.0|^8.0|^9.0|^10.0)    
Not finding what you were looking for? Try calling `composer require "laravel/framework:11.0.0" --dry-run` to get another view on the problem.

This gives us a nice list to work with that allows us to sign off which packages we might need to look at. Equally we can try upgrading these one by one until hopefully none of them show up anymore. For instance if I try just a slightly newer version of Laravel 10, here’s what I get:

peterfox@Peters-MBP-2 project % composer why-not laravel/framework 10.43.0
There is no installed package depending on “laravel/framework” in versions not matching 10.43.0
Not finding what you were looking for? Try calling `composer require “laravel/framework:10.43.0” — dry-run` to get another view on the problem.

Test in a Staging Environment: It’s essential to test the upgraded packages in a staging environment before deploying the changes to production. This allows you to identify and address any compatibility issues or unexpected behavior before it impacts your users.

Utilize Composer Plugins: There are several Composer plugins available that can assist with package upgrades. For example, hirak/prestissimo speeds up Composer installations, composer-merge-plugin allows you to merge multiple composer.json files, and consolidation/composer provides additional commands and utilities for managing Composer dependencies.

By employing these tricks, you can streamline the process of upgrading Composer packages in your PHP projects while minimizing the risk of compatibility issues and downtime.

Fill-in the form below to reach out to us with your project👇

Related articles

Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon

get in touch

EVEN IF YOU DON'T YET KNOW WHERE TO START WITH YOUR PROJECT - THIS IS THE PLACE

Drop us a few lines and we'll get back to you within one business day.

Thank you for your inquiry! Someone from our team will contact you shortly.
Where from have you heard about us?
Clutch
GoodFirms
Crunchbase
Googlesearch
LinkedIn
Facebook
Your option
I have read and accepted the Terms & Conditions and Privacy Policy
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
slash icon
slash icon
slash icon
slash icon
slash icon
slash icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon