简体   繁体   中英

How to install GD Library? Laravel at AWS Lambda with Bref

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM