重新编译GD扩展

哪有什么坚强,不过都是硬撑罢了。

编译安装php7.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/php.d \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-fpm \
--enable-opcache \
--disable-fileinfo \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype \
--with-jpeg \
--with-zlib \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-exif \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl=/usr/local/curl \
--enable-mbregex \
--enable-mbstring \
--with-password-argon2 \
--with-sodium=/usr/local \
--enable-gd \
--with-openssl=/usr/local/openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-ftp \
--enable-intl \
--with-xsl \
--with-gettext \
--with-zip=/usr/local \
--enable-soap \
--disable-debug \
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:

今天就出现了一个问题,我的gd库中没有webp支持,看看错误提示

1
Call to undefined function imagecreatefromwebp()

重新编译GD库

重新编译gd,但是又由于我采用的是静态编译,所以必须要重新编译php,然后编译gd,最后在php.ini文件中添加扩展so文件。

重新编译php

不要添加 --enable-gd 参数即可

编译GD

1
yum install libwebp-devel libwebp autoconf automake gcc libjpeg-devel libpng-devel libXpm-devel freetype-devel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
wget https://www.php.net/distributions/php-7.4.28.tar.bz2
tar xf php-7.4.28.tar.bz2
cd php-7.4.28
cd ext/gd/
phpize

## Run the actual configure

./configure --with-php-config=/usr/local/php/bin/php-config --with-gd --enable-gd --with-jpeg=/usr/include --with-webp=/usr/include/webp

make && make install

## Copy new gd.so file in place, backup old one
cp /usr/lib64/php/modules/gd.so ~/gd.so.bak
cp /var/www/php-7.4.28/ext/gd/modules/gd.so /usr/lib64/php/modules/gd.so

# Right after, otherwise server goes down.
sudo service httpd restart

# Check if WebP support is enabled:
php -r "print_r( gd_info() );"

编辑php.ini

1
2
3
echo extension=gd.so >> /usr/local/php/lib/php.ini

extension = gd.so
1
systemctl reload php-fpm

其他

尚未尝试

1
--enable-gd --with-webp --with-jpeg  --with-freetype --enable-gd-jis-conv  --with-iconv-dir=/usr/local/lib