How to install php.x.x-gd and php.x.x-sodium manually in ubuntu if Composer update failed

Posted by

If you running COMPOSER UPDATE in ubuntu and if it failed due to below error :php.x.x-gd and php.x.x-sodium extension missing

root@Jami2:/opt/lampp/htdocs/holidaylandmark/holiday# composer update
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - lcobucci/jwt[4.3.0, ..., 4.4.x-dev, 5.0.0, ..., 5.4.x-dev] require ext-sodium * -> it is missing from your system. Install or enable PHP's sodium extension.
    - laravel/passport[v11.9.0, ..., 11.x-dev] require lcobucci/jwt ^4.3|^5.0 -> satisfiable by lcobucci/jwt[4.3.0, 4.3.x-dev, 4.4.x-dev, 5.0.0, ..., 5.4.x-dev].
    - Root composer.json requires laravel/passport ^11.9 -> satisfiable by laravel/passport[v11.9.0, ..., 11.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
    - /opt/lampp/etc/php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-sodium` to temporarily ignore these required extensions.

To install and enable the PHP 8.2 Sodium (php8.2-sodium) and GD (php8.2-gd) extensions manually on Ubuntu for use with XAMPP, you need to ensure that XAMPP is using PHP 8.2, and then proceed to install these extensions specifically for XAMPP’s PHP. Here’s how to manage this process, considering XAMPP handles PHP extensions a bit differently from standard Ubuntu PHP packages:

Step 1: Verify PHP Version in XAMPP

First, confirm that XAMPP is using PHP 8.2:

Check PHP Version: Open the terminal and type:

/opt/lampp/bin/php -v

This command will show the PHP version that XAMPP is using. Ensure it reads PHP 8.2.x.

Step 2: Install Required Libraries

Before compiling PHP extensions, ensure that you have the necessary development libraries installed:

Update System:

sudo apt update

Install Development Tools and Libraries:

sudo apt install build-essential libgd-dev libsodium-dev

Step 3: Download PHP 8.2 Source Code

If XAMPP’s PHP version is correct but lacks the required extensions, you might need to compile them:

Download the PHP Source Matching XAMPP’s PHP Version:

cd /tmp
wget https://www.php.net/distributions/php-8.2.x.tar.gz  # Replace "x" with the exact minor version that XAMPP uses.
tar -xzf php-8.2.x.tar.gz

Step 4: Compile and Install Sodium and GD Extensions

For each extension, follow these steps within the PHP source directory:

Navigate to the Extension Directory:

cd /tmp/php-8.2.x/ext/

Sodium:

cd sodium
/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config
make
sudo make install

if /opt/lampp/bin/phpize failing with below error

root@jami3:/tmp/php-8.2.4/ext/sodium# /opt/lampp/bin/phpize
Configuring for:
PHP Api Version:         20220829
Zend Module Api No:      20220829
Zend Extension Api No:   420220829
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

Please run below command and then run /opt/lampp/bin/phpize

sudo apt install autoconf

GD:

cd ../gd
/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config --with-gd --enable-gd-native-ttf --with-jpeg --with-freetype
make
sudo make install

Step 5: Enable Extensions in php.ini

After installing the extensions, you need to enable them in XAMPP’s php.ini:

Edit php.ini:

sudo nano /opt/lampp/etc/php.ini

Add Extensions:

Ensure these lines are in the file:

extension=sodium.so
extension=gd.so

Step 6: Restart XAMPP

Restart XAMPP to apply the changes:

sudo /opt/lampp/lampp restart

Step 7: Verify Installation

Check Extensions:

Use the following commands to ensure the extensions are loaded:

/opt/lampp/bin/php -m | grep sodium
/opt/lampp/bin/php -m | grep gd
  1. Test with Composer: Try running your Composer update again to see if the issues are resolved.

Conclusion

By following these steps, you should be able to manually compile and install php8.2-sodium and php8.2-gd for XAMPP’s PHP on Ubuntu, ensuring that these extensions are available for Composer projects. This manual approach is necessary when the pre-compiled extensions are not available or not compatible with the specific PHP setup in XAMPP.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x