Composer found when running directly, but not when running artisan - composer-php

I am helping work on a site that uses OctoberCMS. I was trying to update to the latest release, but when I run the Artisan command to update October, I get the following error:
$ php artisan october:update
Updating October CMS...
Executing: composer update
'composer' is not recognized as an internal or external command, operable program or batch file.
[ERROR] Update failed. Check output above
However, if I run composer update directly, it works as expected:
$ composer update
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
> System\Console\ComposerScript::postAutoloadDump
INFO Discovering packages.
laravel/tinker .............................................................................. DONE
nesbot/carbon ............................................................................... DONE
nunomaduro/termwind ......................................................................... DONE
october/rain ................................................................................ DONE
94 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> System\Console\ComposerScript::postUpdateCmd
No security vulnerability advisories found
It has been close to 10 years since I did much PHP development, so my Composer-fu is more than a little rusty. If there is more info needed to help diagnose what's going on, let me know!
Environment:
Windows 11 Pro
Git Bash (running in ConEmu)
PHP 8.1.3
Composer 2.4.4

Can you try running composer in commandline/powershell? (You will likely see the same error)
'composer' is not recognized as an internal or external command, operable program or batch file.
Is not a response Git Bash or a linux like terminal would produce.
I think artisan is trying to run composer in a windows shell and can't find it in your PATH, but for some reason you have it in your Git Bash path.

Related

Why Composer uninstall things right after the installation?

Composer keeps removing the files just after it installs them!
I used composer create-project otra/skeleton --remove-vcs otra-user -vvv to debug and it shows things like :
- Installing otra/otra (1.0.0-alpha.2.4.0): Extracting archive
Executing async command (CWD): unzip -qq -o '/var/www/html/perso/otra-user/vendor/composer/tmp-ad5334fdc8c968f8ad3d54814c2b67c1' -d '/var/www/html/perso/otra-user/vendor/composer/cc30fdc4'
Executing command (CWD): rm -rf '/var/www/html/perso/otra-user/vendor/otra/otra'
Executing command (CWD): rm -rf '/var/www/html/perso/otra-user/vendor/composer/cc30fdc4'
And as usual since a few months, it finished with the infinite loop that shows :
2 packages you are using are looking for funding.
Use the composer fund command to find out more!
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Composer works like a charm before, I do not know what they have changed so I have all those issues now.
I have updated my Composer version and I did a composer diagnose but it shows nothing wrong.
I am using Composer 2.0.12 and PHP 8.0.3.
Thanks to #yivi that pointed me to an another problem in composer.json where I indeed did a loop...
I solved my problem replacing #otra-update by #otra-init in post-install-cmd and post-update-cmd which was what I really wanted to do.
Thanks for your time #Nico Haase and #yivi :)

"database/seeds" error when running "composer global require laravel/valet"

I'm running Ubuntu 18.04.4 LTS (Bionic Beaver).
I have installed Composer, Laravel, among other things on this server. I'm trying to run:
composer global require laravel/valet
It attempts to run, and outputs:
Changed current directory to /home/myUser/.config/composer Using version
^2.9 for laravel/valet ./composer.json has been updated Loading
composer repositories with package information Updating dependencies
(including require-dev) Nothing to install or update Generating
optimized autoload files
In ClassMapGenerator.php line 69:
Could not scan for classes inside "database/seeds" which does not
appear to be a file nor a folder
Where is/should this folder be, and why wouldn't it already be there anyway?
Laravel Valet is a MacOS utility, there are linux ports, such as this one, but it won't work on Ubuntu as it uses Homebrew under the hood, a package manager for MacOS.

Cannot update Composer's memory size

