Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: include composer to complement built-in php #470

Closed
ARehmanMahi opened this issue Jan 11, 2024 · 14 comments
Closed

Feature request: include composer to complement built-in php #470

ARehmanMahi opened this issue Jan 11, 2024 · 14 comments

Comments

@ARehmanMahi
Copy link

laravel/octane#764 (comment)

As FrankenPHP has its own PHP, We can discard system level PHP install.
And start the app using./frankenphp php-cli artisan octane:start which will use Franky's built-in PHP to run the app.

But doing composer install requires PHP binary, so you still need a globally accessible PHP binary.
How about including composer to complement built-in php so doing ./frankenphp php-cli composer install would work seamlessly?

@withinboredom
Copy link
Collaborator

If you are using the docker image, you can just do install-php-extensions @composer when installing your extensions.

@ARehmanMahi
Copy link
Author

Hi appreciate the fast reply, should have included it before, not using docker. Using standalone binary. Any suggestion for this? Sorry for noob questions.

If difficult then maybe I should use docker instead, but that would be another dependency for me to manage on the server.

@withinboredom
Copy link
Collaborator

If you are using the standalone binary, why not have composer.phar in a directory of your project, then add:

#!/bin/bash

exec ./frankenphp-linux-x86_64 php-cli ./composer.phar $@

Then you just call ./composer install like ye old days before we did globally installed composers.

@ARehmanMahi
Copy link
Author

ARehmanMahi commented Jan 11, 2024

I was just trying the same with a custom alias, but this is very neat. Thank you. Loving how Franky is headed.
Thank you for the reply and all the efforts the contibutors have put into the project.

@dunglas
Copy link
Owner

dunglas commented Jan 11, 2024

This could be nice to add these tricks to the docs.

@ARehmanMahi
Copy link
Author

ARehmanMahi commented Jan 11, 2024

Definitely would be helpful. One time I was curious which PHP packages were included in Franky's PHP & couldn't find in docs. Some fellow pointed a hint towards the build process of Franky and I got it from there.

So maybe include the hint for packages and pointing to:

export PHP_EXTENSIONS="apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,igbinary,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,sysvsem,tokenizer,xml,xmlreader,xmlwriter,zip,zlib"


Plus, for a noob like myself, If would be wondering how would php.ini in this case would work, as we don't have access to the internals?

This ./frankenphp php-cli -c /path/to/your/php_cli.ini script.php
That ./frankenphp php-cli -d memory_limit=512M script.php

@dunglas
Copy link
Owner

dunglas commented Jan 11, 2024

Passing flags such as -c or -d isn't supported yet, but could be nice to support.

@rodrigopedra
Copy link

@dunglas running a shell script like you suggested here: #470 (comment) fails with Laravel post install script

Specifically, when running the package auto-discover.

Here is the relevant output:

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In Application.php line 430:
                                                                          
  Invalid working directory specified, allow_url_fopen=1 does not exist.  
                                                                          

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Steps to reproduce:

  • cd into a Laravel project
  • run ./composer install where composer is the shell script suggested by you on the referenced comment
  • also remember to have a composer.phar file in the same directory

@withinboredom
Copy link
Collaborator

withinboredom commented Jan 17, 2024

@rodrigopedra I was actually the author of that comment...

Anyway, there isn't an "Application.php" in Laravel as far as I can tell, so I have no way to know what is going on in your code. If you could point to it, that would be fantastic.

For what it's worth:

getcwd() appears to return the correct working directory when running with php-cli

@ARehmanMahi
Copy link
Author

ARehmanMahi commented Jan 18, 2024

Ok, just ran a test and got this error.

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

Fatal error: Uncaught ReflectionException: Class "config" does not exist in /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:912
Stack trace:

Inside new test added frankenphp, compser.phar & composer.sh with the code snipper provided above.

Ran ./composer create-project laravel/laravel example-app

Tried to google, but all suggestions were for an existing project the above is new laravel install.
Someone said it's related to mbstring when compiling php, but mbstring is added in the build script I reckon.
So not really sure. mybe someone can test it? WIll look into it again later. Google GPT stuff.

@withinboredom
Copy link
Collaborator

It would be great if you could share the actual code causing the error instead of entire frameworks so that we can reproduce with a minimal example. In that error message, it looks like the project needs to be configured. For laravel help, I recommend going to the laravel repo or forums.

@ARehmanMahi
Copy link
Author

