Home >Development Tools >composer >Composer offline installation local package method

Composer offline installation local package method

藏色散人
藏色散人forward
2021-05-10 15:31:025430browse

The following tutorial column of composer will introduce to you how to install local packages offline with composer. I hope it will be helpful to friends who need it!

The local situation is like this. Composer has been installed because the project (thinkphp) needs to install an ffmpeg package, but it failed to install it many times. Later I found out that it was on git, so I simply installed the package. I downloaded it from git and want to install it locally, but I really can't stand the installation speed. I switched to the domestic source and the Alibaba source, but it just couldn’t be downloaded, so I had to download the package offline and install it locally.

I was very happy to read Baidu’s articles on this, but most methods didn’t work. So I asked a friend to do some skeleton work, and it turns out that only useful information can be found abroad. Let’s get straight to the practical stuff:

First delete composer.lock in the project directory, then transfer the downloaded package to a place that can generate a URL, the kind that can be accessed directly via http, and then edit composer.json

    "repositories": [
	    {
            "type": "composer",
            "url": "https://mirrors.aliyun.com/composer/"
        },
        {
            "type": "package",
            "package": {
                "name": "php-ffmpeg/php-ffmpeg",
                "version": "0.16",
                "dist": {
                    "url": "http://192.168.100.52/upload/PHP-FFMpeg-0.16.zip",
                    "type": "zip"
                }
            }
        }
    ]

Then, add php-ffmpeg/php-ffmpeg to require (of course, keep your other require items, this is just to talk about this offline package), as follows:

    "require": {
		"php-ffmpeg/php-ffmpeg": "^0.16.0"
    }

Then install it, Because my composer has been upgraded to 2.0, I added a --no-plugins parameter to see if there is a yellow warning. If you are 1.0, you don’t need to add this parameter:

composer require php-ffmpeg/php-ffmpeg --no-plugins

or run The following command can also be used:

composer update

What is mentioned above is the entire actual installation process, just follow it.

Finally, in order to facilitate the installation of composer in the future, delete the newly generated composer.lock, edit composer.json, delete the package section, and restore it:

    "repositories": [
	    {
            "type": "composer",
            "url": "https://mirrors.aliyun.com/composer/"
        }
    ]

Update composer again That's it.

Finally, let’s talk about the reference article:

https://stackoverflow.com/questions/29994088/composer-require-local-package

https://getcomposer. org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

The above is the detailed content of Composer offline installation local package method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete