Composer is very slow while downloading Laravel - php

can you help me please? I want to install Laravel via composer create-project laravel/laravel in to the cms directory but Composer downloads it very very slow. Can you help me with it how to boost it?
Here is my terminal:
saidalo#Saidalo-Yodgoroff:/var/www/html$ composer create-project laravel/laravel cms "5.1.*"
Installing laravel/laravel (v5.1.33)
- Installing laravel/laravel (v5.1.33)
Downloading: 100%
Created project in cms
> php -r "copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing vlucas/phpdotenv (v1.1.1)
Downloading: 100%
- Installing symfony/var-dumper (v2.7.11)
Downloading: 100%
- Installing symfony/translation (v2.7.11)
Downloading: Connecting...
I don't know what to do!

Try
composer config --global repo.packagist composer https://packagist.org
to force https

There is a package to speed up your composer. It may be useful
Disable Xdebug
Turn it off and be happy.
Use Prestissimo
is a global Composer plugin that installs dependencies in parallel. It is crazy fast. It’s worth noting that Prestissimo requires cURL, which may not work behind certain firewalls or proxies. I haven’t run into any issues at all personally.
Source: composer speed up from laravel

Try hirak/prestissimo Composer plug-in. It will drastically reduce dependency installation process of any large project.

I disabled IPv6 on my network card it seems to have fixed it. Image below of what I unchecked, hope that helps.
Disable IPv6 Img Link

Related

How to handle missing dependencies with composer & docker?

I have an application that I want to install for local development on my laptop with Docker. The application requires libraries from composer.
I would like to avoid installing PHP on my laptop and all necessary extensions just to be able to run composer.
I also don't want to run composer during the build inside of my application container, because I need the vendor folder on my local computer using mount binding.
It looked like the perfect solution to me to install composer though a docker container as explained here:
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer install
However, when doing so, how do you resolve any PHP dependency conflicts?
For example
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer require phpoffice/phpspreadsheet
will fail with
Using version ^1.14 for phpoffice/phpspreadsheet
./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
- phpoffice/phpspreadsheet 1.14.1 requires ext-gd * -> the requested PHP extension gd is missing from your system.
- phpoffice/phpspreadsheet 1.14.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
- Installation request for phpoffice/phpspreadsheet ^1.14 -> satisfiable by phpoffice/phpspreadsheet[1.14.0, 1.14.1].
How can I solve this kind of problems?
When the environment where you are running install, update or require commands is different from the environment where you are going to execute the code, and if you are absolutely certain that these dependencies are going to be met when the code is actually run, you do not need to check them during installation.
Just use --ignore-platform-reqs (docs).
What I usually put in my Dockerfiles when creating images for this kind of project is something like this, the the very minimum:
composer install --ignore-platform-reqs --prefer-dist
The whole thing goes like this if the artefact is being prepared for production:
composer install --ignore-platform-reqs --prefer-dist --no-scripts \
--no-progress --no-suggest --no-interaction --no-dev --no-autoloader
A couple additional steps to dump-autoload and execute post-install scripts are going to be needed in this case.
You do not elaborate how are you planning on running the result of this installation afterwards, so I'm not sure that part will be relevant for you.
Note: this is not particularly "docker" dependant. This strategy would apply any time you are creating an installation on a different machine than were you plan on running the installation.

composer cache not working on bitbucket pipeline build

