2

When using Intervention\Image in laravel on lambda The following error has occurred. By the way, it works in the local environment.

I have to add gd.

[2021-08-17 10:37:18] DEV.ERROR: GD Library extension not available with this PHP installation. {"exception":"[object] (Intervention\Image\Exception\NotSupportedException(code: 0): GD Library extension not available with this PHP installation. at /var/task/vendor/intervention/image/src/Intervention/Image/Gd/Driver.php:19)

What I looked up

https://bref.sh/docs/environment/php.html#extensions

https://github.com/brefphp/extra-php-extensions

Deployment method

We are deploying to lambda using the sls command.

sls deploy --stage dev

Based on the investigation, the following is implemented

composer require bref/extra-php-extensions

Added below serverless.yml


plugins:
    - ./vendor/bref/bref
    - ./vendor/bref/extra-php-extensions #add

functions:
    # This function runs the Laravel website/API
    web:
        image:
            name: laravel
        events:
            -   httpApi: '*'
    # This function lets us run artisan commands in Lambda
    artisan:
        handler: artisan
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-80}
            - ${bref:layer.console}
            - ${bref-extra:gd-php-80} #add

Even if the above settings are added and deployed, they are not updated. .. why?

enviroment

  • Laravel Framework 8.33.1
  • PHP 7.4.3
  • bref
  • serverless

I'm sorry if English is strange.

  • Looking at the [documentation](https://bref.sh/docs/environment/php.html#customizing-phpini-in-extra-layers) it seems you still need to register the extension in a custom *.ini file. Have you tried this? – nitrin0 Aug 26 '21 at 16:43
  • Thank you for your reply Before that, the way to write serverless.yml was strange. I'll fix that. However, an error has occurred. What should I do in this case? `An error occurred: WebLambdaFunction - Resource handler returned message: "Please don't provide Handler or Runtime or Layer when the intended function PackageType is Image.` edit `serverless.yml edit. add functions->web add layers` – ニホニウム Aug 27 '21 at 03:18
  • @nitrin0 I am also facing the same issue. I've added the changes in serverless.yml file after installing the required package using composer. Then I created a custom ini file. Now it is showing only {"message":"Internal Server Error"} – Muhammed Shihabudeen Labba A Oct 05 '21 at 06:45
  • @Muhammed Shihabudeen Labba A I know the cause. [aws blog in japanese](https://aws.amazon.com/jp/blogs/news/working-with-lambda-layers-and-extensions-in-container-images/) ↑ Layers cannot be added to the container image. So you need to add a layer to the container image itself and include it in the image. But I don't know how to include it in the container image. I would add it by writing it in the Dockerfile ... Please let me know if you understand. – ニホニウム Oct 05 '21 at 10:09
  • @Muhammed How about this?Dockerfile edit. FROM bref/php-80-fpm COPY . /var/task COPY --from=bref/extra-gd-php-80 /opt /opt CMD [ "public/index.php" ] – ニホニウム Oct 20 '21 at 12:52
  • @ニホニウム I just followed the bref document to install extra php extensions and later I have checked whether it is installed or not using the command echo "GD: ", extension_loaded('gd') ? 'OK' : 'MISSING', '
    ';
    – Muhammed Shihabudeen Labba A Oct 20 '21 at 15:09
  • @Muhammed I can't answer because I don't know what you're doing right now. So, which site can you see only in Japanese? Especially in the comments section https://teratail.com/questions/362103 – ニホニウム Oct 21 '21 at 06:33

1 Answers1

0

Put the layers into web "tag".

plugins:
    - ./vendor/bref/bref
    - ./vendor/bref/extra-php-extensions #add

functions:
    # This function runs the Laravel website/API
    web:
        image:
            name: laravel
        layers:
            - ${bref-extra:gd-php-80} #add
        events:
            -   httpApi: '*'
    # This function lets us run artisan commands in Lambda
    artisan:
        handler: artisan
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-80}
            - ${bref:layer.console}

Then add the folder php/conf.d inside put a file with extension .ini. For example php.ini. In it just put:

extension=gd
Camilo
  • 1
  • 1