php

Apt-Get Install Php-Gd

PHP is a server-side scripting language commonly used in development of websites. It is also used for creating and manipulating images files in different image formats such as JPEG, WBMP, PNG, GIF, etc. PHP handles all the image manipulation needs using the GD library. GD (stands for Graphic Draw) is an open-source code library that is required for creating and manipulating images in PHP. Along with creating JPEG, PNG, and GIF images, it can also create graphs, charts, and thumbnails. PHP and GD may also need additional libraries based on the image formats you want to deal with.

This article covers how to use apt-get to install php-gd in Linux OS. We will perform the entire procedure on Ubuntu OS. However, you can also use this procedure on Debian and Mint OS.

We will install the php-gd package from the Ubuntu default repositories. Let’s get started.

1. First, update the local repository index using the command below:

$ sudo apt-get update

2. Then run the command below to install php and php-gd using the command below:

$ sudo apt-get install php7.4 php7.4-gd

It will list the php and php-gd packages along with dependencies that will be installed during this operation. Then it will ask for confirmation for the installation of these packages. Hit y and then Enter key to continue the operation.

It might take some time for all the packages to be installed. Once installed, move on to the next step.

3. Install Apache2 and libapache2-mod-php7.4 if not already installed on your system using the command below:

$ sudo apt-get install apache2 libapache2-mod-php7.4

Then verify if the Apache service is running using the command below:

$ sudo systemctl status apache2

If the service is not running, try to restart it.

4. Then move inside the root directory of your website. We are using here the Apache default root directory /var/www/html:

$ cd /var/www/html

Then create test.php file using the command below:

$ sudo nano test.php

Add following line in the file:

<?php phpinfo(); ?>

Now, save and close the test.php file.

5. Open any web browser in your system and go to the following address:

http://localhost /test.php

or

http://hostname-or-domain name>/test.php

Once the above address opens, it will show you all the details about PHP installation on your system.

Scroll down the webpage to the GD section. This section verifies that the GD library is installed on your system. It also tells all the details about the GD installation on your system.

Another way to verify GD installation is to use the following command in your Terminal:

$ php -i | grep ‘GD’

The output similar to the following screenshot verifies that the GD library is installed in our system.

This article covered how to use apt-get to install php-gd in Ubuntu OS. We also covered how to verify the installation of php-gd. I hope this will help you in the installation of php-gd on your Linux system.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.