How to Install GD Library on Ubuntu Server

 70
How to Install GD Library on Ubuntu Server

The GD library is a popular PHP extension used for creating and manipulating images. The steps below will walk you through how to install and enable the GD library on an Ubuntu server.

Step 1: Update Package List 
Before installing new packages, It's essential to update your package to ensure you have the latest versions.

sudo apt update

Step 2: Install GD Extension 
To install the GD library, you can use the following command. this will install the GD extension for the default PHP version.

sudo apt install php-gd

If you need to install GD for a specific PHP version, such as PHP 8.2, use the command below:

sudo apt install php8.2-gd   

Step 3: Verify GD Installation
To check if the GD library is installed or enabled, run the following command:

php -m | grep gd

Step 4: Enable the GD Extension
If GD is installed but not enabled, you will need to enable it in the php.ini configuration file. First, find the location of your php.ini file by running:

php --ini   

Once you have the path, open the php.ini file in the text editor, such as nano :

sudo nano /etc/php/8.2/apache2/php.ini

Search for the line that mentions the GD extension. It may look like this. remove the semicolon (;) at the beginning of the line.

;extension=gd

Save and close the file by pressing Ctr + O , then enter Enter to confirm, Ctr + X to exit.

Step 5: Restart the Web Server
After enabling the GD extension, you must restart the web server to apply the changes.
For Apache:

sudo systemctl restart apache2 

For Nginx:

sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx

Step 6: Confirm GD Installation
To confirm that the GD extension is now enabled, re-run the command:

php -m | greb gd

You should see “gd” in the output.
Optional: Create a PHP info File
To further confirm that the GD extension is enabled, you can create a PHP file to display your PHP configuration. 

<?php 
phpinfo();
?>


Thanks for reading


Post a Comment

0Comments

* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Post a Comment (0)