Without pictures, websites would be fairly boring.
However, compressing or cropping images, doing greyscale, etc. can be time-consuming and often error-prone.
Fortunately, using the PHP GD extension take care of all your basic image edit requirements.
At Bobcares, we often get requests to install PHP gd extension as part of our Server Management Services.
Today, let’s get into the details and see how our Support Engineers manage PHP install gd extension and fix errors.
How we install GD library for PHP on CentOS
The GD library is a library that offers graphics drawing tools to manage image data. By default, it may not be installed on the server. So, we have to install the GD library manually.
Here, let’s see how our Support Engineers install a GD library for PHP on CentOS
Before getting into the installation procedure, we make sure that if it’s already installed with the following command.
rpm -qa | grep gd
If not, we follow the below steps to install a gd extension.
1. We run the below command to install a gd extension.
yum install php-gd
2. Then, we restart the apache as follows.
service httpd restart
That’s it!. Here we have installed the gd library.
Similarly, adding GD library support involves executing the command:
sudo apt-get install php7.0-gd
After that, we create info.php with one line of code
<?php phpinfo(); ?> to test whether or not the gd extension is enabled on the server.
For example, after enabling the extension, the output looks like:
How we fix the gd extension installation errors
At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems while installing gd extension on the server.
Now, let’s see the major reasons for installation error and how our Support Engineers fix the top errors.
1. Missing package
Recently, one of our customers had a problem with the gd extension. He had installed php71w-gd and still had this error when uploading a file. The error said,
Intervention Image Exception NotSupportedException
GD Library extension not available with this PHP installation.
On checking, our Support Engineers found that he was using the Laravel web framework on the CentOS7 server and Nginx web server. Also, the gd package was not installed properly.
That means GD Library was missing on the server.
Therefore, we reinstalled php71 and php-gd from Remi’s RPM repository by running this code.
yum --enablerepo=remi-php71 install php-gd
Then, we restarted Nginx and PHP-FPM.
systemctl restart nginx systemctl restart php-fpm
This is how we fixed the error.
2. Missing configuration in php.ini
Every domain has its own php.ini file. It contains information on how PHP applications run under the domain.
Therefore, it should also be enabled in php.ini after installing the module server-wide. Then only the module can take effect on the corresponding domains.
Sometimes, customers may forget to enable it in the php.ini file which results in an error like.
NotSupportedException in Driver.php line 16: GD Library extension not available with this PHP installation.
Then, our Support Engineers add the following line to the php.ini file. If the domain is on a Windows server, we add
Or in a Linux server, we uncomment the line:
Then, we restart the web server for the changes to take effect.
systemctl restart apache
Or in Nginx,
systemctl restart nginx
This fixes the error and the website works normally.
[Need assistance in tasks like PHP install gd extension? We’ll help you.]
In short, a GD library is a graphics drawing library that provides tools for modifying image data. Today, we saw the topmost reasons for the gd extension installation errors and how our Support Engineers manage PHP install gd extension.