I am working on a project where I need to determine which composer packages are installed globally and what version. What is the best way to do that on Mac?
I was hoping there was some kind of terminal command for that and I can't seem to find it.
This is what I tried:
php /usr/local/bin/composer.phar show
Tried this
php global composer.phar show
The order of the parameters is wrong. global is not a valid parameter for the PHP interpreter, but for the composer application.
To see the packages installed globally on your system run:
php composer.phar global show
Or, if composer itself is installed globally:
composer global show
Related
How can I satisfy a Composer platform package dependency with an alternative path? I have a package that depends on php >=5.4, but my stock PHP is 5.3 and I have a separately maintained PHP 5.4 installation under the executable name of php54. Any way to make Composer aware of it?
You can run composer through your php54 executable. Either call it explicitly php54 composer.phar ... but that is painful if you have composer installed globally. In that case you're probably better off doing a shell script called composer that will call the phar file with php54 or register a bash alias for it.
I am new to VS code. I am trying to work with PHP, but I keep getting this notification.
phpcs: Request workspace/configuration failed with message:unable to
locate phpcs. please add phpcs to your global path or use composer
dependency manager to install it in your project locally.
Intellisense doesn't work for PHP too.
I am using a Windows system. I tried to download and install Composer, but I am still getting the problem as shown in the screenshot.
]1
I have some extensions installed which are visible in the screenshot, but the issue persists.
The easiest way is to use composer to install phpcs globally and symlink the binary into your path;
Assuming you have composer installed and are using osx or linux (if not, follow instructions from here: composer) then install phpcs globally: open your terminal and type:
composer global require "squizlabs/php_codesniffer=*"
You will then need to make sure phpcs is in your path. The easiest way is to symlink into /usr/local/bin. open your terminal and type:
sudo ln -s ~/.composer/vendor/bin/phpcs /usr/local/bin/phpcs
I don't know if this question has been asked, because searching finds results mostly about moving the libraries installation directory.
I have a globally installed composer command. Is there a way to run, for example, composer install in a different directory than current, i.e. to specify the directory in which I would like tu run the command?
E.g. being in /home/someuser, I would like to acquire the same result as in running composer install it inside /home/someuser/myproject. Of course, one way would be to simply change the current directory, run composer and go back.
Try composer install -h. There you'll find an option --working-dir (or -d). And that's what you're looking for.
Then run:
composer install --working-dir=/home/someuser/myproject
You can find more in composer docs.
Depending on your operating system, the = might need to be removed:
composer install --working-dir /home/someuser/myproject
In addition to the above answer from Tomáš Votruba i had to append the = charachter on OSX. So the full command would be:
composer install -d=/home/someuser/myproject
My first post on SO so was unable to simply add this as a comment.
This works for me, PHP 7.3 on ubuntu 18.04
Install
composer install --working-dir=/your_composer_dir
Update
composer update --working-dir=/your_composer_dir
I tried what others said, but it was giving me: Invalid working directory specified 'PATH' does not exist. Although it was my working dir that contained composer.json!
I don't know why anyway, but this worked for me (only for gnu/linux users):
composer --working-dir=$(pwd)
And by the way, if you had run composer -h, it would've told you the solution:
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
I am using a Windows machine with PHPStorm (terminal) and this worked for me.
composer install --working-dir /home/someuser/myproject
My Linux OS machines require me to use
composer install --working-dir=/home/someuser/myproject
Note: You may be able to substitute ~/ for /home/someuser/ if your path is super long.
Run:
cd /home/mysites/google.com
Then run:
composer require facebook/graph-sdk
Above steps will open up the directory named (google.com) and install facebook Graph SDK there.
quick question, and please let me know if anything about my idea is silly in general / if there is a better approach to this:
For the purpose of creating a Continuous Delivery pipeline, I would like to declare some packages needed for various types of tests in Composer with "require-dev". However, I am wondering if it was possible to run the install command in a way that it would install all packages listed under "require-dev" globally with one command?
It would be nice, since it would allow me to keep the test environments up-to-date with ease and allow for global access of all PHP Testing solutions I need. I know it is not much work and I would already be done with it if I just went through all of them manually, but I was curious to know if there was a nice way of doing this, since I think downloading and everything by hand, giving it execution rights and then moving it to the bin/ directory for global access is kind of a tedious solution.
According to the composer's help using the global keyword with the composer allow running commands in the global composer dir ($COMPOSER_HOME).
This means when you run composer global require phpunit/phpunit, composer will update its global directory instead of the directory you are in at that moment.
so in my case, $COMPOSER_HOME is in my home directory /Home/.composer, running the above command will;
update the /Home/.composer/composer.json file.
Download the latest phpunit package to the /Home/.composer/vender
Add a symlink to the phpunit executable file into the /Home/.composer/vendor/bin directory
so at this point if i have the bin folder included in my paths i would be able to run phpunit within my system regardless of which directory i'm running the command in.
Now if you prefer the dependency to be installed as part of the development requirement all you need to do is to add --dev parameter to the install (or update) command as well e.g. composer global require phpunit/phpunit --dev
What is that global install supposed to do?
The usual thing to do would be to install Phpunit. Now it wouldn't help you if you have two projects, one using the old version 3.7, and the newer using 4.6, to install any version globally.
Don't install dependencies globally that are used by a certain package explicitly.
However, tools that are not required, or are not stated to be required in a specific version, like PHP Codesniffer, can easily be installed centrally with
composer global require squizlabs/php_codesniffer
Then put the resulting path of ~/.composer/vendor/bin into the PATH environment variable. Note that ~ does not resolve there, you have to do that yourself.
I ran this command to install globally PHPUnit:
composer global require 'phpunit/phpunit=3.7.*'
Now I want to uninstall globally PHPUnit.
Any ideas?
To remove a globally installed package run:
composer global remove phpunit/phpunit
global command lets you to run many commands like install, require or update as if you were running them from the COMPOSER_HOME directory.
Read the related documentation here: http://getcomposer.org/doc/03-cli.md#global
COMPOSER_HOME depends on your system (on Linux it's ~/.composer), see http://getcomposer.org/doc/03-cli.md#composer-home for more details.
Also you can use another way
cd $HOME/.config/composer
And in composer.json file remove some require positions
After all execute composer update
This is a long way, but more clear