Appearance
Enabling/installing GD extension? --without-gd
To enable the GD extension in PHP, you will need to install the extension and then enable it in your PHP configuration file. Note that GD is usually enabled by default in modern PHP distributions.
- First, install the GD extension. On a Debian-based system, you can use the following command:
How to enable the GD extension in PHP?
bash
sudo apt-get install php-gdOn a Red Hat-based system:
bash
sudo yum install php-gd- Next, you will need to enable the extension in your PHP configuration file. This file is usually called
php.ini.
Locate the line that reads ;extension=gd and remove the ; to uncomment the line. It should look like this:
ini
extension=gd- Save the changes to the file and restart your web server. For Apache, run
sudo systemctl restart apache2(Debian/Ubuntu) orsudo systemctl restart httpd(RHEL/CentOS). For Nginx, restart PHP-FPM instead:sudo systemctl restart php-fpmorsudo systemctl restart php8.x-fpm.
You can check if the extension is loaded by creating a PHP info file.
To do this, create a new file called info.php and add the following code:
php
<?php
phpinfo();
?>Place this file in your web root directory (e.g. /var/www/html) and access it in your web browser. In the output, search for the gd section. If the extension is loaded, you will see information about it in this section.
If you installed PHP with the --without-gd flag, then the GD extension will not be compiled into PHP and you will not be able to use it. In this case, you will need to recompile PHP with the --with-gd flag.