laravel / sail

Docker files for running a basic Laravel application.
https://laravel.com/docs/sail
MIT License
1.65k stars 474 forks source link

Unable to start due to missing PHP Redis Extension #302

Closed MattHadfield113 closed 2 years ago

MattHadfield113 commented 2 years ago

Description:

All of our docker installs throughout the company are failing due to PHP Redis not being available inside the docker image.

C:\WORKINGPATH>docker run --rm -v "C:\Projects\Dashboard:/opt" -w /opt laravelsail/php80-composer:latest composer install --ignore-platform-reqs
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   LogicException

  Please make sure the PHP Redis extension is installed and enabled.

  at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:77
     73▕     protected function createClient(array $config)
     74▕     {
     75▕         return tap(new Redis, function ($client) use ($config) {
     76▕             if ($client instanceof RedisFacade) {
  ➜  77▕                 throw new LogicException(
     78▕                     extension_loaded('redis')
     79▕                         ? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
     80▕                         : 'Please make sure the PHP Redis extension is installed and enabled.'
     81▕                 );

      +21 vendor frames
  22  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Laravel\Telescope\TelescopeServiceProvider))

      +5 vendor frames
  28  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Trying to run using the following batch file -

docker run --rm -v "%cd%:/opt" -w /opt laravelsail/php80-composer:latest composer install --ignore-platform-reqs

Steps To Reproduce:

Try to run the above command using Docker, downloads latest image, then fails to run due to PHP-Redis being missing. Happening on 4 developer machines at present.

driesvints commented 2 years ago

Instead of docker run, does it work for you with just sail build --no-cache (this will remove all data from linked volumes) and sail up? Please also share your docker-composer.yml file.

MattHadfield113 commented 2 years ago

@driesvints nope tried deleting all the volumes even manually.

Docker-Compose.yml as per below -

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
            - selenium
    mysql:
        image: 'mysql:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - 'sailmysql:/var/lib/mysql'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "mysqladmin", "ping"]
    mysql_test:
      image: 'mysql:8.0'
      environment:
        MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
        MYSQL_DATABASE: '${DB_DATABASE}'
        MYSQL_USER: '${DB_USERNAME}'
        MYSQL_PASSWORD: '${DB_PASSWORD}'
        MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
      volumes:
        - 'sailmysqltest:/var/lib/mysql'
      networks:
        - sail
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
          test: ["CMD", "redis-cli", "ping"]
    selenium:
       image: 'selenium/standalone-chrome'
       volumes:
            - '/dev/shm:/dev/shm'
       networks:
           - sail
       ports:
          - '${FORWARD_SELENIUM_PORT:-4444}:4444'
          - '${FORWARD_SELENIUM_PORT_2:-9515}:9515'
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    meilisearch:
        image: 'getmeili/meilisearch:latest'
        ports:
            - '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
        volumes:
            - 'sailmeilisearch:/data.ms'
        networks:
            - sail
    azureemulator:
        image: 'mcr.microsoft.com/azure-storage/azurite'
        volumes:
          - 'sailazureemulator:/azurestore'
        ports:
          - '${FORWARD_AZURE_PORT_BLOB:-10000}:10000'
          - '${FORWARD_AZURE_PORT_QUEUE:-10001}:10001'
          - '${FORWARD_AZURE_PORT_TABLE:-10002}:10002'
        networks:
          - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailmysqltest:
      driver: local
    sailredis:
        driver: local
    sailmeilisearch:
        driver: local
    sailazureemulator:
      driver: local
MattHadfield113 commented 2 years ago

I should also note that the above is using the command to install the composer requirements as per the docs at -

https://laravel.com/docs/8.x/sail#installing-composer-dependencies-for-existing-projects

driesvints commented 2 years ago

@MattHadfield113 your app is a PHP 8.0 project, correct?

clytras commented 2 years ago

@MattHadfield113 your app is a PHP 8.0 project, correct?

OP states a PHP 8.1 version.

  • Sail Version: 1.12.9
  • Laravel Version: 8.74.0
  • PHP Version: 8.10
  • OS: Windows 10

This is probably a PHP version conflict on Windows if it isn't a typo.

MattHadfield113 commented 2 years ago

@driesvints correct.

driesvints commented 2 years ago

@MattHadfield113 any reason then why you reported this as 8.10?

MattHadfield113 commented 2 years ago

@driesvints apologies, that was a typo, its all running PHP 8.0

taylorotwell commented 2 years ago
CleanShot 2021-12-17 at 11 00 11@2x

Unable to recreate - if you find a bug and can PR a fix feel free.

MattHadfield113 commented 2 years ago

@taylorotwell @driesvints upon further investigation, this happens when the following is set in the .env file -

CACHE_DRIVER=redis

When running the command -

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/var/www/html \
    -w /var/www/html \
    laravelsail/php80-composer:latest \
    composer install --ignore-platform-reqs

This then generates the error of -

 LogicException

  Please make sure the PHP Redis extension is installed and enabled.

  at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:77
     73▕     protected function createClient(array $config)
     74▕     {
     75▕         return tap(new Redis, function ($client) use ($config) {
     76▕             if ($client instanceof RedisFacade) {
  ➜  77▕                 throw new LogicException(
     78▕                     extension_loaded('redis')
     79▕                         ? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
     80▕                         : 'Please make sure the PHP Redis extension is installed and enabled.'
     81▕                 );

      +21 vendor frames
  22  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Laravel\Telescope\TelescopeServiceProvider))

      +5 vendor frames
  28  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Setting cache driver back as per below resolves the issue -

CACHE_DRIVER=file

Therefore i would suggest that laravelsail/php80-composer:latest is missing the Redis extension, thus causing the error.

driesvints commented 2 years ago

@MattHadfield113 to be fair, you shouldn't set your cache store when running this command. It's only intended to run at the beginning when you're first installing your dependencies. Just unset the env variable for now to run the command.

MatanYadaev commented 2 years ago

@driesvints I also encountered this issue right now. Yes, I can unset the env variable just before executing this command, but because it's part of my .env.example I wonder if there are better solutions/workarounds. I am looking to make new developers' onboarding as easy as possible.

driesvints commented 2 years ago

I understand but I think it's best to document this internally for now.

plakhin commented 2 years ago

I'm also experience the error. In my case the problem is that php for some reason is 8.1 instead of 8.0

After sail build --no-cache && sail up:

stan@thinkpad:~/www/projectx$ sail shell
sail@de41c47ee716:/var/www/html$ php -v
PHP 8.1.1 (cli) (built: Dec 31 2021 07:26:38) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.1, Copyright (c), by Zend Technologies
sail@de41c47ee716:/var/www/html$ which php
/usr/bin/php
sail@de41c47ee716:/var/www/html$ php8.
php8.0  php8.1
sail@de41c47ee716:/var/www/html$ php8.0 -v
PHP 8.0.14 (cli) (built: Dec 20 2021 21:23:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.14, Copyright (c), by Zend Technologies
    with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans
sail@de41c47ee716:/var/www/html$

Sail Version: 1.13 Laravel Version: 8.77.1 OS: Windows 10 + WSL2

docker-compose.yml:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
...
plakhin commented 2 years ago

I guess #314 is related since php8.0 inside the container has all needed extensions, however php8.1 doesn't