Robskiwarrior's avatar

Production Laravel Octane HTTPS Error fix

TLDR: Add "OCTANE_HTTPS=true" in your .env file.

Just wanted to point out to help anyone who is trying to use Octane, I chose FrankenPHP, but I am guessing this is a setting that is required for any way you chose to go:

After installing I was getting CORS errors because for some reason the server was calling the scripts and styles from a non secure url. This was a little confusing at first but long story short, the documentation needs to be read.

Add in your env file:

OCTANE_HTTPS=true

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue of Laravel Octane serving assets over non-secure URLs, which can lead to CORS errors, you need to ensure that Octane is aware that it should serve content over HTTPS. This is particularly important when running in a production environment where HTTPS is expected.

The solution is to set the OCTANE_HTTPS environment variable to true in your .env file. This instructs Laravel Octane to generate URLs with the https scheme, ensuring that all assets and resources are served securely.

Here's how you can do it:

  1. Open your .env file located in the root of your Laravel project.

  2. Add the following line to the file:

    OCTANE_HTTPS=true
    
  3. Save the changes to your .env file.

By setting OCTANE_HTTPS=true, you inform Laravel Octane to treat all URLs as secure, which should resolve the CORS errors related to mixed content (i.e., trying to load resources over HTTP when the page is served over HTTPS).

After making this change, restart your Octane server to ensure the new environment variable is loaded:

php artisan octane:restart

This should resolve the issue with non-secure URLs and CORS errors when using Laravel Octane in a production environment.

Please or to participate in this conversation.