ARehmanMahi commented Jan 18, 2024

@withinboredom Hi, there was no code & no project.

I just ran ./composer create-project laravel/laravel example-app In an Empty Folder, which is a composer command to install laravel project.

I'm trying to use frankenphp php-cli to run composer commands.
I just used your suggested .sh script and frankenphp & it's built-in php.

composer

#!/bin/bash

exec ./frankenphp php-cli ./composer.phar $@

composer.phar

Downloaded from the site directly.

frankenphp v1.0.3

Downloaded from the git directly.

Commands

$ mkdir test
$ cd test
# copy all three files here
$ ls > composer composer.phar frankenphp
$ ./composer create-project laravel/laravel example-app

Laravel installer runs fine untill it reaches pro-install script and error outs

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

Fatal error: Uncaught ReflectionException: Class "config" does not exist in /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:912
Stack trace:
#0 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(912): ReflectionClass->__construct('config')
#1 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\Container\Container->build('config')
#2 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(957): Illuminate\Container\Container->resolve('config', Array, true)
#3 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\Foundation\Application->resolve('config', Array)
#4 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(942): Illuminate\Container\Container->make('config', Array)
#5 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(1454): Illuminate\Foundation\Application->make('config')
#6 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(560): Illuminate\Container\Container->offsetGet('config')
#7 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(611): Illuminate\Log\LogManager->getDefaultDriver()
#8 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(124): Illuminate\Log\LogManager->parseDriver(NULL)
#9 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(681): Illuminate\Log\LogManager->driver()
#10 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(317): Illuminate\Log\LogManager->error('Call to undefin...', Array)
#11 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(278): Illuminate\Foundation\Exceptions\Handler->reportThrowable(Object(Error))
#12 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(523): Illuminate\Foundation\Exceptions\Handler->report(Object(Error))
#13 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(203): Illuminate\Foundation\Console\Kernel->reportException(Object(Error))
#14 /var/www/html/test/example-app/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 {main}

Next Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist. in /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:914
Stack trace:
#0 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(795): Illuminate\Container\Container->build('config')
#1 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(957): Illuminate\Container\Container->resolve('config', Array, true)
#2 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(731): Illuminate\Foundation\Application->resolve('config', Array)
#3 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(942): Illuminate\Container\Container->make('config', Array)
#4 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php(1454): Illuminate\Foundation\Application->make('config')
#5 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(560): Illuminate\Container\Container->offsetGet('config')
#6 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(611): Illuminate\Log\LogManager->getDefaultDriver()
#7 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(124): Illuminate\Log\LogManager->parseDriver(NULL)
#8 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(681): Illuminate\Log\LogManager->driver()
#9 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(317): Illuminate\Log\LogManager->error('Call to undefin...', Array)
#10 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(278): Illuminate\Foundation\Exceptions\Handler->reportThrowable(Object(Error))
#11 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(523): Illuminate\Foundation\Exceptions\Handler->report(Object(Error))
#12 /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(203): Illuminate\Foundation\Console\Kernel->reportException(Object(Error))
#13 /var/www/html/test/example-app/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 {main}
  thrown in /var/www/html/test/example-app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 914
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

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.

I'm not very technical in this stuff, but using the franky and the tips, I found this problem and wanted to test & share as someone above had issue with the same approach.

I don't have any urgent usage for this, but just sharing for the info if this is a bug?
And would be good if this would work with this scenario as I was trying to use it that way for convenience.

P.S. didn't want to create a new issue in the repo, as there was already realted discussion in the comments here.
Let me know how I can help further. Thank you

@withinboredom
Copy link
Collaborator

I'd recommend creating a new issue to investigate it properly and it would get more eyes on it. We would need to dig into composer/laravel and figure out what it is doing and whether it is due to them doing something weird/unexpected or FrankenPHP not setting something up properly.

This issue seems more about using composer and less about setting up a laravel project.

@rodrigopedra
Copy link

@withinboredom I'll keep the discussion on the new issue, but as I couldn't reply to you before, I just wanted to give you feedback.

I tested on a fresh Laravel app, created using laravel new franken (which used my system PHP and composer to bootstrap)

Thank I followed the suggestion on creating a local shell script and using a local composer.phar

Laravel doesn't have a class named Application.php, you are right about that.

But composer does:

https://github.com/composer/composer/blob/4e5be9ee7d924d8efc58d676439b0c7bd18a9ce4/src/Composer/Console/Application.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants