Ubuntu Linux:向Apache Web服务器安装或者添加PHP-GD支持

时间:2020-01-09 10:45:39  来源:igfitidea点击:

如何在Apache/PHP5上安装install php gd支持,以便在Ubuntu Linux LTS下动态处理镜像? PHP主要与各种插件一起用于服务器端应用程序软件中。 PHP包含大量带有核心版本的免费和开源库。

PHP是一个基本的Internet感知系统,其内置的模块可用于访问FTP服务器,许多数据库服务器,嵌入式SQL库(例如嵌入式MySQL和SQLite),LDAP服务器等。
标准PHP构建中提供了C程序员熟悉的许多功能,例如stdio系列中的那些功能。

GD图形库,用于动态处理镜像。
您将需要使用具有镜像功能的GD库的PHP进行编译,以使其起作用。
然而。

Ubuntu(和Debian)Linux附带了名为php5-gd的软件包。
只需执行以下命令即可安装此模块:

# apt-get install php5-gd

或者

$ sudo apt-get install php5-gd

示例输出(来自我的Debian服务器)

apt-get install php5-gd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libgd2-xpm
Suggested packages:
  libgd-tools
The following packages will be REMOVED:
  libgd2-noxpm
The following NEW packages will be installed:
  libgd2-xpm php5-gd
0 upgraded, 2 newly installed, 1 to remove and 7 not upgraded.
Need to get 270 kB of archives.
After this operation, 176 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://debian.osuosl.org/debian/ squeeze/main libgd2-xpm amd64 2.0.36~rc1~dfsg-5 [231 kB]
Get:2 http://security.debian.org/ squeeze/updates/main php5-gd amd64 5.3.3-7+squeeze9 [39.1 kB]
Fetched 270 kB in 2s (124 kB/s)                                      
dpkg: libgd2-noxpm: dependency problems, but removing anyway as you requested:
libgvc5 depends on libgd2-noxpm (>= 2.0.36~rc1~dfsg) | libgd2-xpm (>= 2.0.36~rc1~dfsg); however:
  Package libgd2-noxpm is to be removed.
  Package libgd2-xpm is not installed.
(Reading database ... 206928 files and directories currently installed.)
Removing libgd2-noxpm ...
Selecting previously deselected package libgd2-xpm.
(Reading database ... 206919 files and directories currently installed.)
Unpacking libgd2-xpm (from .../libgd2-xpm_2.0.36~rc1~dfsg-5_amd64.deb) ...
Setting up libgd2-xpm (2.0.36~rc1~dfsg-5) ...
Selecting previously deselected package php5-gd.
(Reading database ... 206930 files and directories currently installed.)
Unpacking php5-gd (from .../php5-gd_5.3.3-7+squeeze9_amd64.deb) ...
Processing triggers for libapache2-mod-php5 ...
Reloading web server config: apache2.
Setting up php5-gd (5.3.3-7+squeeze9) ...

最后,重新启动Apache 2 Web服务器,执行:

# /etc/init.d/apache2 restart

现在,您可以测试您的php应用程序了。

如何验证是否加载了php5-gd支持?

在shell提示符下执行以下命令:

$ php5 -m | grep -i gd

输出示例:

gd

或者

$ php5 -i | grep -i --color gd

或者

$ php -i | grep -i --color gd

输出示例:

Additional .ini files parsed -  /etc/php5/cli/conf.d/gd.ini,
gd
GD Support -  enabled
GD Version -  2.0
gd.jpeg_ignore_warning -  0 -  0
XAUTHORITY -  /var/run/gdm3/auth-for-Hyman-ruJHl1/database
_SERVER["XAUTHORITY"] -  /var/run/gdm3/auth-for-Hyman-ruJHl1/database

您还可以使用以下php代码。
创建一个名为test.php的文件,并将其放置在Web服务器目录中,即Apache DocumentRoot(例如/var/www):

<?php
  phpinfo();
?>

如下运行:

http://your-server-ip/test.php

寻找GD扩展名。