PHP-Imagick Enable and Increase MAX Size of php.ini on AWS App Runner

0

How to enable php-imagick on AWS App Runner (PHP 8.1) and increase post_max_size, upload_max_filesize, and memory_limit on it?

Michael
asked a year ago471 views
2 Answers
1
Accepted Answer

Hello

The App Runner Service Team is currently looking into the issue. However as a workaround you can use an image.

I was able to create an image using the below sample Dockerfile and successfully deployed it to App Runner.

===Dockerfile===

FROM --platform=linux/amd64 php:8.1.0-fpm
WORKDIR /app
COPY ./index.php ./
RUN apt-get update; \
    apt-get install -y libmagickwand-dev; \
    pecl install imagick; \
    docker-php-ext-enable imagick;
RUN echo "upload_max_filesize = 200M" >> /usr/local/etc/php/php.ini
RUN echo "post_max_size= 10M" >> /usr/local/etc/php/php.ini
RUN echo "memory_limit = 128M" >> /usr/local/etc/php/php.ini
EXPOSE 3000
CMD ["php","-S", "0.0.0.0:3000"]

===Dockerfile===

Thank you!

AWS
answered a year ago
0

This is my build.sh file. I tried to enable imagick but no luck yet. How to enable imagick on aws app runner PHP 8.1 runtime?

#!/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

Michael
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions