How to use global composer.json when create project in Composer? - composer-php

I have add the following config, and if I reqiure global package, all is Okey. Every packages will be installed from mirrors.aliyun.com
composer global config repo.packagist composer https://mirrors.aliyun.com/composer/
and content from ~/.composer/composer.json
{
"require": {
"laravel/installer": "^4.0",
"laravel/valet": "^2.11"
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
}
}
But if I create project with composer like this, I found package downloading from https://repo.packagist.org/packages.json
composer create-project --prefer-dist laravel/laravel sample.com -vvv
I need to download from mirror, but the config in global composer.json is ignored, anyone knows why is that?
Here is some related logs
Reading /Users/jack/.composer/composer.json
Loading config file /Users/jack/.composer/config.json
Loading config file /Users/jack/.composer/auth.json
Loading config file /Users/jack/.composer/composer.json
Loading config file /Users/jack/.composer/auth.json
Reading /Users/jack/.composer/auth.json
Reading /Users/jack/.composer/vendor/composer/installed.json
Creating a "laravel/laravel" project at "./sample.com"
Downloading https://repo.packagist.org/packages.json
UPDATE # 19:55
I add --repository parameter, then the laravel/laravel template is downloaded from mirror repository
composer create-project laravel/laravel sample.com --prefer-dist --repository=https://mirrors.aliyun.com/composer/ -vvv
But after downloading laravel/laravel, still download from Packagist, here are some related logs
Reading /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/config.json
Loading config file /Users/cuimingda/.composer/auth.json
Loading config file /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/vendor/composer/installed.json
Creating a "laravel/laravel" project at "./api.mingda.net"
Downloading https://mirrors.aliyun.com/composer/packages.json
Installing laravel/laravel (v7.25.0)
Created project in /Users/cuimingda/Sites/api.mingda.net
Reading ./composer.json
Reading /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/config.json
Loading config file /Users/cuimingda/.composer/auth.json
Loading config file /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/vendor/composer/installed.json
> post-root-package-install: #php -r "file_exists('.env') || copy('.env.example', '.env');"
Executing command (CWD): '/usr/local/Cellar/php/7.4.8/bin/php' -d allow_url_fopen='1' -d disable_functions='' -d memory_limit='1536M' -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Downloading https://repo.packagist.org/packages.json

I just found the answer myself.
DO NOT USE the follow methods to set mirror, because they will modify ~/.composer/composer.json, and composer.json will not work when create project
composer global config repo.packagist composer https://mirrors.aliyun.com/composer/
RIGHT WAY - Manually put the following code to ~/.composer/config.json, and whether composer global require or composer create-project, they all will fetch files from mirror site, not packagist.org
{
"config": {},
"repositories": [
{
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
},
{
"packagist": false
}
]
}
There is no need to add any repositories related configto ~/.composer/composer.json
{
"require": {
"laravel/installer": "^4.0",
"laravel/valet": "^2.11"
}
}

Related

composer is not updateing dependancy with lumen

