Call to undefined function: imagecreate() on Linux system - do I have all the correct components installed?

Posted on 2005-04-06
Medium Priority
1 Endorsement
Last Modified: 2011-08-18
Hi all,

For a new dedicated server we have moved to I get the following error when trying to use imagecreate():

"Fatal error: Call to undefined function: imagecreate()"

(See here

I initially put this down to the GD library not being installed but

rpm -U gd-2.0.28-4.i386.rpm

exectued from root where that rpm is tells me package gd-2.0.28-4 is already installed. Also php_info():

tell me php was configured with "with-gd=shared". I'm not sure what this means but I assume it means PHP knows about GD.

Finally I also added the following line to php.ini:

I can't think of anything else to do, so I would be grateful if you could have a think for me about why this might not be working.

Many thanks,

Leon Chevalier
Question by:d60eba
  • 4
  • 3
  • 3
  • +2
LVL 16

Expert Comment

ID: 13714775
looking at your phpinfo, I can't see gd being installed.

you should see something like that after FTP

GD Support  enabled  
GD Version  bundled (2.0.15 compatible)  
FreeType Support  enabled  
FreeType Linkage  with freetype  
GIF Read Support  enabled  
JPG Support  enabled  
PNG Support  enabled  
WBMP Support  enabled  
XBM Support  enabled  
LVL 16

Expert Comment

ID: 13714788
Did your system admin enable GD support for PHP?
./configure --with-gd

You would also need to specify --with-libjpeg-dir and --with-libpng-dir. And they need to be installed.

Expert Comment

ID: 13714792
You need to have php built with the "gd" graphics library installed. If you run the phpinfo() command, you'll probably see that "'--with-gd" is not in the "Configure Command" section at the top. You'll have to get your sysadmin to rebuild php with this option.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 16

Expert Comment

ID: 13714800
LVL 25

Expert Comment

by:Marcus Bointon
ID: 13714884
Your configure options already includes all of gd, png and jpeg. You don't need to specify an extension in php.ini on Linux (mine works fine without one). All I can think of is that because you'd specified --with-gd=shared, it was looking for a system installed gd, which may not have been there at compile time. Recompile it with plain --with-gd, and it should pick up PHP's bundled version. While you're at it, you may as well upgrade to PHP 4.3.11 for a bunch of bugfixes.

Author Comment

ID: 13714980
Hi Squinky,

Thanks - I suppose I'll need to recompile then. This would be my first time recompiling (or compiling for that matter) as I have until now used rpm's for installation.

The configure command that I see in my current PHP info is HUGE:

'./configure' '--build=i686-redhat-linux-gnu' '--host=i686-redhat-linux-gnu' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-db4=/usr' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd=shared' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-ncurses=shared' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-xml' '--with-expat-dir=/usr' '--with-dom=shared,/usr' '--with-dom-xslt=/usr' '--with-dom-exslt=/usr' '--with-xmlrpc=shared' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mbstring=shared' '--enable-mbstr-enc-trans' '--enable-mbregex' '--with-mime-magic=/usr/share/file/magic.mime' '--with-apxs2=/usr/sbin/apxs'

Do I need to repeat this all again? Can I use this with an RPM? That would make my life easier! ;-)


LVL 25

Expert Comment

by:Marcus Bointon
ID: 13715311
Well, since that's what it used before, it would make sense to use it again to replicate the setup (apart from the gd change). It's not a big deal - you can just paste that lot onto a command line and it will work! All you should need to do is download and untar the PHP source code, cd into the source directory, then paste in that line (perhaps go via an editor to make the changes more easily, you can leave the quotes in place). After it's finished configuring, do 'make', then stop apache ('apachectl stop'), then 'make install' then restart apache ('apachectl startssl'). All there is to it.

PHP has so many options that it's difficult to build an rpm that will suit everyone. I'm pretty sure it's possible to build an rpm from the PHP source that you then install it with rpm, but I've never tried that.

Author Comment

ID: 13715989
Hi Squinky,

Great - you were right. I pasted in that line and that started the ball rolling. I also needed to install a lot of dependencies (if anyone is having the same problems see this guide: http://www.modem-help.co.uk/help/diary20040402.html)

I have now got as far as a sucessful make install, and this is the result:

[root@server397 php-4.3.11]# make install
Installing PHP SAPI module:       cgi
Installing PHP CGI into: /usr/bin/
Installing shared extensions:     /usr/lib/20020429/
Installing PEAR environment:      /usr/share/pear/
[PEAR] Archive_Tar    - already installed: 1.1
[PEAR] Console_Getopt - already installed: 1.2
[PEAR] PEAR           - already installed: 1.3.5
Wrote PEAR system config file at: /etc/pear.conf
You may want to add: /usr/share/pear to your php.ini include_path
[PEAR] HTML_Template_IT- already installed: 1.1
[PEAR] Net_UserAgent_Detect- already installed: 2.0.1
[PEAR] XML_RPC        - already installed: 1.2.2
Installing build environment:     /usr/lib/php/build/
Installing header files:          /usr/include/php/
Installing helper programs:       /usr/bin/
  program: phpize
  program: php-config
  program: phpextdist

Brilliant! I have looked in /usr/bin and sure enough there's a file named "php" modified today.

However, when I restart Apache everything is just the same as it was!:

It's still Version 4.3.9 and GD image still doesn't work. Any ideas why this might be? Do I have to tell Apache about the update?

Many thanks,


Expert Comment

ID: 13716505
When you reconfigured it did it as a CGI module.. Your php info shows that it's using the Apache2 handler, so I'd say it didn't actually get your changes...

What version of linux are using, there might be a php rpm package available for your... Worst case I've had pretty good luck in the past solving issues like this by downloading and rebuilding the Src rpm for the php package to build the modules that I couldn't find in a specific rpm package.  Overall that's not too bad a process provided you've got all of the devel packages in place that you need.  For new versions of redhat its pretty much:

rpmbuild --rebuild php-x.x.x.src.rpm

Then this will end up with a bunch of binary rpms for php in the /usr/src/rehdat/RPMS/i386/ directory

Author Comment

ID: 13716663
Hi Systech,

I'm using CentOs 4. This compile of PHP was the first time I've done anything remotely complicated in linux, so unless I have a step-by-step I'm going to find it tricky.

My host has RPMs here:

As you can see they have the php-4.3.9-3.2.i386.rpm RPM. Could this be used to do what you say?

Would there perhaps be an easier way? Can't I just tell Apache to use the CGI module (whatver that is ;-)


LVL 25

Assisted Solution

by:Marcus Bointon
Marcus Bointon earned 400 total points
ID: 13717041
--enable-force-cgi-redirect could well be causing the problem as it only applies to CGI builds, so it may be implicitly selecting a CGI build to satisfy that. Because it has not built an apache module, it will not have replaced the existing version, which would explain what you're seeing. Try removing that option from configure and build it again. The Apache module SAPI is specified using --with-apxs2=/usr/sbin/apxs (which you have already).

All the configure options are documented here: http://www.zend.com/manual/configure.php

> there might be a php rpm package

This is the problem I ran into - it's almost impossible to find an rpm that does all that you want, as every machine is configured differently. RedHat EL3 only supports PHP up to 4.3.2 via RHN, so I completely removed the PHP install that was originally on it, and packages that depended on it, which was only Squirrelmail, which I didn't need anyway.

rpm can get very unhappy if you install packages outside of its control (the main reason I dislike it!). You can build your own rpms to work around this - this rather old post might be of interest:


and I found a PHP 4.3.11 srpm here:


On the whole I've found that building stuff from source is more reliable and not really any more difficult than using rpm - but maybe that's just because I'm used to OpenBSD!

Accepted Solution

The_Systech earned 1600 total points
ID: 13718308
Looks like they have an RPM specifically for php-gd available from that link you posted...


You might be able to download and install that and have GD working again.

Though since you did the compile from source route eariler I might suggest running the command
rpm -qa | grep php-

To determine for certain what php rpms were originally loaded on the system.  Then download each of these in addition to the php-gd package to one directory and then run the following command in that directory.

rpm -ivh --replacepkgs *.rpm

That will reinstall all the php stuff back to the way it was before you tried to compile from source, and hopefully also add the php-gd libraries that you are currently missing.

Author Comment

ID: 13718642
The Systech I love you and I want to have your children! That worked - I just did what you said and bingo. I am extremely pleased.

Plus, a few notes following this day-long saga:

(1) Linux. Well, what can I say? Never have I experienced such joy in actually managing install something than on Linux. However, I still quake in fear every time the work "compile" is mentioned.
(2) RMPs. Note to self: always have a good look through your provider's RPM repository before attempting the as-yet-never-been-sucessfully-completed "compile"

Also, thanks Squinky - I'm sure we would have got it working if it hadn't been for the eagle-eyedness of The_Systech. Hence points all round.

Thanks guys,


p.s I'm sure I'll be back with more installation questions before too long. Be afraid.


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question