Ubuntu下配置PHP的GD库主要有两种方法,以下是具体步骤:
sudo apt update
sudo apt install php8.0-gd
或通用命令:sudo apt install php-gd
sudo systemctl restart apache2
sudo systemctl restart php8.0-fpm nginx
info.php文件(内容:<?php phpinfo(); ?>),上传至服务器根目录,访问并搜索“GD”确认。sudo apt update
sudo apt install build-essential libpng-dev libjpeg-dev libfreetype6-dev
wget https://www.php.net/distributions/php-8.0.26.tar.gz
tar -zxvf php-8.0.26.tar.gz
cd php-8.0.26/ext/gd
phpize
./configure --with-gd --with-png-dir=/usr --with-jpeg-dir=/usr --with-freetype-dir=/usr
make
sudo make install
php.ini,取消;extension=gd前的分号,或添加extension=gd.so。说明:方法一简单快捷,适用于大多数场景;方法二需手动操作,适合需要特定版本或自定义配置的情况。