I got this in my bitbucket pipeline:
pipelines:
branches:
develop:
- step:
caches:
- composer
name: unit tests - Delivery
image: totersapp/laravel-docker:phpredis
script:
- echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit-php.ini
- ln -f -s .env.pipelines .env
- composer install
services:
- postgres
- redis
every time it run it is downloading the same files (even on the second run).. any ideas why?
This is the log for composer install:
+ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 199 installs, 0 updates, 0 removals
- Installing kylekatarnls/update-helper (1.2.0): Downloading (connecting...)Downloading (0%) Downloading (100%)
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (95%)Downloading (100%)
- Installing symfony/polyfill-ctype (v1.13.1): Downloading (connecting...)Downloading (0%) Downloading (100%)
update: couldn't override default
Based on this answer I tried this:
- step:
caches:
- composer
image: totersapp/laravel-docker:phpredis
script:
- composer install
..
definitions:
caches:
composer: /composer/cache
My problem is that I'm trying to call composer with a custom cache directory (in this case it's /composer/cache) but then again I don't have a way to call the composer install command while supplying the custom cache directory as an option (ie which is what the bitbucket tutorial is doing with bundle in this example:
- bundle install --path vendor/bundle
said another way, I cannot run something like this:
- composer install --cache-directory /composer/cache
Update 2: discrepancy between composer.json and composer.lock
First as a sanity check, I simply cloned the repo of Nico
Haase, and ran the pipelines, passed ✅
I copied and pasted the contents of his bitbucket-pipelines.yml into mine, and I copied and pasted his composer.json, I ran the pipeline. Failed ❌
But I got this in the composer install log:
+ composer install --ignore-platform-reqs --no-scripts
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
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.
Package operations: 199 installs, 0 updates, 0 removals
- Installing kylekatarnls/update-helper (1.2.0): Downloading (connecting...)Downloading (0%) Downloading (100%)
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (95%)Downloading (100%)
- Installing symfony/polyfill-ctype (v1.13.1): Downloading (connecting...)Downloading (0%) Downloading (100%)
So i figured it's b/c the composer.lock file is out of sync with composer.json, so I added composer update to my pipeline.. this loaded from cache! ✅but failed here ❌:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 108 installs, 0 updates, 0 removals
- Installing ocramius/package-versions (1.4.2): Downloading (connecting...)Downloading (0%) Downloading (30%)Downloading (35%)Downloading (65%)Downloading (80%)Downloading (100%)
- Installing symfony/flex (v1.6.0): Downloading (connecting...)Downloading (100%)
Symfony operations: 1 recipe (4c6f09f5995a77b64f54dd80675d3bfe)
- Configuring symfony/flex (>=1.0): From github.com/symfony/recipes:master
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.0.*"
Prefetching 106 packages
- Downloading (0%) (5%) (10%) (16%) (21%) (31%) (36%) (41%) (47%) (52%) (57%) (65%) (70%) (75%) (80%) (85%) (90%) (95%) (100%)
Package operations: 106 installs, 0 updates, 0 removals
- Installing psr/container (1.0.0): Loading from cache
- Installing symfony/service-contracts (v2.0.1): Loading from cache
..
..
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!! Fatal Error: composer.lock was created for PHP version 7.2.9 or higher but the current PHP version is 7.1.32.
note: in my original composer.json file, i found this line
"config": {
..
"cache-dir": "~/.cache/composer",
},
so I removed that line, but that didn't help either.
Still digging (for the record this is what my composer.json looks like, i kept the cache-dir part in it for reference)
According to a question on the Bitbucket forums, this can happen if the docker image you are using is putting the downloaded files in a unusual position. According to the documentation about caches, the usual directory that is cached is ~/.composer/cache, while the docker file of the image uses /composer.
Please try to use the following configuration. It contains a custom cache (which needs a custom name!) that puts the customized composer folder in the cache:
pipelines:
branches:
develop:
- step:
caches:
- composer-custom
definitions:
caches:
composer-custom: /composer/cache
As you can see on https://bitbucket.org/haasenico/composer-cache/addon/pipelines/home#!/results/4, the cache is used and seems to work for my short example
To make this work I basically followed Nico Haase's answer, but I also had to do the following:
remove "cache-dir": "~/.cache/composer" from my composer.json
ensure that the cache file saved is in sync with whatever is going on in composer.json.. you cannot ask composer.json to load the dependencies from a cache file that has irrelevant content. To do this, I simply deleted all caches file and started again, it worked this time!

Error installing composer due to symfony/routing version

