How to Run Composer from Anywhere

How to run composer from anywhere?

composer.phar can be ran on its own, no need to prefix it with php. This should solve your problem (being in the difference of bash's $PATH and php's include_path).

Is there any way to install Composer globally on Windows?

Sure. Just put composer.phar somewhere like C:\php\composer.phar, then make a batch file somewhere within the PATH called composer.bat which does the following:

@ECHO OFF
php "%~dp0composer.phar" %*

The "%*" repeats all of the arguments passed to the shell script.

Then you can run around doing composer update all ya want!

composer installation on VPS with different domain hosting

1st - You need to install composer tool globally. This means that you need to install it once but you need to run composer install on each folder that has a composer.json file, in order to install its dependencies.

2nd - I am not sure how you server is organised regarding permissions, but I think installing it with root is enough.

3rd - I normally move and rename the composer.phar file to a location like /usr/local/bin.

--- Try doing these steps ---

Download composer (get instructions on link below)

https://getcomposer.org/download/

Make the phar executable:

chmod a+x composer.phar

Run this to move and rename it:

mv ./composer.phar /usr/local/bin/composer

After this, you should be able to call composer from anywhere on your server. To test it, simply run: composer.

Now proceed to you app folder (where composer.json is located) and run: composer install

Installing Composer globally for laravel usage?

Locate your `php.exe file, it is probably in:

C:\wamp\bin

or

C:\wamp\bin\php

Create a file (use notepad) composer.bat in the same folder and add this line to it:

@php C:\wamp\bin\php\php5.4.12\composer.phar %*

Close and try to run composer from anywhere:

cd\
composer --version

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.

Composer is not perfect and it doesn't suit all use cases but, when it comes to installing a library that relies on it, it's undoubtedly the best alternative and it's a fairly decent one.


I've checked other answers that came after mine. They mostly fall in two categories:

  1. Install a library and write a custom download script with it
  2. Use an online web based interface for Composer

Unless I'm missing something, none of them address the complaints expressed by the OP:

  • Learning curve
  • Use of third-party software
  • Possibility to develop right on the server (using SSH, I presume)
  • Potentially deep dependency tree

Do I need to install Composer on server?

No, you can build your application on a separate server (or less optimal when working in a team, on your development machine) and then copy the project (including the installed vendors) onto your server. In fact it is quite common to build the application on a separate server and then only deploy the artifact (a tar.gz file, an os-package like deb or a built docker image) instead, in order to have a production system without tools/dependencies not required for running the actual application like git, composer, etc.

You might have to run additional commands, e.g. to make sure cache files are generated, but basically you run a composer install --dump-autoload --no-dev --prefer-dist (and possibly also --classmap-authoritative) to install the production dependencies, run your required artisan commands to copy assets into the public directory, build cache files, etc. and then transfer the whole project over to your server using your preferred method from rsync to any of the other ones mentioned above. There might still be some details you have to take care of, but by no means do you have to have composer installed on your production server.



Related Topics



Leave a reply



Submit