I am using php 5.6.12 version,
I have to compulsory use this version.
running command : composer update
it is showing me like below,
Loading composer repositories with package information
Updating dependencies (including require-dev)
It is showing this only this since long time, not updates any dependancy of my packages
my composer.json file package as below,
"require": {
"php": ">=5.5.9",
"laravel/lumen-framework": "5.2.*",
"vlucas/phpdotenv": "~2.2",
"google/apiclient": "^2.0",
"maatwebsite/excel": "~2.1.0",
"googleads/googleads-php-lib": "^32.1",
"aws/aws-sdk-php-laravel": "~3.0",
"baopham/dynamodb": "^4.11",
"laravelista/lumen-vendor-publish": "^2.1",
"jenssegers/mongodb": "3.2.*",
"php-imap/php-imap": "^3.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~5.0",
"mockery/mockery": "~0.9"
},
I have run composer update -vvv command , it gives me below error,
Reading ./composer.json
Loading config file ./composer.json
Checked CA file E:\xampp7\apache\bin\curl-ca-bundle.crt: valid
Executing command (E:\xampp563\htdocs\delrentals-dashboard-api): git branch --no-color --no-abbrev -v
Failed to initialize global composer: Composer could not find the config file: C:/Users/hetal.gohel/AppData/Roaming/Composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Running 1.7.2 (2018-08-16 16:57:12) with PHP 7.0.27 on Windows NT / 6.1
Loading composer repositories with package information
Downloading https://repo.packagist.org/packages.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/packages.json into cache
Updating dependencies (including require-dev)
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2013.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2014.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2015.json from cache
Downloading http://repo.packagist.org/p/provider-2016%2421f5855cc4abf8648b47c77d76fee501bfc9fd4d893d6a602e8c8dbd0c4ea0ff.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2016.json into cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2017.json from cache
Downloading http://repo.packagist.org/p/provider-2018-01%24ebbeedf5cdf822efb5bb90b0b147c964df3e11e74d453bbdb6b04b537c180a7e.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-01.json into cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-04.json from cache
Downloading http://repo.packagist.org/p/provider-2018-07%240016a26f1005f0fb0be2f409b3fc05dde3132eb7694bc50e386e2a6be4802ee6.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-07.json into cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-10.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-archived.json from cache
Downloading http://repo.packagist.org/p/provider-latest%242eb9ff7604840d5f7b019a1d5770e987526594ecf1528f5fe6b613654914d5c4.json
......
I have create composer.json file with empty object "{}"
in location C:\Users\hetal.gohel\AppData\Roaming\Composer
Loading config file ./composer.json
Checked CA file E:\xampp7\apache\bin\curl-ca-bundle.crt: valid
Executing command (E:\xampp563\htdocs\delrentals-dashboard-api): git branch --no-color --no-abbrev -v
Reading C:/Users/hetal.gohel/AppData/Roaming/Composer/composer.json
Loading config file C:/Users/hetal.gohel/AppData/Roaming/Composer/composer.json
Running 1.7.2 (2018-08-16 16:57:12) with PHP 7.0.27 on Windows NT / 6.1
Loading composer repositories with package information
Downloading https://repo.packagist.org/packages.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/packages.json into cache
Updating dependencies (including require-dev)
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2013.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2014.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2015.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2016.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2017.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-01.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-04.json from cache
Downloading http://repo.packagist.org/p/provider-2018-07%24456764a723221fb097b4ae41ef2ce7d91d1207de7b45ed8301c2e0bf1c55387e.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-07.json into cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-2018-10.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-archived.json from cache
Downloading http://repo.packagist.org/p/provider-latest%245fb6a563ef29d0728dfbcf5cc60a8e56619893d5635943fb610b74eb55281719.json
Writing C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/p-provider-latest.json into cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/provider-laravel$lumen.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/provider-laravel$lumen-framework.json from cache
Reading C:/Users/hetal.gohel/AppData/Local/Composer/repo/https---repo.packagist.org/provider-illuminate$auth.json from cache
.....
It gives still error
Ok let me summarize.
Create a composer.json file in C:/Users/hetal.gohel/AppData/Roaming/Composer/composer.json. Just fill it with an empty json object {}. And then run composer update -vvv to see the update process in detail. Just wait until it's done. If the update process takes too long may be you should add the package dependency one by one.

Configure composer to get data from packagist.org via https

When building files in an environment that blocks outbound http requests, I get an error like:
Updating dependencies (including require-dev)
The "http://packagist.org/p/provider-2013%ahash.json" file could not be downloaded: failed to open stream: Connection timed out
http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
Is there some way to instruct composer to use https connection to packagist?
I've experienced the issue with both 1.2.0 and 1.6.5 versions of composer.
You can either force composer to use https by:
composer config -g repo.packagist composer https://packagist.org
Or you could set in your composer.json file:
"repositories": [
{
"type": "composer",
"url": "https://packagist.org"
},
{ "packagist": false }
]
Source: issue #5656 on composer's github repository.

Composer clones from cache instead of repo

I have two projects I am working on, both were setup as git repos, both use composer.
First project uses second as a library.
I configured composer.json in the following way:
... "repositories": [
{"type": "composer", "url":"http://composer.myrepourl.com/repo/private/"},
]
"require": {
"second/second": "dev-B-3"
} ...
There was no problem pulling the project from a repository for the first time. However now I made some changes in second project, pushed to the repo and now want to have them in first project, but for some reason composer pulls from the cache.
I ran composer clear-cache. I tried deleting: vendor folder, /home/user/.composer/cache, cache inside container /root/.composer/, but it still finds a way to clone the second project from cache instead of pulling it from repo.
Any ideas on how to force composer to always pull from repo instead of cloning from cache?
Run
$ composer install --prefer-source
Alternatively, specify your preferred installation method in composer.json generally:
{
"config": {
"preferred-install": "source"
}
}
or specifically for the desired dependency
generally:
{
"config": {
"preferred-install": {
"vendor/package": "source",
"*": "dist"
}
}
}
For reference, see:
https://getcomposer.org/doc/03-cli.md#install
https://getcomposer.org/doc/06-config.md#preferred-install
you should run
composer clear-cache
then
composer update --prefer-source
Ok I have found a solution:
sudo rm -r /home/user/project/vendor
cd %wherever_your_docker_is%
docker-compose stop
docker-compose rm
docker-compose up -d
composer update

