2

I discovered an issue with our Laravel project during a fresh installation. When I cloned the entire project and created the env file, I proceeded to install Sail containers and the existing Composer package file by executing the following command as per the official Sail documentation:

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

After running the above command, I encountered this error message:

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Error

  Class "Redis" not found

  at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:81
     77▕      * @throws \LogicException
     78▕      */
     79▕     protected function createClient(array $config)
     80▕     {
  ➜  81▕         return tap(new Redis, function ($client) use ($config) {
     82▕             if ($client instanceof RedisFacade) {
     83▕                 throw new LogicException(
     84▕                     extension_loaded('redis')
     85▕                         ? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'

      +19 vendor frames

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

  26  artisan:35
      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

I suspect that laravelsail/phpxx-composer image does not have the Redis extension installed, but I'm unsure how to address this issue.

For reference, the Laravel version is v10, we are using phpredis, and our PHP version is v8.2.

7
  • 1
    It should; do sail tinker and put extension_loaded('redis') in it to check. See github.com/laravel/sail/issues/302 for a discussion of a similar issue in 8.0/8.1. Commented Jun 16, 2023 at 12:56
  • added to the composer.json? "require": { "predis/predis": "^2.0", }, Commented Jun 16, 2023 at 13:11
  • @ceejayoz There is no container to check. It is just laravelsail/phpxx-composer. Nothing created yet Commented Jun 16, 2023 at 13:28
  • @ЛюбомирГорбей as I mentioned I'm using phpredis. Should i require predis package? Commented Jun 16, 2023 at 13:29
  • 2
    try: docker run --rm -p 6379:6379 redis . Should i require predis package? -Yes Commented Jun 16, 2023 at 13:42

1 Answer 1

2

Your .env file breaks the installation. They intended this command to be run on clear repo clone where .env file should not be committed as a good practice. To install vendor packages you don't need this configuration, just like --ignore-platform-reqs skips all extensions checks on Laravel side config cannot rely on them (here Redis) either.

IMO simplest fix is to add -e "CACHE_DRIVER=file" \ to the docker command that you took from Laravel docs:

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

Your millage may vary. If you use other config options / deps, they may need additional configuration resets. With long list of those you may consider --env-file docker options to provide an empty file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.