I'm trying to install an extension on Magento 2 via Composer, but when I run Composer update, I get the following error:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
I try:
php -d memory_limit=-1 composer update
But I get:
Could not open input file: composer
So I tried and got:
curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 1.9.0) successfully installed to: /home/customer/www/xxx/public_html/composer.phar
Use it: php composer.phar
So, thinking it's fixed I again tried and got:
php -d memory_limit=-1 composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
So I tried composer update again and got:
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
So again, I try composer update and get
Could not open input file: composer
I'm right back to where I started and incredibly confused :/ Please advise. Thank you.
When you are using php -d memory_limit=-1 you are setting an ini entry on the fly but only for the script run via that command.
Your idea to run this command was close to what you want to achieve:
php -d memory_limit=-1 composer update
The only thing you have to know is the fact that composer works as a command because it stands somewhere your OS would look for all the executables (most likely /usr/bin/composer, /usr/local/bin/composer, or something the like, this is usually referenced as the PATH). But when you try to run php composer, then composer is just considered as a regular file, and your OS do not try to look in your executable path anymore.
What you can do still is to use the command which, that will return you the path to that composer executable.
$ php $(which composer) -V
Composer version 1.8.6 2019-06-11 15:03:05
So you should be able to achieve what you aim to do via
php -d memory_limit=-1 $(which composer) install
for installation of packages; and
php -d memory_limit=-1 $(which composer) update
for updates.
Please also mind that: there is a full article in the composer documentation about memory limit: https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors
That could possibly ease you job, changing the relevant PHP CLI setting, or that could point you at the usage of
COMPOSER_MEMORY_LIMIT=-1 composer install
and
COMPOSER_MEMORY_LIMIT=-1 composer update

Laravel Artisan not working at all after clone

I have this weird situation: I've cloned all my repositories from github in a new local machine running Mac OsX some of them has Laravel framework installed but only some of these can execute the cmd php artisan.
I've tried to check permission on folders, uninstall/re-install composer and I've also tried to install a fresh version of Laravel. Another problem is that running the command doesn't output anything - no errors, nothing - only a new empty line of the terminal.
The only thing I know is that if I clone one of the repositories, then run composer install it throws Script php artisan optimize handling the post-install-cmd event returned with error code 255.
Thanks
Update 1:
I've found running composer install -vvv -o that composer throw this error
Warning: require(/Users/USERNAME/laravel/bootstrap/autoload.php): failed to open stream: No such file or directory in /Users/USERNAME/laravel/artisan on line 16
Fatal error: require(): Failed opening required '/Users/USERNAME/laravel/bootstrap/autoload.php' (include_path='.:') in /Users/USERNAME/laravel/artisan on line 16
Update 2:
It seems that cmd git clone didn't copy that autoload file bootstrap/autoload.php for some reason that I don't understand at all.
I've imported the file manually from github and run, removed the vendor folder then run again composer install --no-scripts but still having the problem with artisan and if I run composer update it throw Script php artisan optimize handling the post-update-cmd event returned with error code 255
I had to re-install laravel and copy files manually to make it works again.

Laravel Installer method

Normally I do install Laravel 5.1 by following this command regarding to documentation:
composer create-project laravel/laravel --prefer-dist
It works fine.
But I read in the documentation under "Via Laravel Installer" also it is possible to install via Laravel Installer, which is much faster than installing via Composer:
laravel new blog
But to use this method I need to run following command once:
composer global require "laravel/installer=~1.1"
When I do run it I get following errors many times
Deprecation Notice: Composer\Package\Version\VersionParser::parseLinks
is deprecated. Use \Composer\Package\Loader\ArrayLoader::parseLinks()
instead in
phar://C:/ProgramData/Composer/bin/composer.phar/src/Composer/Package/Version/VersionParser.php:226
after many line of same error ./composer.json has been updated appears and it continues with the same line of errors, it ends with following
Loading composer repositories with package information Updating
dependencies (including require-dev) Nothing to install or update
Generating autoload files
What is wrong with it? Any idea or solution.
My environment: Windows 10, GitBash and cmder console.
Update of composer, I did ran composer self-update also
Snapshot of console
EDIT:
Note, I can confirm after solving the issue that the installation via Laravel Installer method is faster than composer.
The Composer Assets Plugin you've installed locally is using a deprecated method of Composer. The plugin is already fixed, so run composer global update to get the latest versions with the bug fix. After it, you should be able to run the command succesfully.
If this doesn't work (as you might get the same error running the previous command), try removing the global vendor directory. When running any global Composer command, it outputs something like "Changed current directory to XXX". Remove the XXX/vendor directory and then try running the command.
In addition to #WouterJ answer.
Worst case if the steps provided by #WouterJ did not work, you could manage to uninstall and reinstall composer for windows.
When done, run composer global update to be sure to get latest updates, if there was.
Then run composer global require "laravel/installer=~1.1" and it should works.
Remember to update your windows environment path C:\Users\UserName\AppData\Roaming\Composer\vendor\bin

Resources