problem with GD image extension on Amazon Linux 2

Viewed 9009

I've recently created LAMP servers on EC2 instances using Amazon Linux AMI.

using

sudo yum install -y php70-gd

I installed the GD extension. This all worked fine and i could upload and manipulate images using PHP.

Now I've created a LAMP server using Amazon Linux 2 using the tutorial here :https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html

My problem is that I can't get the GD extension to work. i tried using

sudo yum install -y gd

and this seemed to install an older version of GD. I tried

sudo yum install php-gd

and this seems to install the latest version of the extension.

But the gd extension still doesn't seem to work. when I enter yum info gd In the console it shows :

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
Name        : php-gd
Arch        : x86_64
Version     : 7.2.5
Release     : 3.amzn2.0.2
Size        : 769 k
Repo        : installed
From repo   : amzn2extra-lamp-mariadb10.2-php7.2
Summary     : A module for PHP applications for using the gd graphics library
URL         : http://www.php.net/
License     : PHP and BSD
Description : The php-gd package contains a dynamic shared object that will add
            : support for using the gd graphics library to PHP.

when I try an image resize script I get an error. I've tried this test script :

$testGD = get_extension_funcs("gd"); // Grab function list 
if (!$testGD){ echo "GD not installed."; exit; }
echo"<pre>".print_r($testGD,true)."</pre>";

and this gives me the result

GD not installed.

so obviously something is not right. Can anyone help?

thanks

7 Answers

Amazon Linux 2 uses Apache with PHP-FPM instead of mod_php. So you need to restart the php-fpm process to reload PHP with the new extension.

sudo systemctl restart php-fpm

I'm running php 7.2.14 on Amazon Linux 2 and this worked for me:

$ sudo yum update -y
$ sudo yum install -y php-gd
$ sudo reboot

And solved... Turns out restarting apache with

sudo systemctl restart httpd

wasn't enough to load the newly installed component...

what i needed to do was

sudo reboot

and everything works...

Why did't i try that 24 hours ago!

my PHP version was - PHP 7.2.18 $ php -v

I had to install -y php72-gd

$ sudo yum update -y $ sudo yum install -y php72-gd $ sudo reboot

$ sudo yum install -y php-gd
$ sudo systemctl restart php-fpm

No need to reboot

I was getting error Required extension GD is not loaded while using Claviska Simple Image Library in my project on AWS with Php 7.0

So I needed to update the GD php library:

sudo yum install -y php70-gd

and then restart httpd service to load the updated php.

sudo /etc/init.d/httpd restart

Worked for me!

You may have done nothing wrong and might not need to reboot either. Sometimes, the extensions are not directly mapped in the php.ini file. As such, you may need to map the newly added extensions (or which are not mapped already) in the php.ini file. In your case, add

extension=gd.so

In general,

extension=<my_extension_name>.so

Related