Php – How to install PHP GD in Ubuntu

PHPUbuntu

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

Best Answer

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