Configure composer to get data from packagist.org via https - composer-php

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.

Related

Laravel installation problem (by using composer on windows)

I am trying to install laravel on windows by using composer, and got this error:
"[Composer\Downloader\TransportException]
curl error 7 while downloading https://repo.packagist.org/p2/laravel/laravel.json: Failed to connect to 127.0.0.1 port 9999: Connection refused"
You could also run this command on the CLI before installing any dependencies. It forces the composer to use HTTPS to download all resources:
composer config -g repo.packagist composer https://packagist.org
Or if your problem is not resolved:
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 }
]
FMI: http://codinginharmony.blogspot.com/2012/10/forcing-composer-to-use-https.html#comment-form

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

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"
}
}

Composer can't access local Satis server

I am hosting a Satis Private Repository currently on my local machine while I do some debugging and testing. I have added a repository too which currently just contains a project on GitLab which included a composer package.
Currently it is being pulled from a docker image, and is hosted at localhost:8002.
My repository is setup in my Laravel project as follows:
"repositories": [
{ "packagist": false },
{
"type": "composer",
"url": "http://localhost:8002/packages.json"
}],
And if I navigate to that URL in my browser I get the following output:
{
"packages": [],
"includes": {
"include/all$949e06d91b8be4b54109a0b06c31805a5735a1ba.json": {
"sha1": "949e06d91b8be4b54109a0b06c31805a5735a1ba"
}
}
}
However, if I try to composer update the Laravel project, I get the following errors depending on if I execute it from within the container.
The "http://localhost:8002/packages.json" file could not be downloaded (HTTP/1.1 504 Gateway Timeout)
[Composer\Downloader\TransportException]
The "http://localhost:8002/packages.json" file could not be downloaded: failed to open stream: Address not available
If anyone would be able to point me in the right direction at all I would really appreciate it, as I am scratching my head here.

Downloading: connection...Failed to download cartalyst/nested-sets from dist:

I'm having some problems with a package (cartalyst/nested-sets) on my local laravel application. My composer.json is valid as:
$ composer validate
./composer.json is valid
I have a copy of the nested-sets package files on my desktop and have included them in my project tree - so the files are present and paths are correct.
Here's a snapshot of my composer.json file:
"require": {
"cartalyst/nested-sets": "2.0.*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.cartalyst.com"
}
],
...
I then issue:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing cartalyst/nested-sets (v2.0.2)
Downloading: connection...Failed to download cartalyst/nested-sets from dist: The "https://api.github.com/repos/cartalyst/nested-sets/zipball/7a425710ece922556e55150f5a1f2dfbedd4ffaa" file could not be downloaded (HTTP/1.1 404 Not Found)
Now trying to download from source
- Installing cartalyst/nested-sets (v2.0.2)
Cloning 7a425710ece922556e55150f5a1f2dfbedd4ffaa
It then just hangs with a blinking cursor at the shell. PHP OpenSSL extension is installed on my local and switching the firewall off makes no difference.
From the shell:
Failed to download cartalyst/nested-sets from dist: file could not be downloaded (HTTP/1.1 404 Not Found) but the files are already there? I don't understand.
You encounter this problem because you have to subscribe to Cartalyst repositories so you can get full access of their ressources and products ( libraries , components , sources ).
When Composer is trying to fetch Cartalyst from donwload or accessing a repository , it will ask you a valid username / password , if you have paid for a subscription you will get a valid auth credentials that enable you to access the repository and donwload via composer the required component / library ...
please read the following : https://medium.com/#Cartalyst/boss-sheet-8019c5e07246

Setting up alias for master branch in composer

I am trying to package a module for use with composer. I have a valid composer file and I am able to install it with composer, but only when I specify that it should use dev releases (via the "#dev" version directive or minimum stability dev). I am having trouble packaging my repo so that it is seen as a master release.
I found a composer document about aliases that seems to be made for my case, but I cant get it working. Heres the relevant portion of my composer.json:
"extra": {
"branch-alias": {
"dev-master": "1.0"
}
}
Also for reference heres the require from my main projects composer file:
"require": {
"misterglass/kohana-twig" : "1.*"
},
And the actual error from composer is:
Problem 1
- The requested package misterglass/kohana-twig 1.* could not be found.
According to some helpful people on the #composer IRC channel, aliases are just to associate different versions to each other, and not to assign stability.
In order to for composer to consider it stable, you need to add a tag, which you can do on the command line or by creating a release in github.

Resources