欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php遇到错误Call to undefined function ImageCreate()解决方法

程序员文章站 2022-06-15 15:46:26
目录常规ubuntu与windows编译make安装方法phpize方法centos安装gd库在使用php处理一些图像时,有时会出现诸如这样的错误:call to undefined function...

在使用php处理一些图像时,有时会出现诸如这样的错误:call to undefined function imagecreate()

这是由于没有安装或是没有开启php的gd库导致的问题。

常规ubuntu与windows

解决方案:

一、在linux系统(这里用的是ubuntu系统)下

首先在终端输入下列命令:

sudo apt-get install php5-gd

这样就已经安装完php的gd库了。如果使用的是apache服务器,这时还需重启下服务器:

sudo service apache2 restart

如果是nginx则可用可不用。

二、在windows系统下

打开php安装目录下的php.ini配置文件,找到这一行:

;extension=php_gd2.dll

将这一行前面的;号去掉,然后保存。这样已经开启了gd扩展库。

最后重启下服务器就行了。

编译make安装方法

在编译配置扩展的时候就没加上gd的同学可以参考下面的方法

找到安装php的目录下,重新配置扩展

make clean
./configure --prefix=/png/php/5.6.40 --enable-fpm --with-apxs2=/usr/bin/apxs2 --enable-maintainer-zts -with-mysqli --with-pdo-mysql --with-pdo-sqlite --with-gd
make
make test
make install

./configure --with-gd有了就行,其他的扩展看需求

vim打开php.ini

搜索

#vim命令关键字搜索: (1) 点esc (2)/“关键字”

/extension=php_gd2.dll

找到这行去掉前面的分号“;”

php遇到错误Call to undefined function ImageCreate()解决方法

保存退出,重启nginx,apache2重启apache2

/etc/init.d/httpd restart

php遇到错误Call to undefined function ImageCreate()解决方法

index.php查找gd,,,成功!

phpize方法

原因:未安装php的gd库,主要处理图片的库

解决方法:

在已经安装php的情况先,需要对php进行扩展,加入gd库

1:进入到php源码里面的gd目录下

cd /usr/src/php-5.5.38/ext/gd/

2:执行phpize (命令在php/bin/目录下)

phpize

3:编译安装

./configure --with-php-config=/usr/local/php5/bin/php-config --with-png-dir --with-freetype-dir --with-jpeg-dir --with-gd
make
make install

会报错,执行下面命令:

yum install libpng
yum install libpng-devel
yum install freetype-devel

此时安装完成后会生成一个gd.so的文件,记住这个路径

ls /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/
curl.so gd.so opcache.so pcntl.so pdo_mysql.so

4:修改php的配置文件php.ini将gd.so的路径加入进去,如下加入到最后面就行

vim /usr/local/php5/php.ini
[root@slb03 ~]# tail -1 /usr/local/php5/php.ini
extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/gd.so

5:重启apache服务

/etc/init.d/httpd restart

centos安装gd库

采用phpize的方式安装,也不成功

提示cannot find config.m4.

[root@hotdata gd]# php -i | grep -i --color gd
pwd => /usr/include/php/ext/gd
_server["pwd"] => /usr/include/php/ext/gd

[root@hotdata gd]# yum -y install m4
loaded plugins: security
setting up install process
package m4-1.4.13-5.el6.x86_64 already installed and latest version
nothing to do
[root@hotdata gd]# yum -y install autoconf
loaded plugins: security
setting up install process
package autoconf-2.63-5.1.el6.noarch already installed and latest version
nothing to do
[root@hotdata gd]# /usr/bin/phpize 
cannot find config.m4. 
make sure that you run '/usr/bin/phpize' in the top level source directory of the module

直接使用yum命令安装不成功,错误信息如下:
主要提示信息为需要安装依赖包,可是我已经安装了

