Composer : how to add a dependency without network connection?
Thanks to edmondscommerce's comment I found the solution:
I update my main composer.json file with an artifact respository (and I disable the packagist one):
{
"name": "user/silex",
"repositories": [
{
"type": "artifact",
"url": "artifact/"
}, {
"packagist": false
}
], "require": {
"silex/silex": "1.2"
, "twig/twig": ">=1.8,<2.0-dev"
, "monolog/monolog": "1.*"
, "doctrine/dbal": "2.2.*"
, "symfony/security": "~2.3"
},
"autoload": {
"psr-4": {
"Portal\\": "src/"
}
}
}
Then I put a folder called artifact
according to the url put in the composer.json file.I create into this folder a zip called monolog-monolog-1.8.zip with the library I want to add.
Then just launch a composer update
command!
Be carefull, zip's root must contain a composer.json file, and this composer.json file must contain a version!
Cannot make composer install work offline
By default Composer does not disable access to packagist.org when you add custom repos. You can disable it with the following config:
{
"repositories": [
{
"packagist.org": false
}
]
}
Composer: how can I install another dependency without updating old ones?
To install a new package and only that, you have two options:
Using the
require
command, just run:
Composer will guess the best version constraint to use, install the package, and add it tocomposer require new/package
composer.lock
.You can also specify an explicit version constraint by running:
composer require new/package ~2.5
Using the
update
command, add the new package manually tocomposer.json
, then run:composer update new/package
--with-dependencies
. This will whitelist all dependencies of the package you are trying to install/update (but none of your other dependencies).Regarding the question asker's issues with Laravel and mcrypt: check that it's properly enabled in your CLI php.ini. If php -m
doesn't list mcrypt then it's missing.
Important: Don't forget to specify new/package
when using composer update
! Omitting that argument will cause all dependencies, as well as composer.lock
, to be updated.
How to get composer to install older version of a specific dependency within required range?
Since install
is meant to read from a lockfile, this option wouldn't make sense for the command.
But for update
(and if there is no lockfile, install
behaves as update
), there is the --prefer-lowest
flag (docs).
There is also the option to downgrade a specific package without affecting your composer.json
file, by running something like:
composer update --with vendor/package:2.0.1
Mind you, any of these options will modify your lockfile, so after testing you would probably need to git restore composer.lock
to go back to the original state.Commiting a lockfile for a project by mistake should be a biggish issue. Since applications are usually built/deployed by reading the lockfile, a lockfile in an inconsistent state could break things in unexpected places.
But warding of commiting and pushing changes by mistake seems to be excessive, IMO. Developers can make changes to any file, and if they commit those "by mistake", things can break all around.
Expecting a basic "I should look what's changed before staging and commiting" seems a very low bar to me.
How do I install Composer PHP packages without Composer?
The composer.json
file lists the dependencies. In your example:
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0"
},
You must then find the corresponding packages in the packagist site. Repeat the same process for each dependency: find additional dependencies in their corresponding composer.json
files and search again.When you finally have a complete list of the required packages, you only need to install them all one by one. For the most part, it's just a matter of dropping the files somewhere in your project directory. But you must also ensure that PHP can find the needed classes. Since you aren't using Composer's auto-loader, you need to add them to your own custom autoloader. You can figure out the information from the respective composer.json
files, e.g.:
"autoload": {
"psr-4": { "Coinbase\\Wallet\\": "src/" }
},
If you don't use a class auto-loader you'll need to figure out the individual require_once
statements. You'll probably need a lot of trial and error because most library authors won't care documenting that.Also, and just in case there's confusion about this:
- Composer has an official GUI installer for Windows and a copy and paste command-line installation procedure for all platforms.
- Composer can be run locally and its output just uploaded elsewhere. You don't need SSH in your shared hosting.
- The command needed to install a library can be copied and pasted from the package web site—even if the package maintainer didn't care to document it, packagist.org generates it by default.
I've checked other answers that came after mine. They mostly fall in two categories:
- Install a library and write a custom download script with it
- Use an online web based interface for Composer
- Learning curve
- Use of third-party software
- Possibility to develop right on the server (using SSH, I presume)
- Potentially deep dependency tree
Related Topics
How to Select a MySQL Database to Use with Pdo in PHP
Reverse Letters in Each Word of a String Without Using Native Splitting or Reversing Functions
Find All Second Level Keys in Multi-Dimensional Array in PHP
Zend Framework 2 Routing Subdomains to Module
How to Change the Default Netbeans 7 Project Directory
Finding First Day of Week via PHP
How to Determine the Length (In Pixels) of a String Being Rendered on a Web Page
File_Get_Contents('Php://Input') Always Returns an Empty String
Newline Not Working in PHP Mail
How to Make a Chat Room Script with PHP
Call to Undefined Function Curl_Init() - with Wamp
PHP Warning: Unknown: Input Variables Exceeded 1000
PHP MySQL Query Where X = $Variable
Efficient Reloading Data/Pushing Data from Server to Client
Php-Paypal-Error: 14077410:Ssl Routines:Ssl23_Get_Server_Hello:Sslv3 Alert Handshake Failure