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
。說明:方法一簡單快捷,適用于大多數場景;方法二需手動操作,適合需要特定版本或自定義配置的情況。