Skip to content

[Feature Request] Support starting web server without .env file #69

@foremtehan

Description

@foremtehan

PHP Version

8.4

Swoole Extension Version

6.0.2

Description

For security reasons, I only pass .env content (not the file itself) via docker compose env_file attribute.

But as soon we start the server we get thousands of errors like this in the terminal:

[2025-05-01 13:34:41 $861.0]    WARNING Worker::report_error(): worker(pid=956, id=0) abnormal exit, status=255, signal=0
[2025-05-01 13:34:41 *959.1]    ERROR   php_swoole_server_rshutdown() (ERRNO 503): Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/var/www/html/.env]. in /var/www/html/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /var/www/html/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /var/www/html/vendor/hyperf/support/src/DotenvManager.php(34): Dotenv\Dotenv->load()
#2 /var/www/html/vendor/hyperf/support/src/DotenvManager.php(40): Hyperf\Support\DotenvManager::load()
#3 /var/www/html/vendor/hypervel/foundation/src/Listeners/ReloadDotenvAndConfig.php(60): Hyperf\Support\DotenvManager::reload()
#4 /var/www/html/vendor/hypervel/foundation/src/Listeners/ReloadDotenvAndConfig.php(45): Hypervel\Foundation\Listeners\ReloadDotenvAndConfig->reloadDotenv()
#5 /var/www/html/vendor/hypervel/event/src/EventDispatcher.php(241): Hypervel\Foundation\Listeners\ReloadDotenvAndConfig->process()
#6 /var/www/html/vendor/hypervel/event/src/EventDispatcher.php(152): Hypervel\Event\EventDispatcher->{closure:Hypervel\Event\EventDispatcher::createClassListener():237}()
#7 /var/www/html/vendor/hypervel/event/src/EventDispatcher.php(75): Hypervel\Event\EventDispatcher->invokeListeners()
#8 /var/www/html/vendor/hyperf/framework/src/Bootstrap/WorkerStartCallback.php(36): Hypervel\Event\EventDispatcher->dispatch()
#9 [internal function]: Hyperf\Framework\Bootstrap\WorkerStartCallback->onWorkerStart()
#10 {main}
  thrown in /var/www/html/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68

Steps To Reproduce

services:
  hypervel:
    container_name: hypervel
    image: hypervel/app:latest
    build: .
    env_file:
      - ./.env

I don't need to put .env file in the root because of the above config, I do these steps via appleboy/ssh-action github action in my server not the container. It ssh to my server and deploy my app like:

github workflow:

script: |
         echo '${{ secrets.ENV_FILES }}' > .env
         docker compose up -d 


In the current situation, I have only two options: either push the .env file to github or build the image with the .env file included, both are risky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions