Ubuntu Linux: Install or Add PHP-GD Support To Apache Web Server

I am using an Apache web server and PHP 5 server-side scripting language to produce dynamic web pages for our corporate website. How do I install install php gd support on an Apache/PHP5 for dynamically manipulating images under Ubuntu Linux LTS?

PHP is used mainly in server-side application software along with various addons. [donotprint]
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 5m
[/donotprint]PHP includes a large number of free and open source libraries with the core build. PHP is a fundamentally Internet-aware system with modules built in for accessing FTP servers, many database servers, embedded SQL libraries such as embedded MySQL and SQLite, LDAP servers, and others. Many functions familiar to C programmers such as those in the stdio family are available in the standard PHP build.

The GD Graphics Library for dynamically manipulating images. You will need to compile PHP with the GD library of image functions for this to work. However. Ubuntu (and Debian) Linux comes with the package called php5-gd. Just type the following command to install this module:
# apt-get install php5-gd
$ sudo apt-get install php5-gd

Sample outputs (from my Debian server)

apt-get install php5-gd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
Suggested packages:
The following packages will be REMOVED:
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) ...

Finally, restart the Apache 2 web server, enter:
# /etc/init.d/apache2 restart
Now, you can test your php application.

How do I verify that php5-gd support loaded or not?

Type the following command at a shell prompt:
$ php5 -m | grep -i gd
Sample outputs:


$ php5 -i | grep -i --color gd
$ php -i | grep -i --color gd
Sample outputs:

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

You can also use the following php code. Create a file called test.php and put in your web server directory i.e. Apache DocumentRoot (such as /var/www):


