How to Install php7 gd on Ubuntu 16.04

Install php7 gd ubuntu

In this tutorial, We will discuss how to install and verify php7 gd library on Ubuntu 16.04. PHP is used mainly in server-side application software along with various add-ons. PHP is a fundamentally Internet-aware system with built in libraries. GD library is used to create and manipulate image file in PHP. PHP needs to be compiled with GD library for image functions to work. If you are using PHP with Apache web server on Ubuntu and you want to install image support, then this article may be very helpful to you.

We will install php-gd library in the first section. In the second section, we will install apache web server and test PHP gd extension is properly installed or not. Let's get started.

Installation of PHP GD library

Update the packages list available in the repositories by executing first command 'apt-get update'. The second command will do the actual installation of PHP7.0 and GD library with dependent packages.

$ apt-get update
$ apt-get install php7.0-gd php7.0

It might or might not take time and it depends on dependencies available on the machine. Now, We test the installation by deploying sample code in Apache web server.

Verification of PHP GD library installation

Install apache2 web server and apache php module by executing below command.

$ apt-get install apache2 libapache2-mod-php7.0

Restart apache web service by below command.

$ systemctl restart apache2.service
If you are doing this on docker container and face any issue related to bus while restarting service, you can use /etc/init.d/apache2 restart command to restart apache server.

Now Go to apache server root directory, by default it is /var/www/html. Create testgd.php with one line of code <?php phpinfo(); ?>. This function will display all the information about PHP installed on your web server.

$ cd /var/www/html/
$ vi testgd.php

<?php phpinfo(); ?>

Now open your favorite web browser and type "http://${server_hostname or website name}/testgd.php". I am doing this on my local machine, So for me, It is "http://localhost/testgd.php". PHP information page will open, scroll down and go to "gd" section, You will see the screen like below. GD section will display detailed information about GD installed on your system.

Information and status about GD installed on your computer can be seen

We have successfully installed and verified php7 gd extension on Ubuntu 16.04. If you face any difficulties in an installation or anything new on PHP GD that the world should know, Leave your feedback in comment section.

3 Comments... add one

  1. Sir when I tried this line " apt-get install php7.0-gd php7.0" I got some error :
    You might want to run 'apt-get -f install' to correct these:
    The following packages have unmet dependencies:
    libapache2-mod-php7.0 : Depends: apache2-api-20120211
    Depends: apache2-bin but it is not going to be installed
    Recommends: apache2 but it is not going to be installed
    E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

    • @rbshree : Can you please try installation of apache2 using below command.

      $ sudo apt-get update
      $ sudo apt-get install apache2

      If that didn't work then try using below commands.
      $ sudo add-apt-repository ppa:ondrej/apache2
      $ sudo apt-get update
      $ sudo apt-get install apache2

      After successfull installation of apache2 proceed with your next steps


Leave a Comment