phpgd

How to install GD extension for PHP?


I have PHP 8.1.2 with Apache 2.4.52 on Ubuntu 22.04 and I think I need the GD Graphics Extension for my PHP scripts to work but it appears not to be installed and / or enabled (there is no GD section in the output from running phpinfo().

Some advice I have seen is to run apt-get install php-gd and restart Apache without any modifications to php.ini.

At php.net it seems to suggest there is a

recommended bundled version of the GD library

already present in my PHP and that I need to edit php.ini in order to enable it. I understood (I now think wrongly) this meant I needed to remove the prefixed semi colons from these pre existing directives:

The advice continues on to suggest for certain image formats (although possibly not for PNG) I need to uncomment:

For enhancing GD's font capabilities uncomment:

searching /etc/php/8.1/apache2/php.ini revealed that was no ;--enable-gd line or any of the other above directives in that file. There was a ;extension=gd line.

I would like to know how to proceed from here in order to install (if it is not already installed as I thought the documentation implied) and enable the GD Graphics extension.

Edit I also saw this geeksforgeeks article suggesting to uncomment ;extension=gd and restart the server.


Solution

  • You can run php -v to see what version of PHP you have on the machine. After that, you can run sudo apt-get install php<your-php-version>-gd, e.g. sudo apt-get install php8.1-gd. Hope it helps!