如何在 AWS App Runner 上安装 PHP 8.1 Imagick?

huangapple go评论80阅读模式
英文:

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?

我正在安装项目到 AWS App Runner。
项目使用 PHP Imagick,所以我尝试安装它。
我从 GitHub 源代码导入了项目(Laravel 10 + PHP 8.1),并通过配置文件(apprunner.yaml)自动运行它。
我尝试在 build.sh 文件中添加了几行代码,但项目仍然无法获取 Imagick。
如何在 AWS App Runner 的 PHP 运行时中启用 Imagick?

我附上了我的当前代码。

英文:

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

答案1

得分: 0

你的安装看起来一团糟,你混合使用了 php-* 和 php81-php-* 软件包,参见 FAQ

在你的过去,有 EL-7 和 EL-8 的混合指令。

要进行正确的存储库配置和使用,请遵循 向导 中的说明。

简而言之,在 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

但请注意,EL-7 还有大约 1 年左右即将结束生命周期。

简而言之,在 EL-8 或 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

然后

# php --ri imagick

imagick

imagick 模块 => 已启用
imagick 模块版本 => 3.7.0
...

无需构建任何内容,也无需更改任何配置文件。

英文:

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.

答案2

得分: 0

这是我的最终解决方案。


echo "构建"

#基本配置
yum update -y
sudo amazon-linux-extras enable epel
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils -y
yum-config-manager --disable 'remi-php*'
yum-config-manager --enable remi-php81
yum clean metadata
yum update -y php php-cli php-intl php-common php-devel php-fpm php-gd php-mbstring php-mysqlnd php-opcache php-pdo php-process php-xml --disableplugin=priorities

# 安装 PHP Imagick
echo "安装 Imagick 包--------------------------------------------------------------------->>>>>"
sudo yum install -y --enablerepo=remi libstdc++.so.6 LibRaw LibRaw-devel --disableplugin=priorities
yum install -y php-imagick --disableplugin=priorities
php --ri imagick
# 安装 Imagick 结束

echo '检查 imagick 安装状态'
php -m|grep imagick```

<details>
<summary>英文:</summary>

This is my solution finally.

````#!/usr/bin/env bash

echo &quot;build&quot;

#basic configuration
yum update -y
sudo amazon-linux-extras enable epel
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils -y
yum-config-manager --disable &#39;remi-php*&#39;
yum-config-manager --enable   remi-php81
yum clean metadata
yum update -y php php-cli php-intl php-common php-devel php-fpm php-gd php-mbstring php-mysqlnd php-opcache php-pdo php-process php-xml --disableplugin=priorities

# Install PHP Imagick
echo &quot;Installing imagick packages---------------------------------------------------------------------&gt;&gt;&gt;&gt;&gt;&quot;
sudo yum install -y --enablerepo=remi libstdc++.so.6 LibRaw LibRaw-devel --disableplugin=priorities
yum install -y php-imagick --disableplugin=priorities
php --ri imagick
# end install imagick


echo &#39;Check imagick installed status&#39;
php -m|grep imagick````



</details>



huangapple
  • 本文由 发表于 2023年5月21日 02:17:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76296740.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定