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

Built-in health up/ route view does not respect the APP_BASE_PATH environment variable #54310

Open
wojo1206 opened this issue Jan 22, 2025 · 3 comments

Comments

@wojo1206
Copy link

Laravel Version

11.39.1

PHP Version

8.2

Database Driver & Version

Not relevant

Description

When running php artisan optimize, I noticed the built-in health up/ route does not respect the APP_BASE_PATH environment variable. If APP_BASE_PATH differs from __DIR__, this causes the cached path to become invalid. After investigating, I traced the issue to the following file and lines:

src/Illuminate/Foundation/Configuration/ApplicationBuilder.php:

return response(View::file(__DIR__.'/../resources/health-up.blade.php', [
    'exception' => $exception,
]), status: $exception ? 500 : 200);

It might be necessary to publish the view into the views directory first, though I couldn’t find documentation mentioning that. For now, I’ll just disable the up/ route in optimized deployments when APP_BASE_PATH is set.

Steps To Reproduce

  1. Modify Application::configure to enable the health path.
  2. Generate symlink to your app path to simulate alternative path.
  3. Set the symlink to your ENV variable: export APP_BASE_PATH=[YOUR_SYMLINK_PATH]
  4. run php artisan optimize
  5. Inspect the cached file (~/bootstrap/cache/routes-v7.php), and you’ll see the path for up/ does not begin with APP_BASE_PATH.
@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@danielh-official
Copy link

Why would you want to change the APP_BASE_PATH anyway?

And if you're looking to make it configurable, would something like this suffice?

// Config uses an environment variable
$healthUpViewPath = config('app.health_up_view_path', __DIR__.'/../resources/health-up.blade.php');

return response(View::file($healthUpViewPath, [
    'exception' => $exception,
]), status: $exception ? 500 : 200);

@wojo1206
Copy link
Author

@danielh-official Hmm, that might work but isn't ideal. I started my project in Laravel 5 and I have been upgrading continuously to v11. I know that some views could be published (copied to views dir). This route isn't published in my setup and I don't know if the health route feature supports publishing at all.

APP_BASE_PATH is very useful when deploying to read-only environments like AWS Lambda. On deploy, I must build my app on another machine and then move all to Lambda. Lambda has specific entry point (which can't be changed) /var/task where all the code must reside.

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

No branches or pull requests

3 participants