Closed ARehmanMahi closed 7 months ago
I suspect (without digging into laravel's template repo), that some script is using:
{
"scripts": {"example": "composer do-stuff"}
}
instead of
{
"scripts": {"example": "@composer do-stuff"}
}
The former would use a globally installed composer (if available) while the latter should call back into itself. It'd be interesting to test both these variations in a project and see what happens.
I didn't now what the @ sign did in composer file, just got the info from your comment, Thank you.
Every command in laravel's composer has @php, but I think the error is in postAutoloadDump
.
composer.json
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
This has gone out of my current knowledge of composer & the internal framework. This is an interesting outcome, and most probably at Laravel's end itself.
I'm not sure if I can help any further, but let me know. And maybe close this issue as it seems out of Franky's scope.
Ah, interesting. It's possible that FrankenPHP doesn't let composer know how to call @php
.
If we take a look at composer it is actually trying to execute a php
binary, which would default to frankenphp
in this case.
It then tries to call frankenphp
with -d
arguments, which will fail.
So, it looks like if we want full php-cli support, we'd need to have a php
binary that can be used by composer (can use environment variable: PHP_BINARY
).
@dunglas ^
We might need to possibly extract the static php binary to a location on disk and set PHP_BINARY
env var when executing cli scripts (particularly composer).
or provide a fully backwards compatible cli. or ignore unsupported arguments.
That's a great find, you are awesome.
I know dunglas mentioned php parameters are not supported yet, so this would require some extra work. Glad my discussion helped in pointing out some not-so-common use cases.
Simple approaches are not so simple after all :)
Thanks for the investigation!
In my opinion we should:
frankenphp php-cli
WDYT?
Composer uses the PHP_BINARY
env variable if it's set, we just need to test that it handles spaces for our case. Meaning will it call "frankenphp php-cli" script.php or "frankenphp php-cli script.php".
I ran into the same problem - in a laravel project, composer wants to a call php binary e.g. to do package discovery. As a workaround, I created a shell script in /usr/local/bin/php
to strip the -d
parameters and call frankenphp:
#!/bin/bash
# iterate over $@. if the current argument is -d, remove the argument and the next one
for i in "$@"
do
if [ "$i" == "-d" ]; then
shift
shift
fi
done
/usr/local/bin/frankenphp php-cli "$@"
With this, the composer install goes through.
Nice one. Would you mind opening a docs PR to mention this trick? Maybe in the known-issues.md
file?
Closing for now: https://github.com/dunglas/frankenphp/pull/610
Following the discussion here https://github.com/dunglas/frankenphp/issues/470#issuecomment-1898094157
I'm trying to use frankenphp php-cli to run composer commands.
I just ran
./frankenphp php-cli ./composer.phar create-project laravel/laravel example-app
In an Empty Folder. And get the following error. This is a composer command to install laravel project.Edit 1
Edit 2
Edit 3
composer.phar
frankenphp v1.0.3
How to reproduce on Ubuntu 22.04
Laravel installer runs fine untill it reaches pro-install script and error outs This also happens on an existing project.
Using system-level php with composer works fine so it seems to be frankenphp php-cli's issue maybe.