phpamazon-web-servicesphp-8.1aws-app-runner

how to install php8.1 imagick on awa app runner?


I am installing project on aws app runner. Project uses php imagick so I tried to install it. I imported project form github source code (Laravel 10 + php 8.1) and running it automatically through configuration file (apprunner.yaml). I tried to add several lines on build.sh file but project still can't get imagick. How to enable this imagick on aws app runner php runtime?

I attached my current code.

#!/usr/bin/env bash

echo "build"

sudo yum list installed | grep php
sudo yum remove php*
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php81
sudo yum install php81
ln -s /usr/bin/php81 /usr/bin/php

# Install Composer & necessary packages
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
    >&2 echo 'ERROR: Invalid installer checksum'
    rm composer-setup.php
    exit 1
fi

php composer-setup.php
rm composer-setup.php

sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo yum -y update
sudo yum-config-manager --enable remi-php81
sudo yum -y install --enablerepo=remi-php81 php81 php81-php php81-php-common php81-php-mbstring php81-php-mysqlnd php81-php-xml php81-php-bcmath php81-php-gd php81-php-intl php81-php-pecl-mcrypt
sudo yum -y install --enablerepo=remi-php81 --disablerepo=amzn2-core php81-php-pecl-zip
sudo yum -y install --enablerepo=remi-php81 php81-php-pecl-imagick-im7
sudo yum -y install --enablerepo=remi-php81 php81-php-fpm php81-php-pecl-apcu php81-php-opcache
yum install nginx -y

# Install dependencies
php composer.phar install

cp -p .env.staging .env
php artisan key:generate
php artisan config:cache
php artisan config:clear
sudo chmod -R 755 ./storage

# Install PHP Imagick
echo "Installing imagick packages--------------------------------------------------------------------->>>>>"
yum install -y libpng-devel libjpeg-devel openjpeg2-devel libtiff-devel libwebp-devel giflib-devel
yum install -y gcc gcc-c++ autoconf automake
pecl install Xdebug
sudo service httpd restart
yum groupinstall "Development Tools" -y
yum install build-essential -y
yum install -y tar
curl -OL https://www.imagemagick.org/download/ImageMagick.tar.gz
tar -vxf ImageMagick.tar.gz
cd ImageMagick*
./configure --prefix=/ \
    --with-bzlib=yes \
    --with-fontconfig=yes --with-freetype=yes \
    --with-gslib=yes --with-gvc=yes \
    --with-jpeg=yes --with-openjp2=yes \
    --with-png=yes \
    --with-tiff=yes \
    --disable-dependency-tracking
make && sudo yum install -y ImageMagick-devel & sudo make install

sudo service nginx stop
sudo service php-fpm stop

yum -y install yum-utils
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php81
yum repolist
echo 'php devel install----------------------------->'
yum install -y php-cli
yum install -y php-pear
yum install -y php-dev php81-php-devel php-devel pcre-devel make
ln -s /usr/bin/phpize81 /usr/bin/phpize
ln -s /usr/bin/pecl81 /usr/bin/pecl
sudo /usr/bin/pecl install imagick
sudo echo "extension=imagick.so" > /etc/php.d/imagick.ini
sudo /etc/init.d/httpd restart

sudo service php-fpm start
sudo service nginx start

echo 'Check imagick installed status'
php -m|grep imagick
echo "Finish imagick packages--------------------------------------------------------------------->>>>>"

# Nginx And PHP-FPM Configuration
cp -p /app/scripts/resources/nginx.conf /etc/nginx/nginx.conf
cp -p /app/scripts/resources/www.conf /etc/php-fpm.d/www.conf

# Directory Permission
chown -R :nginx /app/storage
chown -R :nginx /app/bootstrap/cache
chown -R :nginx /app/public

find /app/storage -type d -exec chmod 775 {} \;
find /app/storage -type f -exec chmod 664 {} \;

find /app/bootstrap/cache -type d -exec chmod 775 {} \;
find /app/bootstrap/cache -type f -exec chmod 664 {} \;

find /app/storage -type d -exec chmod g+s {} \;
find /app/bootstrap/cache -type d -exec chmod g+s {} \;

setfacl -R -d -m g::rwx /app/storage
setfacl -R -d -m g::rwx /app/bootstrap/cache

# Log Configuration
ln -s /dev/stdout /var/log/nginx/error.log
ln -s /dev/stdout /var/log/nginx/access.log

ln -s /dev/stdout /var/log/php-fpm/error.log
ln -s /dev/stdout /var/log/php-fpm/www-access.log
ln -s /dev/stdout /var/log/php-fpm/www-error.log

# NPM Build
echo "node js, npm install"
curl -fsSL https://rpm.nodesource.com/setup_16.x | bash - && yum -y install nodejs
yum install gcc-c++ make -y

echo "npm install"
npm install

echo "npm build"
npm run build

Solution

  • Your installation looks like a mess, you are mixing php-* and php81-php-* packages, see FAQ

    In your past, there is a mix of EL-7 and EL-8 instructions

    For a proper repository configuration an usage, follow the wizard instructions

    In short, on EL-7

    # yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    # yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
    # yum install yum-utils
    # yum-config-manager --enable   remi-php81
    # yum install php-cli php-imagick
    

    But remind that EL-7 is close to its EOL in ~1 year.

    In short, on EL-8 or EL-9

    # dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
    # dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
    # dnf module reset php
    # dnf module install php:remi-8.1
    # dnf install php-cli php-imagick
    

    And then

    # php --ri imagick
    
    imagick
    
    imagick module => enabled
    imagick module version => 3.7.0
    ...
    

    The is no need to build anything, and no need to alter any configuration files.