In Ubuntu 18.04, I have php installed. I confirmed it work with index.php testing. I now try to install composer
composer install
But below error was shown:
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for symfony/routing v4.1.6 -> satisfiable by symfony/routing[v4.1.6].
- don't install symfony/symfony v3.4.17|don't install symfony/routing v4.1.6
- Installation request for symfony/symfony v3.4.17 -> satisfiable by symfony/symfony[v3.4.17].
I have previously install Symfony as a package by
sudo apt install php-symfony
php-symfony is already the newest version (3.4.6+dfsg-1ubuntu0.1).
Do I uninstall symfony and replace it with symfony/routing v4.1.6?
I googled for a long time but I cannot find relevant instructions. Symfony documentation appears to only show instruction on using composer to install Symfony. But I now have trouble to install composer. Please help, thanks!
The symfony/symfony package already includes the Routing component (which you try to install with the symfony/routing package). This is something Composer wrongly allowed in older versions and was fixed in Composer 1.7.3.
Do you really need the Routing component in version 4? If that's the case, you need to remove symfony/symfony first and require all the needed components explicitly if you cannot upgrade all Symfony packages to 4.1.
If you want to install a new Symfony project, I recommend not using the packaged php-symfony and instead use composer to create a new project from scratch. I don't know much about the package, but as you can tell from the version it is outdated (v3.4.18 is the current version). Relying on an outdated package is not recommended. Instead use the recommended way to set up a new project:
composer create-project symfony/skeleton my-project
If you want a full stack application you can also use symfony/website-skeleton as the basis for the project. If you want to stick to the old 3.4 version you can add the constraint to the command:
composer create-project symfony/skeleton:"^3.4"
See also https://symfony.com/doc/current/setup.html

Download composer packages before install

I want to force to composer to download all packages before to install it and to speedup the dependencies installation on projects.
On production environment, I don't want to wait to packages download, it must be installed from cache.
Something like:
$> composer download-install # Currently not exists
$> composer install # Install from previously cached packages.
There are any composer option to do it?
Thanks!
There's a composer package that does exactly that!
Require it globally like this:
$ composer global require hirak/prestissimo
Then just a regular composer install will prefetch all the packages first and then install them as if they're from cache.
$ composer install
Read more at https://github.com/hirak/prestissimo

Composer takes forever to download even with hirak/prestissimo?

Why does composer create-project take forever to download and create project?
I have tried:
Slim:
$ composer create-project slim/slim-skeleton slim-app
Laravel:
$ composer create-project laravel/laravel lavavel-app"5.0.*" --prefer-dist
It is just extremely slow:
Installing slim/slim-skeleton (3.1.2)
- Installing slim/slim-skeleton (3.1.2) Downloading: 100%
Created project in mr-simon-cohen-slim
Loading composer repositories with package information
Updating dependencies (including require-dev)
(it just stuck here...)
Any ideas?
I'm on Kubuntu 16.10.
EDIT:
After installing hirak/prestissimo, I get this error:
$ composer create-project slim/slim-skeleton slim-app
Cannot create cache directory /home/tealou/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/tealou/.composer/cache/files/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/tealou/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/tealou/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache
(it stuck here forever now)
During installing hirak/prestissimo, I get this error:
$ composer global require "hirak/prestissimo:^0.3"
Changed current directory to /home/teelou/.composer
[ErrorException]
file_put_contents(./composer.json): failed to open stream: Permission denied
So i used sudo:
$ sudo composer global require "hirak/prestissimo:^0.3"
[sudo] password for teelou:
Changed current directory to /home/teelou/.composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing hirak/prestissimo (0.3.5) Downloading: 100%
Writing lock file
Generating autoload files
What can I do to fix this mess now?
EDIT 2:
I got it fixed by:
$ sudo chmod -R 777 /home/teelou/.composer/
But hirak/prestissimo does not help in speeding up the download at all. It is still very slow.

Categories