Run it as follows:
Look for GD extension.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 62 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
62 comments… add one
  • Heroin Feb 7, 2007 @ 11:46

    Thanks didnt really understand what GD was and which package it was. Apt-cache search gave me a load of weird packages. So i thank you!

    Perhaps it would be nice if there was a line you can run to see if its running properly

  • 🐧 nixCraft Feb 7, 2007 @ 15:15


    You can type php -m command to see php-gd support is loaded or not at a shell prompt:
    php -m

    You can also create a php code with phpinfo() function and see if GD is loaded or not :)


    • akanksha Apr 3, 2017 @ 6:40

      yes GD is loaded but and this is enable also.

  • Eric Feb 14, 2007 @ 8:22

    That’s great, it solves my problem in my new server. Good stuff.

  • zaf Apr 4, 2007 @ 7:26

    when running in a browser it only shows the code, but doesn’t show the php information.
    Can anyone please help me solving this problem.

    • RamdomInternetGuy Jul 18, 2014 @ 1:06

      install PHP5

      apt-get install php5 libapache2-mod-php5

      • Anonymous Dec 5, 2014 @ 7:47

        He was probably waiting for an answer for the last 7 years xD

        • anonymous2 May 24, 2016 @ 6:23

          I know I was…..

          • waqas ahmad Nov 28, 2016 @ 13:22

            but this answer can help some one else.

  • zaf Apr 4, 2007 @ 10:36

    I have a problem running php files in a browser; I tried a test.php with but it only shows the code lines in the browser with no PHP information.
    I would really appreicate you help.

  • cruz Jul 4, 2007 @ 15:29

    Hi, I want to install GD library, I want use it with PHP

    I tried:

    sudo apt-get install php5-gd

    but i get following error message

    E: couldn´t find package php5-gd

    Apache is working, my soft versions are:
    SO ubuntu 7.07
    PHP Version 5.2.1
    Apache/2.2.3 (Ubuntu)

    what can I do?


  • 🐧 nixCraft Jul 5, 2007 @ 12:26

    You need to use php5-gd only, try apt-get update first.

  • wilco Jul 17, 2007 @ 21:25

    When I apt-get install php5-gd the response is ‘Please insert the disc labeled ‘Ubuntu-Server 6.06.1 _Dapper Drake_ – Release i386’.
    But I am working remote, what can I do to solve this issue??

  • 🐧 nixCraft Jul 17, 2007 @ 21:47

    You need to force apt-get to run via network by editing /etc/apt/sources.list file. Comment out CDROM entry.

  • wilco Jul 17, 2007 @ 22:08


    Thanks that did the job!
    I had to apt-get update first and after that it worked like a charme!
    Thanx again

  • Tharange Nov 9, 2007 @ 8:08

    Thanks, My prob Solved.

  • Newbie2 Nov 10, 2007 @ 21:46

    I have a standard linux box from theplanet.com (formerly ev1servers.net formerly rackshack.net) and they generally use Redhat Pro as the OS..

    I found the easiest way to install PHP GD on the servers from “the planet” was to use the command:

    yum install php-gd

    Do it from the root dir via SSH (using the program called “putty”) and it all happens very fast. Restart the server and check if your page apps run correctly.

    Thats about as simple as I can explain it for any other newbies that don’t understand linux like myself.

    hope this is helpful.

  • Mark Dec 5, 2007 @ 15:49

    Hi all,

    I’m running a Joomla install on a virtual Jumpbox. I’ve tried running the above but it doesn’t seem to help.

    Has anyone experience of getting this to work on the Jumpbox platform?

    Cheers, MARK.

  • xer Feb 28, 2008 @ 10:02

    thank you =)

  • ihya Apr 26, 2008 @ 6:58

    thank you

  • Peter Martin Aug 26, 2008 @ 9:20

    When I tried to install some 3rd party extension in my Joomla 1.5 website (hosted on my local Ubuntu PC) I got the error that GD2 was missing.

    With your instruction I was able to install GD2 successfully. I reinstalled the Joomla Extension and now it’s able to resize images!


  • fixsmall Oct 22, 2008 @ 19:48

    I test my gd but it doesn’t support xbm ,how could i do ?

    when I wanna use phpXplorer it show me could not find “PHP GD XBM Support”
    thank you !

    You need either PHP GD extension or Image Magick for image manipulation.
    PHP GD extension found 2.0 or higher
    PHP GD FreeType Support exists
    PHP GD T1Lib Support exists
    PHP GD GIF Read Support exists
    PHP GD GIF Create Support exists
    PHP GD JPG Support exists
    PHP GD PNG Support exists
    PHP GD WBMP Support exists
    PHP GD XBM Support not found

  • Webdesign Amsterdam Apr 9, 2009 @ 13:52

    Thanks! Never thought i could solve this problem this fast.

  • Matteo Terruzzi Jul 1, 2009 @ 17:30

    Thank you very much, you have resolved all my problems!

  • Webdesign Rotterdam Jul 13, 2009 @ 11:16

    Thank you very much, you have resolved all my problems! Never thought i could solve this problem this fast.

  • berkmense Oct 30, 2009 @ 10:40

    i am using Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch .i am not able to download GD ..Please help me..

  • tanks Dec 23, 2009 @ 11:35

    thank you very very much!

  • manuel Feb 8, 2010 @ 8:26

    you are #1 in google for this search, so I’m goingo to thankyou to keep it this way.

  • Roy Jul 11, 2010 @ 18:32

    Thanks for such simple instructions!

  • Pablito Zamudio Jul 18, 2010 @ 13:55

    In the installation of php5-gd, do not include T1Lib in the GUI option–include only TrueType.

  • Hemma Aug 2, 2010 @ 8:43

    how to install php GD in ubuntu linux? This is for resize the thumbnail images. Thank You

  • g Aug 19, 2010 @ 6:09

    Nice information ooooOO…

    so if we already HAVE the apache and php installed
    but not included with
    These extensions;


    on Linux,,,

    should we installed it by typing one by one apt-get install <> ?

  • g Aug 19, 2010 @ 6:12

    so how if we want more extension installed
    at the time we already have the apache and php installed on our linux….?

  • Rafael Sep 7, 2010 @ 17:16

    Perfect! Thanks from Brazil \o/

  • tangtang Dec 6, 2010 @ 10:45

    but , my server is off line
    what can i do?

  • lixin Dec 29, 2010 @ 9:13


  • Vladimir Feb 24, 2011 @ 14:56

    It still actual and helped me resolve my problem with images processing in a minute. Thanks.

  • vivek Apr 26, 2011 @ 7:06

    how can i enable Gd, Curl, Memcache, Mysql, Mysqli, Exif, ftp, iconv, json, Session, apc modules in centos .

    tanks & regards

  • Achyut Neupane Jun 14, 2011 @ 12:19

    I dont have website.
    But I want to learn how to add captcha in website.

  • musasa Jun 20, 2011 @ 7:31

    Thanks it helped. may God be with you.

  • RedScourge Jul 12, 2011 @ 20:51

    If you are like me, and running PHP 5.2.X on an Ubuntu system that normally ships with PHP 5.3.X, it is difficult to compile your own PHP from altered source so that it uses bundled GD instead of system GD, since libaprutil1-dev and apache2-prefork-dev depend on some non-dev packages that essentially break your ability to compile this unless you first were to uninstall PHP and Apache entirely. You can get around this by installing all the dependencies you need for building minus these two libraries, then downloading the .deb packages for these two libraries, forcing them in with dpkg –force-depends -i [packagename], THEN alter and compile, and then remove all the build dependencies after. This is how I built myself a bundled GD version of php5-gd_5.2.10.dfsg.1-2ubuntu6.10_amd64.deb.

  • hennie Sep 18, 2011 @ 11:12

    i am running a couple of sites and forums on the server
    my fear is when i install the php5-gd it will damidge the current running php5

    so my question is can i install it without damidging the current setup
    or will i have to repair them afterwards

  • Guru Wannabe Oct 28, 2011 @ 14:02

    Thank you very much. It’s 2011oct28 and your post just help me =).
    Was figuring what went wrong with my WebApp running Turkey Linux LAMP appliance in Virtualbox. Got an error message about GD library.
    Googled and read a ‘thread’ of scary ‘recompile’ … late night tales… and thanks for your post that saved me all from those.
    I ssh as root into the VirtualBox appliance and did exactly as you said and viola … it just works.

    • Guru Wannabe Oct 28, 2011 @ 14:05

      Ooops! wireless keyboard … I meant TurnKey Linux LAMP and no didn’t eat turkey earlier.

  • Rama Jan 9, 2012 @ 10:04

    Thanks, that worked for me also.

  • Insan Jan 30, 2012 @ 14:22

    Thanks, it took me a while to actually realize that the library was not installed.. that’s why it kept crashing! But now, problem is fixed! :)

  • Sweet Victory Apr 10, 2012 @ 15:45

    Done. Thank you! xoxo

  • rofr Jul 16, 2012 @ 13:24

    worked perfect, thx.

  • manoj Aug 27, 2012 @ 17:58

    can anybody help to for how to install gd library on Ubuntu

  • mena Sep 24, 2012 @ 8:15

    10q very much!

  • Jill May 12, 2013 @ 15:27

    Very descriptive post, I liked that a lot.
    Will there be a part 2?

  • iyo Aug 22, 2013 @ 2:03

    thx ,,its work for my new server

  • Fred Johnson Jun 9, 2014 @ 14:41

    This is awesome, thanks! I’m setting up a PHP server for a developer, and I know next to nothing about PHP. This got me what I needed.

  • Carlos Nov 7, 2014 @ 11:24

    Hi ! this line is good, work, thanks guys.

  • Soulriser Mar 13, 2015 @ 15:15

    Nine years later and this article is still very useful. Just the tip I needed! Thanks!

  • Mohan Jul 14, 2015 @ 6:26

    Is it possible to install specific version of GD library? Because, if i execute apt-get install php5-gd, its installing the dev version of GD version, which I don’t want. Instead, I want to install a stable version. What can i do? I’m using ubuntu OS.


  • henry Nov 14, 2015 @ 9:51

    please i cant view my form after i might have save it. The form is in PHP file when i try to run it with my phpdesigner i got this respond that PHP GD extension not installed! Pls what can i do.

  • Vinay Dec 29, 2015 @ 9:21

    Thank you, its working fine.

  • Nole Mar 22, 2016 @ 14:18

    Very good explained!

  • Matt Sep 20, 2016 @ 20:00

    Getting an error in log:
    PHP Fatal error: Call to undefined function imagecreatefromjpeg().
    This is supposedly part of GD. When I run command php -i | grep -i –color gd I get this output:
    GD Support => enabled
    GD Version => bundled (2.0.34 compatible)

    However, I don’t see a GD section/block in my phpinfo page. So not sure if GD is installed properly or not. How to fix error?

    • 🐧 Vivek Gite Sep 21, 2016 @ 3:28

      Restart php process like php7.0-fpm or if you are using fastcgi via web-server itself.
      systemctl restart php7.0-fpm
      systemctl restart nginx
      systemctl restart lighttpd
      systemctl restart apache2

  • Chris Costa Jan 3, 2017 @ 1:53

    Tanks. I fixed this error.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum