i am working on multiple composer packages and a application which dose requries all the packages that i develop.
I would like to know how i can have a package with multiple version
stable version for production
development / master version for local development
i tried following config but it din't work
{
"minimum-stability" : "dev",
"require" : {
"varunsridharan/vsp-framework" : "^1.0",
"wponion/wponion" : "^1.0"
},
"require-dev" : {
"varunsridharan/vsp-framework" : "dev-master",
"wponion/wponion" : "dev-development"
}
}
When i run composer install or composer install --no-dev i get the below output
Loading composer repositories with package information
Updating dependencies
[Composer\DependencyResolver\SolverProblemsException]
Problem 1
- The requested package varunsridharan/vsp-framework ^1.0 exists as varunsridharan/vsp-framework[dev-master] but these are rejected by your constraint.
Problem 2
- The requested package wponion/wponion ^1.0 exists as wponion/wponion[dev-development] but these are rejected by your constraint.
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-author
itative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...
Reason why composer has require and require-dev is to allow developers install packages that will allow them better debugging by using packages that are not suggested to be used in production. By adding a package on require-dev this package will not be required on production.
Ex. If you want to optimize you queries, see if you have any n+1 query problem etc you might want to install php-debugbar that will show you this info, but having this on production might expose your queries and will give sensitive info to bad guys.
Packages included on require will always be installed in development and in production and this is the reason you see the error The requested package xxxxx exists as xxxxx[dev-development] but these are rejected by your constraint.
To have different packages in DEV and PROD you need different composer.json files for each environment like #George said.
You can have one composer.json file that will be the production composer and one composer-dev.json that you can use for development.
On your local environment you will need to set value of COMPOSER env variable to composer-dev.json.
Simple way to do this is by running composer like this: COMPOSER=composer-other.json php composer.phar install
If you want to require a new packages you need to run the command twice, one time normally and one time by adding COMPOSER=composer-other.json before composer, to ensure that the package will be added both in dev and production.
P.S I do not know the reason why you need different packages for development and production, but it is suggested to have the same version of packages in dev and prod as having different versions might bring up bugs
You can try changing composer.json file in your dev environment. See Composer
COMPOSER=composer-dev.json php composer install
Reference Composer - specify `composer.json` path
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!!
Since a few days i cant install composer-packages anymore in my local docker container.
I create new composer.json with composer init and try to add a package with composer require fzaninotto/faker
Always i get the same error message
# composer require fzaninotto/faker
Using version ^1.9 for fzaninotto/faker
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
Failed to download fzaninotto/faker from dist: The zip extension and unzip command are both missing, skipping.
Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
Now trying to download from source
- Installing fzaninotto/faker (v1.9.1): Cloning fc10d778e4 from cache
fc10d778e4b84d5bd315dad194661e091d307c6f is gone (history was rewritten?)
Installation failed, reverting ./composer.json to its original content.
[RuntimeException]
Failed to execute git checkout 'fc10d778e4b84d5bd315dad194661e091d307c6f' -- && git reset --hard 'fc10d778e4b84d5bd315dad194661e091d307c6f' --
fatal: failed to read object fc10d778e4b84d5bd315dad194661e091d307c6f: Operation not permitted
require [--dev] [--prefer-source] [--prefer-dist] [--fixed] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...
First i guess my ssh key is the problem but i create a new one and add this to github with the same error.
Than i try it with composer clear and the problem don't resolved.
The problem come in EACH docker container and EACH composer packages... so i cant be a problem with single packages or container.
Have anyone an idea that i can do to use composer again?
If you're using Docker Desktop (Windows) and you updated to the latest version 2.2.0.4, then you get this issue.
Downgrade to the 2.2.0.3 and it should work again (at least it did for me).
See: https://forums.docker.com/t/issues-after-upgrading-docker-desktop-to-2-2-0-4/90589
To downgrade:
Uninstall Docker Desktop. Attention: it will delete your containers, save them before if you want to import them back
Go this page: https://docs.docker.com/docker-for-windows/release-notes/
Click Download under 2.2.0.3
Install Docker Desktop with the installer file
When started it will ask to upgrade to 2.2.0.4, just say "Skip this build"
I didn't have enough points to comment on the top answer but the Docker issue was just closed (like an hour ago!) and so simply updating Docker Desktop on Windows should fix it. Worked for me at least. Now I can install Drupal again!
Good day people, I have been having this problem for days now, when I try to download dependencies for my php project using composer I get this error
c:\wamp64\www\Test>composer global require "fxp/composer-asset-plugin:^1.3.1"
Changed current directory to C:/Users/Nwachukwu Favour/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Installation failed, reverting ./composer.json to its original content.
[Composer\Downloader\TransportException]
The "http://packagist.org/p/provider-2014%241cf88bd0ed4076dc091407477ba2a76483e8598ee5365673381262e6c1d40fcf.jso
n" file could not be downloaded: failed to open stream: HTTP request failed!
require [--dev] [--prefer-source] [--prefer-dist] [--no-plugins] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...
I am running a windows 10 OS and am suspecting that my system cannot download from the command line. I would be very glad if someone can help me solve this problem because it is hindering my project. Thanks in advance.
You could also run this command on the CLI before installing any dependencies. It forces composer to use https to download all resources:
composer config -g repo.packagist composer https://packagist.org
The issue could be caused by the redirect from http to https. (or your firewall blocking the call)
According to this article the problem could be solved by adding the following to your composer.json:
"repositories": [
{
"type": "composer",
"url": "https://packagist.org"
},
{ "packagist": false }
]
Forcing composer to use https connections to Packagist
I just updated my composer to the latest version and this problem is solved.
Try
composer self-update
To know the current version and update details:
composer diagnose
I tried the command below and it worked.
composer config -g repo.packagist composer https://packagist.org
This is just one of the options given above.
I found enabling OpenSSL extension in the php.ini-development/production file fixed the problem.
Its located within your PHP install
just stop your antivirus software :)
for some reason antivirus software kaspersky doesn't like composer :(
I had the same error tried everything... nothing worked.
I remembered I had issues with composer in the past while my AV was on... turned it off and composer worked like a charm :)
just put this in command
composer config -g repo.packagist composer https://packagist.org
Update or Delete your 'http_proxy' variable.
Delete composer
Install Composer again
Restart your machine.
Your are good to go.
try with composer diagnose and after that composer update -vvv
I had the same error, but it was resolved in a different way for me. I used to give sudo to composer commands because folder /home/aspire/.composer is in sudo permission. I changed it to sudo chown $USER /home/aspire/.composer.
I changed the permissions as I mentioned and I ran the code
sudo composer require symfony/orm-pack
Throws error
[Composer\Downloader\TransportException]
The "https://repo.packagist.org/packages.json" file could not be downloaded:
Then I tried
composer require symfony/orm-pack
It works
If anyone know the exact reason, please comment
if you are in china like me,try this:https://developer.aliyun.com/composer
github connection not stable recently.I tryed https://pkg.phpcomposer.com/ first but don't work. I tryed composer diag and composer -vvv and wait.out put show cache file is :Writing C:/Users/Administrator.000/AppData/Local/Composer/repo.so i copy cache file from my colleague,and it works first,laravel run,but composer require show 404.then i found the solution above.try composer update -lock and change the repositories url to ali's.And solved.
This problem happened to me, and I solved it by turning off the firewall.
This is one of the solutions.
If you have http_proxy environment variable, just delete it from either User variables or System variable and save yourself from all this trouble.
How do I install/enable PHP extension mbstring?
Heroku on its documentation says it's shared by default, and should be enabled once a Composer package require it. I tried adding it in composer.json file but nothing changed.
This is my project's composer.json:
{
"require": {
"fabpot/goutte": "^3.2",
"guzzlehttp/guzzle": "^6.2",
"paquettg/php-html-parser": "^1.7",
"ext-mbstring": "*"
}
}
After adding last dependency, I ran:
heroku run composer update
This is the error message I got:
The requested PHP extension ext-mbstring * is missing from your system. Install or enable PHP's mbstring extension.
Thank you
Heroku's filesystem is ephemeral. Any changes you make to it after your Dyno spins up can be lost at any time. This happens at least once per day, and possibly much more frequently.
Additionally, composer update is something that I would advise against running on a server. This command installs the newest available version of each library (or specific ones if you only update specific libraries) that fits what's in composer.json. If you ask for ~1.2 in composer.json you might get 1.2.1 on your development machine, but 1.2.9 in production. This can lead to some tricky bugs.
The composer install command installs the exact versions that are defined in your composer.lock file. It is much safer to run on a server, but it does mean that you've got to update your lock file locally and push it to your server.
For both of these reasons you should run composer update locally. This will update composer.lock, which should then be committed and pushed to Heroku. Heroku will run composer install, and you should be all set.
(Alternatively, you should also be able to run composer update 'ext-mbstring' to leave the rest of your dependencies alone. Be careful with composer update, and try to get in the habit of using composer install unless you know you need to update some of your dependencies.)
I am using Symfony 2.3.4
On my console i did composer create-project sylius/sylius --prefer-dist
Everything downloaded smoothly until it came to installing sensio/distribution-bundle
Composer throw out this error message
[Composer\Downloader\TransportException]
The "https://api.github.com/repos/sensio/SensioDistributionBundle/zipball/4
a2c803dc8db79952ad5e71783c16178427bbc02" file could not be downloaded (HTTP
/1.1 404 Not Found)
create-project [-s|--stability="..."] [--prefer-source] [--prefer-dist] [--repos
itory-url="..."] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--n
o-scripts] [--no-progress] [--keep-vcs] [package] [directory] [version]
I tried :
Editing sylius/composer.json and modify "sensio/distribution-bundle": "2.3." to "sensio/distribution-bundle": "2.2.-dev"
Open a shell in C:\wamp\www\sylius. Rename app/config/parameters.yml.dist to parameters.yml, run php composer.phar update --prefer-dist, still having lots of errors about MongoDb
Is there any other way to install sylius?
How can i fix this?
Thanks heaps
It seems that sylius build in 0.1.0 is broken. If you want functional sylius installation you have to use dev-master version.
composer create-project sylius/sylius sylius dev-master
They fixed the issue! The problem was indeed with the Sylius build. Today i created a freshly installed Symfony2 onto my server, and did composer composer create-project sylius/sylius --prefer-dist
Sensio/SensioDistributionBundle installed correctly.
Steps to installed Sylius
1. composer create-project sylius/sylius --prefer-dist (this method download compressed file when available) or composer create-project -s dev sylius/sylius
make sure to enable php_info extension
create a database in php myadmin
cd sylius and then php app/console sylius:install
The last part of the installation will asked you for some parameters, the default option given works fine. Accustomed it to your config
I spend 48 hours trying to install sylius finally things got better now.
There is many issues with Sylius at the moment. Check Out And is really slow. I am still finding a way to speed things up. I took like 3 minutes to load when i clicked on Register.
If you got issued like MongDB not found, or any bundle not found, then surely there is a problem with the way you are trying to install Sylius. And Please at the moment do not cd sylius and composer update, it won't worked. I got told that they rearranged the bundle.
You can find more detailed Click here!
Please feel free to edit this post if you feel that there is something that i haven't talked about for sylius installation.
Thanks to Sylius Contributors!