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!
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
Change composer global path (Windows)
I found an answer in the source code: https://github.com/composer/composer/blob/master/src/Composer/Factory.php#L45
So environment variable COMPOSER_HOME
must be defined as C:\php\composer
.
why cannot find composer.phar file after install composer
composer.phar is a single file, you can just move it to the system32 folder and have it visible globally
How to use composer on windows?
Okay, let's say your website is at:
C:\xampp\htdocs\mywebsite\
You should put the Composer file at:
C:\xampp\htdocs\mywebsite\composer.json
Then, in your terminal, use these two commands:
cd C:\xampp\htdocs\mywebsite
composer install
That should be it.
You can do various other things with Composer. To find out what type composer
in your terminal. It will show you a list of commands you can use.
If you want to know more about a command then you can use composer help [COMMAND]
, like so:
composer help install
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).
Composer installation: global vs local
The disadvantage of using a globally installed composer is this
- you're likely using different versions along the development pipeline
- you may end up with different results
Just as an example, in a project, we had composer.phar
checked in and updated regularly, but we ran into problems when the version we used was already updated to be able to use the ^
operator, however, a different binary was used during deployment, unaware of that operator, and the deployment failed.
The safest bet is to use the same version of composer.phar
along the development pipeline. Alternatively, as mentioned before, keeping the globally installed composer
regularly updated.
Since we usually use Makefile
s in our projects, here's an example of what it looks like:
.PHONY: composer cs it test
it: cs test
composer:
composer self-update
composer validate
composer install
cs: composer
vendor/bin/php-cs-fixer fix --diff --verbose
test:
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml
vendor/bin/phpunit --configuration=test/Integration/phpunit.xml
Related Topics
How to Make a Cascading Drop Down List in PHP Using Jquery
How to Download Large Files Through PHP Script
Yii2 Translation Does Not Work
How to Get the Last N Items in a PHP Array as Another Array
Difference Between Mt_Rand() and Rand()
%2F in Url Breaks and Does Not Reference to the .PHP File Required
Php: Do Arrays Have a Maximum Size
PHP Strtotime +1 Month Behaviour
How to Use Array_Unique on an Array of Arrays
PHP Regex to Get String Inside Href Tag
File_Exists() Returns False Even If File Exist (Remote Url)
Error 1148 MySQL the Used Command Is Not Allowed with This MySQL Version
How to Override Built-In PHP Function(S)
Algorithm for Generating a Random Number
Retrieve (Or Simulate) Full Query from Pdo Prepared Statement
PHP File Upload Error Tmp_Name Is Empty
How to Validate a Domain Name Using Regex & PHP
How to Configuring a Xampp Web Server for Different Root Directory