i wanted to install the following packages for the Symfony Framework 3.4 with help of the composer package manager:
friendsofsymfony/http-cache-bundle
guzzlehttp/psr8
php-http/guzzle6-adapter
I dont have much experience with composer. I saw that those packages are installable under Symfony 3.4 in a tutorial. I even tried installing every component of the bundle one by one, quitting with the bellow error message for example (guzzlehttp/psr7). When installations failed why are the packages then in my composer.json file under require ?
Here is my composer.json:
"require": {
"php": ">=7.1.3",
"friendsofsymfony/http-cache": "^2.5.2",
"friendsofsymfony/http-cache-bundle": "^2.6",
"guzzlehttp/psr7": "^1.5",
"php-http/guzzle6-adapter": "^2.0",
I am getting this error message:
Errror message
Error message installing (guzzlehttp/psr7):
Errror message
Thanks in advance.
You executed composer update, so probably you have added packages manually in the composer.json
composer update won't change what is inside composer.json.
upgrade: Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
See https://getcomposer.org/doc/01-basic-usage.md for mroe details.
Shortcut for "add if possible" is the command composer require
Exmaple:
composer require friendsofsymfony/http-cache
This will try to install the package. composer.* files will be updated only on successful installation.
Related
This question already has answers here:
Composer: how can I install another dependency without updating old ones?
(5 answers)
Closed 2 years ago.
I want to install zizaco/entrust package in laravel 5.8, in their github page it was said to include "zizaco/entrust": "5.2.x-dev" in composer.json file and run composer update command. I did so as below and ran composer update command.
"require" : {
"php" : "^7.1.3",
"fideloper/proxy" : "^4.0",
"laravel/framework" : "5.8.*",
"laravel/tinker" : "^1.0",
"laravel/ui" : "^1.2",
"maatwebsite/excel" : "^3.1",
"zizaco/entrust" : "5.2.x-dev"
},
but composer update command updates all packages to latest versions (these packages i included in "require" field as above) when installing zizaco/entrust package. So is if there are some coding faults in latest updated packages then whole site can break. FYI after i run the above command i see local git showing changes in many files in folders under vendor folder, it means that there are some updates in packages right?. so it's recommended that composer install command should be run so that those dependency packages will not be updated to latest versions.
So, in my case after including "zizaco/entrust": "5.2.x-dev" in require field in composer.json as above, if i run composer install then it don't install zizaco/entrust package. Furthermore, if i run composer require zizaco/entrust 5.2.x-dev then it still installs latest versions of dependency packages.
So how do i prevent installing latest versions of dependency packages i included in "require" field in composer.json file and i only install zizaco/entrust package.
So that my laravel 5.8 site don't break for updating any packages to latest versions because of malfunction codes or whatever in latest versions. It's very important to handle this scenario because we need to install packages in laravel site for various needs.
You've got two options: use composer require to specify the package to install, or manually update your composer.json file and use composer update [package].
Composer Require
composer require zizaco/entrust:5.2.x-dev
This will automatically update your composer.json file and install the specified version. This will not update any of your other dependencies. While the documentation specifies the package and version should be separated by a colon (:), I tested it with a space and it seemed to work.
Composer Update [package]
composer update zizaco/entrust
If you have manually updated your composer.json file, you will need to run composer update and specify the package to update. If you specify a package to update, only that package will be affected. When you don't specify the package to update, composer will look for updates for all packages.
A Note On Composer Install
composer install will not help you here. If you already have a composer.lock file (which you will since you're just attempting to add a new package), composer install will only look at your composer.lock file and attempt to install everything that is defined there. That means, if you manually update your composer.json file, and run composer install, it will not install the new requirement you specified.
Only when you don't already have a composer.lock file will composer install attempt to resolve dependencies and install them.
Run composer install instead. Alternatively you could use composer require <package name>.
Composer install looks in your composer.lock for exact versions, and only in composer.json for packages that are missing.
Composer update will look in composer.json for version constraint which roughly means "a range of versions". This is why different versions are getting installed.
Step 1:
You just need to add your package to the composer.json file and run the command:
composer install
composer install will check for the new package and install that, besides that it will check for any deprecation in other packages.
Step 2:
You can directly run your command in composer
composer require package/name
For example, if I need to install firebase, run below command from the project root:
composer require firebase/php-jwt
Installing new packages from the terminal automatically adds it into the composer.json file and it does not update previously installed packages.
Hope this helps!!
I have been trying to deploy a php app on heroku but I keep getting this error:
-----> PHP app detected
-----> Bootstrapping...
-----> Installing platform packages...
ERROR: neither your composer.json 'require' section nor any
dependency therein requires a runtime version, but 'require-dev'
or a dependency therein does. Heroku cannot automatically select
a default runtime version in this case.
Please add a version requirement for 'php' to section 'require'
in composer.json, 'composer update', commit, and deploy again.
! ERROR: Couldn't load 'composer.lock'; it must be a valid lock
file generated by Composer and be in a consistent state.
Check above for any parse errors and address them if necessary.
Run 'composer update', add/commit the change, then push again.
! Push rejected, failed to compile PHP app.
! Push failed
anyone know how I can solve it?
So this is what I would look at, and sorry if any of these assumptions are wrong, or I am going through stuff you have already done.
Your composer.json should be divided up into require and require-dev. Require would be installed in production with require-dev added locally.
{
"name": "something/something",
"description": "A description of my project",
"type": "project",
"require": {
"php": ">=5.5.9",
"doctrine/cache": "1.4.*",
"elasticsearch/elasticsearch": "~2.0",
"monolog/monolog": "~1.0",
"knplabs/github-api": "~1.2",
"ezyang/htmlpurifier": "~4.6",
"easyrdf/easyrdf": "0.9.*",
"hoa/compiler": "~2.15",
"hoa/visitor": "~1.15",
"collectiveaccess/service-wrapper": "v1.1",
"phpoffice/phppresentation": "dev-master",
"phpoffice/phpword": "v0.13.*"
},
"require-dev": {
"phpunit/phpunit": "4.3.*",
"maximebf/debugbar": ">=1.0.0"
}
}
If you have not got composer installed you need to do so. https://www.hostinger.com/tutorials/how-to-install-composer
Run php composer install in the first instance of php composer update later on to install your dependencies.
Please commit everything except, the vendor files and any cache or logging. This would include composer.lock which is a list of installed dependencies and the versions you are using.
Heroku will install these dependencies in production making sure it uses the same version as specified in the lock file.
I want to use the Mailgun service in Laravel 5. This requires Guzzle 5 to be installed. I've added the following to composer.json, and installed it:
"guzzlehttp/guzzle": "~5.0"
However, my app is giving me this error:
FatalErrorException in MailgunTransport.php line 121:
Class 'GuzzleHttp\Client' not found
I've ran composer dump-autoload. What am I missing? Thanks.
I solve this by using:
"laravel/framework": "5.0.16",
"guzzlehttp/guzzle": "5.2",
composer update
and that is all.
composer install installs the packages (including exact versions) listed in composer.lock. When adding a new package or changing the version requirements, you need composer update (or you can use composer require) as the new package isn't in the lock file yet.
Running composer install when the composer.json has been updated since the last update/require should generate a warning saying Warning: The lock file is not up to date with the latest changes in composer.json, you may be getting outdated dependencies, run update to update them.
recently I've started one project and want to use elasticsearch. But when I want to install guzzle for PHP via composer, I get folowing error. I have no idea what is this error.
My composer required packages are:
"require":{
"yiisoft/yii":"1.1.14",
"2amigos/yiiwheels":"1.0.3",
"clevertech/yii-booster": "4.0.1",
"drmabuse/yii-bootstrap-3-module": "dev-master",
"guzzle/guzzle": "3.9.0",
"elasticsearch/elasticsearch": "1.2.2"
},
my PHP Version 5.4.7
my composer.json file
I had no problem installing all the packages from your requirements in one go.
If the problem persists, try to delete the vendor folder and the composer.lock file and run composer update again.
I am reading this official facebook https://developers.facebook.com/docs/php/gettingstarted/4.0.0 page.
I want to add the facebook sdk to my project
I tried to do this:
composer require facebook/php-sdk in the root of my project and I got this
Warning: This development build of composer is over 30 days old. It is recommend
ed to update it by running "C:\ProgramData\ComposerSetup\bin\composer.phar self-
update" to get the latest version.
Please provide a version constraint for the facebook/php-sdk requirement: **4**
as you see, I have chosen 4, then I got this error message:
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package facebook/php-sdk could not be found in any version,
there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your min
imum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> f
or more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common
problems.
Installation failed, reverting ./composer.json to its original content.
why is that please? notice please that I didn't add anything to my composer.json.
I opened the composer.json and I found this line:
"require": {
"laravel/framework": "4.2.*"
},
so should I change it to :
"require": {
"laravel/framework": "4.2.*",
"facebook/php-sdk-v4" : "4.0.*"
},
or should I keep it and add a new require entity like this:
"require" : {
"facebook/php-sdk-v4" : "4.0.*"
}
just try and add facebook/php-sdk-4 to your existing require hash and then run composer update.
"require": {
"laravel/framework": "4.2.*",
"facebook/php-sdk-v4" : "4.0.*"
}