Introduction
In this article, we will discuss the process of enabling the GD extension for PHP 8.3.10 on Apache 2.4.62 in the Termux environment on Android. If you are a developer utilizing Termux, which provides a Debian Linux-like environment, and you have updated PHP to version 8.3.10, only to find that the GD extension no longer works, this guide is for you.
Prerequisites
Before starting, ensure you have the following software installed in your Termux environment:
- Apache 2.4.62
- PHP 8.3.10
- The GD library
If you are unsure about the GD library, it is a collection of Graphics Design functions for PHP. It is often used for image processing, such as resizing, cropping, and manipulating images on the fly.
Identifying the Issue
When updating PHP, you might notice that the GD extension is missing, or you encounter an error similar to'Call to undefined function imagecreatefromjpeg()'. These issues occur because GD is not bundled with PHP 8.3.10 and higher, making it necessary to install the GD library manually.
Installing GD Library
To install the GD library, follow these steps:
-
Update the Termux package list using the following command:
apt update -
Install the GD development libraries with this command:
apt install libgd-dev
Now the GD library is installed, but we still need to configure PHP to use it.
Enabling GD Extension in PHP
To achieve this, follow these steps:
-
Open the PHP configuration file in a text editor. In our case, we will use the default
php.inifile, which we can edit with:
nano /data/data/com.termux/files/usr/etc/php/8.3/php.ini -
In the open configuration file, locate the
Dynamic Extensionssection or look for a line containingextension=gd. If you find the line, make sure there are no semicolons (;) at the beginning of the line, which indicates a commented line.
If you don't find the line of code, add it under theDynamic Extensionssection, as shown below:
; ... Other extensions extension=gd
Save and close the php.ini file.
Restart Apache
Now that GD has been enabled, it's essential to restart Apache for the changes to take effect.
Execute the following command to restart Apache:
Verifying the GD Extension
At this point, the GD extension for PHP 8.3.10 should be installed and enabled in the Termux environment on Android. To confirm that the GD extension is working, create a new PHP file containing the following code:
<?php
phpinfo();
?>
Load the PHP file in a web browser using the URL http://localhost/your_php_file.php (replace your_php_file.php with the name you chose for the PHP file). If the GD extension has been successfully enabled, you should see a section titled "GD" in the generated output.