laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.18k stars 10.89k forks source link

Schedule:run command fails due to missing PHP in FrankenPHP binary #52675

Open jurrid opened 1 week ago

jurrid commented 1 week ago

Laravel Version

11.22

PHP Version

8.3

Database Driver & Version

Sqlite

Description

I’m using a FrankenPHP binary and trying to add the schedule:run command to the crontab. However, I’m encountering an error where PHP cannot be found, which is expected because the binary is running on a clean DigitalOcean (DO) VPS with no PHP. I suspect the issue lies in the Schedule::class’s command function, which only returns the Artisan path as a string.

I’m unsure whether this is a Laravel, Symfony, or FrankenPHP issue, but I’m starting by reporting it here in the Laravel framework repo.

Steps To Reproduce

  1. Create a clean Linux VPS (I tested on the smallest DigitalOcean droplet: Ubuntu 24.04 x64, 512 MB Memory, 10 GB Disk).

  2. Run the following command to create the necessary Laravel storage directories:

    mkdir -p /root/storage/app /root/storage/logs /root/storage/framework/cache /root/storage/framework/sessions /root/storage/framework/testing /root/storage/framework/views
  3. Upload the FrankenPHP binary to the /root folder on the VPS and make the file executable:

    
    wget https://github.com/jurrid/frankenphp/raw/main/frankenphp.tar.gz;

tar -xvf frankenphp.tar.gz;

chmod +x /root/frankenphp;


4. Run the following command to create a sqlite database:
```bash
touch /root/storage/database.sqlite;

/root/frankenphp php-cli artisan migrate:fresh --force;
  1. Attempt to run the command:

    /root/frankenphp php-cli artisan schedule:run
  2. Observe the failure.

Additional Information:

driesvints commented 1 week ago

@dunglas do you might know if there's anything obvious we're missing here? 🤔

rodrigopedra commented 1 week ago

The ScheduleRunCommand calls Application::phpBinary() which then uses Symfony\Component\Process\PhpExecutableFinder to find PHP's binary.

@jurrid, can you test, like in a simple script, if Symfony\Component\Process\PhpExecutableFinder can find PHP's binary when running from a FrakenPHP installation?

I don't have any FrakenPHP projects in hand, and I am out-of-office, thus away from my work machine.

The code used by Application::phpBinary() seems pretty straightforward:

(new PhpExecutableFinder)->find(false);

If it can't, maybe it is best to report it to Symfony.

dunglas commented 1 week ago

As a quick workaround, storing this script in your PATH should fix the issue.

A better long term solution would indeed be to add support for FrankenPHP in Symfony\Component\Process\PhpExecuyableFinder.

jurrid commented 1 week ago

I ran the test on the VPS, and here’s the output:

/tmp/frankenphp_4903f3929bf859903322f1f81c789b25/artisan

The binary in the linked GitHub repo has been updated for anyone who wants to test this output as well.

/root/frankenphp php-cli artisan app:output-binary

As suggested by @dunglas , one option is to follow his PATH approach. Alternatively, if your scheduling isn’t too complex, like mine, you can manually add the commands to the crontab without using Laravel’s schedule:run.

For now, I think the Laravel issue can be closed. I will report this issue on the Symfony repo.

jurrid commented 1 week ago

Issue reported on the Symfony repo