40

I want to convert the image in low resolution with GD. I'm working on IBM Server under these speces Version: PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
and I have also comment out the extension from php.ini but can't enabled the GD on php server. I Just received this error.

Run Command: sudo apt-get install libgd

Reading package lists... Done

Building dependency tree Reading state information... Done E: Unable to locate package libgd

Second Command When I run give this message:

1) packages have unmet dependencies

and after running this command received this:

Command: sudo apt-get install libgd-dev

Reading package lists... Done

Building dependency tree

Reading state information... Done

You might want to run 'apt-get -f install' to correct these:

The following packages have unmet dependencies: libgd-dev : Depends: libgd3 (= 2.1.1-4ubuntu0.16.04.6) but it is not going to be installed

         Depends: libpng-dev

         Depends: libz-dev

         Depends: libjpeg-dev

         Depends: libfreetype6-dev but it is not going to be installed

         Depends: libxpm-dev but it is not going to be installed

         Depends: libx11-dev but it is not going to be installed

         Depends: libxt-dev but it is not going to be installed

         Depends: libfontconfig-dev

         Depends: libvpx-dev but it is not going to be installed

         Depends: libtiff-dev

linux-image-virtual : Depends: linux-image-4.4.0-81-generic but it is not going to be installed

E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

Cause of this Problem:

PHP Fatal error: Uncaught Error: Call to undefined function imagecreatefromstring()

Note please anyone tell me the step-by-step command to enable this GD Library on my this Linus machine. thanks alot

Abdul Moeed Chohan
  • 509
  • 1
  • 4
  • 7
  • 1
    First do: `apt-cache search libgd`, because it told you it didn't install libgd. – selten98 Jun 23 '17 at 10:18
  • 1
    You want to resize images or you have problems installing libgd? – DevilaN Jun 23 '17 at 10:18
  • Possible duplicate of https://serverfault.com/questions/238948/how-to-install-php5-gd-on-ubuntu – ajreal Jun 23 '17 at 10:20
  • 1
    can you try installing `sudo apt-get install libgd-dev`? cause i didn't find libgd package in ubuntu repo – Shobi Jun 23 '17 at 10:23
  • @selten98 I found this error after hiting this command sudo apt-get install libgd-dev The following packages have unmet dependencies: libgd-dev : Depends: libgd3 (= 2.1.1-4ubuntu0.16.04.6) but it is not going to be installed Depends: libpng-dev Depends: libz-dev Depends: libjpeg-dev – Abdul Moeed Chohan Jun 23 '17 at 10:37
  • @DevilaN I want to convert like 10MP Picture to 5MP using PHP. – Abdul Moeed Chohan Jun 23 '17 at 10:40

5 Answers5

66
sudo apt-get update

For 5.6 PHP

sudo apt-get install php5.6-gd

For 7.0 PHP

sudo apt-get install php7.0-gd

For 8.0 PHP

sudo apt-get install php8.0-gd
Wesley Gonçalves
  • 1,985
  • 2
  • 19
  • 22
Andrei Todorut
  • 4,260
  • 2
  • 17
  • 28
  • You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies: linux-image-virtual : Depends: linux-image-4.4.0-81-generic but it is not going to be installed php7.0-gd : Depends: php7.0-common (= 7.0.18-0ubuntu0.16.04.1) but 7.0.15-0ubuntu0.16.04.4 is to be installed Depends: libgd3 (>= 2.1.1) but it is not going to be installed Depends: libxpm4 but it is not going to be installed E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution). – Abdul Moeed Chohan Jun 23 '17 at 11:59
  • When I run this command sudo apt-get install php7.0-gd it gives me above result. – Abdul Moeed Chohan Jun 23 '17 at 12:01
  • which version of php do you use ? – Andrei Todorut Jun 23 '17 at 12:02
  • 2
    PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS ) – Abdul Moeed Chohan Jun 23 '17 at 12:02
  • try this `sudo apt-get -f install` – Andrei Todorut Jun 23 '17 at 12:04
  • sudo apt-get -f install php7.0-gd gives this error ==> linux-image-virtual : Depends: linux-image-4.4.0-81-generic but it is not going to be installed php7.0-gd : Depends: php7.0-common (= 7.0.18-0ubuntu0.16.04.1) but 7.0.15-0ubuntu0.16.04.4 is to be installed Depends: libgd3 (>= 2.1.1) but it is not going to be installed Depends: libxpm4 but it is not going to be installed E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution). – Abdul Moeed Chohan Jun 23 '17 at 12:10
  • Could you please tell me. How to install without package ? – Abdul Moeed Chohan Jun 23 '17 at 15:57
  • 1
    in case it wasn't obvious, for php7.1 run sudo apt-get install php7.1-gd – ChronoFish Jan 02 '19 at 20:06
  • 4
    sudo apt-get install php7.2-gd – GAV Nov 04 '19 at 20:26
41

keep it simple...

apt-get install php-gd

will usually find the correct package and version for your install setup and just install everything nice for you.. did for me

GoZippy
  • 518
  • 4
  • 6
2

I had an issue where it still wasn't working, even after installing (on ubuntu 20.04):

sudo apt-get install php-gd

What finally worked was when I remembered to restart my server, which in my case was:

sudo service apache2 restart

Hopefully this will help someone else.

Leon Segal
  • 679
  • 7
  • 28
2

For php8.2-gd on ubuntu 22.04 you might want to run

sudo apt install libgd3

before you install it.

Jochen Schultz
  • 456
  • 5
  • 16
1

I had similar issue but running sudo apt-get install php8.1-gd didn't solve the issue. I had to run sudo apt-get install php8.1-gd/bullseye.

If you running Debian 11,

sudo apt-get install php8.1-gd/bullseye

If you running Debian 10,

sudo apt-get install php8.1-gd/buster

If you are using other debian releases, just replace bullseye with your debian release name.

You can also search for the extension in the terminal. And install from the result.

sudo apt search php8.1-gd