laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.78k stars 296 forks source link

The system environment variables got overrided by the .env #244

Closed litan1106 closed 3 years ago

litan1106 commented 3 years ago

Description:

The system environment variables got override by the .env in Octane but not php-fpm or php-cli. The system environment variables shouldn't be override by the .env in Octane.

Steps To Reproduce: (max and linux)

  1. Test the laravel/octane in composer.json to v0.2.0
"laravel/octane": "~0.2.0",
  1. Add a test route to web.php
Route::get('test-sys-vars', function() {
    var_dump($_ENV['DB_USERNAME']);
    var_dump(config('database.connections.mysql.username'));
    var_dump(getenv('DB_USERNAME'));
    var_dump(getenv('DB_USERNAME', true));
    dd(env('DB_USERNAME'));
});
  1. Run command in the current Laravel project directory.

    export DB_USERNAME=example-app && php -dvariables_order=EGPCS artisan octane:start --server=roadrunner --host=0.0.0.0 --port=8000
  2. Make sure DB_USERNAME exists in the .env

    DB_USERNAME=homestead
  3. Browse http://localhost:8000/test-sys-vars and see result

Then repeat 1 - 5 again with another version

"laravel/octane": "^0.4.0",

image

nunomaduro commented 3 years ago

I wasn't able to reproduce this issue locally. Do you also face the issue when not using sail?

robean01 commented 3 years ago

I also have the same problem and I'm not using sail - I had to switch back to 0.2.0 to get it working.

litan1106 commented 3 years ago

I also have the same problem and I'm not using sail - I had to switch back to 0.2.0 to get it working.

Thanks for the confirmation. I switched back to v0.2.0, it worked for me too. @nunomaduro Somehow, it was broken after v0.2.0 (I just updated the steps to reproduce it.)

litan1106 commented 3 years ago

@nunomaduro maybe caused by these changes? I reverted this line on v0.3.2 and 0.4.0. everything worked like v0.20

image

https://github.com/laravel/octane/compare/v0.2.0...v0.3.2#diff-d86e0d58256c86388b8241b36f32171f8b2156aa131e205ddd18b13d7afb5825L82-R866

L3o-pold commented 3 years ago

I can confirm seeing this issue with v0.3.2+ using Kubernetes. Rolling back to v0.3.1 fixed it. But an important note is that we don't have any .env file (only environment variables) and Octane are not seing them.

   WARN  Laravel Octane is within a beta period. It should only be used for local development and testing in order to improve the quality of the library and resolve any existing bugs.

   INFO  Server running…

  Local: http://0.0.0.0:8080 

  Press Ctrl+C to stop the server

   Illuminate\Encryption\MissingAppKeyException  No application encryption key has been specified.
nunomaduro commented 3 years ago

Currently investigating this...

L3o-pold commented 3 years ago

I prepared a sample Dockerfile for you if needed.

FROM php:8.0.3-cli-buster

RUN apt-get update && apt-get install -y \
    git \
    unzip \
    libzip-dev \
    && rm -rf /var/lib/apt/lists/*

RUN pecl install swoole

RUN docker-php-ext-install pcntl zip \
    && docker-php-ext-enable swoole.so pcntl.so zip.so

RUN curl -sS https://getcomposer.org/installer | php -- --$COMPOSER && mv composer.phar /usr/bin/composer

WORKDIR /var/www/html

RUN composer create-project laravel/laravel example-app

WORKDIR /var/www/html/example-app

RUN composer require laravel/octane \
    && php artisan octane:install --server=swoole

RUN rm /var/www/html/example-app/.env

# dummy APP_KEY env var
ENV APP_KEY=vvVmYOwJCBY5k0Kr5ykVGe1qYbNNCGJL

EXPOSE 80

CMD ["php", "artisan", "octane:start", "--server=swoole", "--host=0.0.0.0", "--port=80"]
docker build -t test . && docker run test:latest
WARN  Laravel Octane is within a beta period. It should only be used for local development and testing in order to improve the quality of the library and resolve any existing bugs.

   INFO  Server running…

  Local: http://0.0.0.0:80 

  Press Ctrl+C to stop the server

   Illuminate\Encryption\MissingAppKeyException 

  No application encryption key has been specified.

  at vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:79
     75▕     protected function key(array $config)
     76▕     {
     77▕         return tap($config['key'], function ($key) {
     78▕             if (empty($key)) {
  ➜  79▕                 throw new MissingAppKeyException;
     80▕             }
     81▕         });
     82▕     }
     83▕ }
foremtehan commented 3 years ago

Do you think this also affect this issue ? https://github.com/laravel/octane/issues/234

the python keyword as system env didnt work in 0.3.2+ but it work in 0.3.1

litan1106 commented 3 years ago

Do you think this also affect this issue ? #234

the python keyword as system env didnt work in 0.3.2+ but it work in 0.3.1

Nope. I am sure that was caused by this change. ( I already tested it. )

image

https://github.com/laravel/octane/compare/v0.3.1...v0.3.2#diff-d86e0d58256c86388b8241b36f32171f8b2156aa131e205ddd18b13d7afb5825L86

zolotov88 commented 3 years ago

Same issue

nunomaduro commented 3 years ago

@zolotov88 @litan1106 @foremtehan @L3o-pold @anopier Can you all test this branch? https://github.com/laravel/octane/pull/257.

L3o-pold commented 3 years ago

@nunomaduro from my test case here https://github.com/laravel/octane/issues/244#issuecomment-829188654 the issue seems fixed 👍

litan1106 commented 3 years ago

@nunomaduro This PR fixed my system env issue as well. Thanks again.