# yum install gd gd-devel php-gd
loaded plugins: security
setting up install process
package gd-2.0.35-11.el6.x86_64 already installed and latest version
resolving dependencies
--> running transaction check
---> package gd-devel.x86_64 0:2.0.35-11.el6 will be installed
--> processing dependency: libpng-devel for package: gd-devel-2.0.35-11.el6.x86_64
--> processing dependency: libjpeg-devel for package: gd-devel-2.0.35-11.el6.x86_64
--> processing dependency: libxpm-devel for package: gd-devel-2.0.35-11.el6.x86_64
--> processing dependency: libx11-devel for package: gd-devel-2.0.35-11.el6.x86_64
--> processing dependency: freetype-devel for package: gd-devel-2.0.35-11.el6.x86_64
--> processing dependency: fontconfig-devel for package: gd-devel-2.0.35-11.el6.x86_64
---> package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
--> processing dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
--> processing dependency: libt1.so.5()(64bit) for package: php-gd-5.4.45-56.el6.art.x86_64
--> running transaction check
---> package fontconfig-devel.x86_64 0:2.8.0-5.el6 will be installed
---> package freetype-devel.x86_64 0:2.3.11-17.el6 will be installed
--> processing dependency: freetype = 2.3.11-17.el6 for package: freetype-devel-2.3.11-17.el6.x86_64
---> package libx11-devel.x86_64 0:1.6.4-3.el6 will be installed
--> processing dependency: libx11 = 1.6.4-3.el6 for package: libx11-devel-1.6.4-3.el6.x86_64
--> processing dependency: pkgconfig(xcb) >= 1.11.1 for package: libx11-devel-1.6.4-3.el6.x86_64
--> processing dependency: pkgconfig(xproto) for package: libx11-devel-1.6.4-3.el6.x86_64
--> processing dependency: pkgconfig(xcb) for package: libx11-devel-1.6.4-3.el6.x86_64
--> processing dependency: pkgconfig(kbproto) for package: libx11-devel-1.6.4-3.el6.x86_64
---> package libxpm-devel.x86_64 0:3.5.10-2.el6 will be installed
--> processing dependency: libxt.so.6()(64bit) for package: libxpm-devel-3.5.10-2.el6.x86_64
---> package libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5 will be installed
---> package libpng-devel.x86_64 2:1.2.49-2.el6_7 will be installed
---> package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
--> processing dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
---> package t1lib.x86_64 0:5.1.2-6.el6_2.1 will be installed
--> running transaction check
---> package freetype.x86_64 0:2.3.11-15.el6_6.1 will be updated
---> package freetype.x86_64 0:2.3.11-17.el6 will be an update
---> package libx11.x86_64 0:1.6.0-6.el6 will be updated
---> package libx11.x86_64 0:1.6.4-3.el6 will be an update
--> processing dependency: libx11-common = 1.6.4-3.el6 for package: libx11-1.6.4-3.el6.x86_64
---> package libxt.x86_64 0:1.1.4-6.1.el6 will be installed
---> package libxcb-devel.x86_64 0:1.12-4.el6 will be installed
--> processing dependency: libxcb = 1.12-4.el6 for package: libxcb-devel-1.12-4.el6.x86_64
--> processing dependency: pkgconfig(xau) >= 0.99.2 for package: libxcb-devel-1.12-4.el6.x86_64
--> processing dependency: libxcb-xkb.so.1()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
--> processing dependency: libxcb-xinput.so.0()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
--> processing dependency: libxcb-sync.so.1()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
--> processing dependency: libxcb-present.so.0()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
--> processing dependency: libxcb-dri3.so.0()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
---> package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
--> processing dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
---> package xorg-x11-proto-devel.noarch 0:7.7-14.el6 will be installed
--> running transaction check
---> package libx11-common.noarch 0:1.6.0-6.el6 will be updated
---> package libx11-common.noarch 0:1.6.4-3.el6 will be an update
---> package libxau-devel.x86_64 0:1.0.6-4.el6 will be installed
---> package libxcb.x86_64 0:1.9.1-3.el6 will be updated
---> package libxcb.x86_64 0:1.12-4.el6 will be an update
---> package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
--> processing dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
--> finished dependency resolution
error: package: php-gd-5.4.45-56.el6.art.x86_64 (atomic)
           requires: php-common(x86-64) = 5.4.45-56.el6.art
           installed: php-common-5.6.16-1.el6.remi.x86_64 (@remi-php56)
               php-common(x86-64) = 5.6.16-1.el6.remi
           available: php-common-5.3.3-49.el6.x86_64 (base)
               php-common(x86-64) = 5.3.3-49.el6
           available: php-common-5.4.45-54.el6.art.x86_64 (atomic)
               php-common(x86-64) = 5.4.45-54.el6.art
           available: php-common-5.4.45-56.el6.art.x86_64 (atomic)
               php-common(x86-64) = 5.4.45-56.el6.art
           available: php55w-common-5.5.38-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 5.5.38-1.w6
           available: php56w-common-5.6.40-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 5.6.40-1.w6
           available: php70w-common-7.0.33-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 7.0.33-1.w6
           available: php71w-common-7.1.26-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 7.1.26-1.w6
           available: php71w-common-7.1.27-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 7.1.27-1.w6
           available: php71w-common-7.1.28-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 7.1.28-1.w6
           available: php71w-common-7.1.29-1.w6.x86_64 (webtatic)
               php-common(x86-64) = 7.1.29-1.w6
 you could try using --skip-broken to work around the problem
 you could try running: rpm -va --nofiles --nodigest

最后采用这种方式安装成功了

yum install php-gd --enablerepo=remi-php56

到此这篇关于php遇到错误call to undefined function imagecreate()解决方法的文章就介绍到这了,更多相关undefined function imagecreate内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!