How to Install php7 gd on Ubuntu 16.04

Install php7 gd ubuntuIn 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.

About Pradip Sakhavala

Pradip is a Linux system administrator, an ardent believer in sharing and contributing to open source community. He has a keen interest in DevOps And IoT. He likes to discuss technical stuff anytime. He has started sharing his experience by blogs recently.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.