Composer: nothing to install or update

I want install this.
I installed composer, set the environment variable path in w10.
Edit the composer.json located in this folder:
C:\Bitnami\wampstack-5.5.29-1\php\PEAR
with this content:
{
"name":"amazonwebservices/aws-sdk-for-php",
"description":"AWS SDK for PHP",
"keywords":["aws","amazon","sdk","s3","ec2","dynamodb"],
"type":"library",
"license":"Apache-2.0",
"authors":[
{
"name":"Amazon Web Services",
"homepage":"http://aws.amazon.com"
}
],
"homepage": "http://aws.amazon.com/sdkforphp/",
"require":{
"php":">=5.2.0"
},
"autoload":{
"classmap": [
"authentication/",
"extensions/",
"lib/",
"services/",
"utilities/",
"sdk.class.php"
]
}
}
{
"require": {
"katzgrau/klogger": "dev-master"
}
}
but when I execute this command in my console:
composer require katzgrau/klogger:dev-master
I get:
nothing to install or update
what I did wrong?
You are reusing the composer.json file of "aws-sdk-for-php".
That is probably not your project. And you are in the wrong folder (PEAR).
Don't copy and paste composer.json files... anyway:
Create a new project folder
then simply run composer require katzgrau/klogger:1.2.0
You'll get all dependencies fetched into the vendor folder and a fresh composer.json file for your project.

Yii2 Error: yii\base\UnknownMethodException: Calling unknown method: yii\web\UrlManager::addRules()

After todays update of composer dependencies (with composer update command) my Yii2 application became broken - It throws Unknown Method – yii\base\UnknownMethodException: Calling unknown method: yii\web\UrlManager::addRules()
After inspecting vendor/yiisoft/yii2/web/UrlManager.php file I found that there is no method addRule.
And the whole entire class UrlManager is different from the class in the repository.
My composer.json:
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "*",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"yiisoft/yii2-gii": "2.0.0-beta",
"claudejanz/yii2-mygii": "*",
"kartik-v/yii2-grid": "dev-master",
"kartik-v/yii2-builder": "dev-master",
"2amigos/yii2-switch-widget": "*",
"yiisoft/yii2-jui": "*",
"DsXack/yii2-underscore": "*",
"2amigos/yii2-editable-widget": "*",
"warrence/yii2-kartikgii": "*"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*"
},
I think they have changed the way some libraries are loaded through composer.
To solve it:
Add to composer.json
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
and run:
# php composer.phar global require "fxp/composer-asset-plugin:1.0.*#dev"
# php composer.phar update --dev
More info: Issue on Github and Issue on Github
Full credit to: #githubjeka and #SonicGD
Here is an explaination of why this happened:
I think this is again the composer dependency resolver doing unexpected things:
you require yiisoft/yii2 in your composer.json but do not have the composer asset plugin installed.
then the dependency resolver does not find packages with vendor bower-asset so it looks for other versions of yiisoft/yii2 that do not have conflict
The result is to install the beta version of yii2 to be installed
The correct solution as already mentioned is to install the composer-asset-plugin:
php composer.phar global require "fxp/composer-asset-plugin:1.0.*#dev"
It seems the update went totally wrong, since the files are different from the ones on github - several functions missing.
What i had to do to get "rid" of this error:
Copy the code from the repository in your local files:
https://github.com/yiisoft/yii2/blob/master/framework/web/UrlManager.php
https://raw.githubusercontent.com/yiisoft/yii2/master/framework/helpers/BaseHtml.php
This solved it for the moment for me.
Like ricardgf says, read this:
https://github.com/yiisoft/yii2/blob/master/docs/guide/start-installation.md
then run:
composer.phar global require "fxp/composer-asset-plugin:1.0.*#dev"
and
composer.phar update --prefer-source --no-interaction
ok I solved the problem installing yii2 in this way :
composer global require "fxp/composer-asset-plugin:1.0.*#dev"
composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
Try to update your composer.json into following way:
"require": {
"yiisoft/yii2": "*"
},
in project directory, write this command-
php composer.phar update

Resources