How to Install PHP Extensions (PDO_MySQL, mcrypt, GD) for Magento on Linux Servers


2 views

When deploying Magento on a Linux environment, missing PHP extensions are among the most common setup blockers. The error messages typically look like:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql.so'
PHP Fatal error:  Uncaught Error: Call to undefined function mcrypt_encrypt()

For most Linux distributions, you'll want to use the system package manager. Here's how to handle this across common distros:

For Ubuntu/Debian

sudo apt update
sudo apt install php-mysql php-gd php-mcrypt
sudo systemctl restart apache2

For CentOS/RHEL

sudo yum install php-pdo php-gd php-mcrypt
sudo systemctl restart httpd

If packages aren't available through your distro's repositories:

# Example for PDO_MySQL
cd /usr/src
sudo pecl download pdo_mysql
tar -xvzf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
phpize
./configure
make
sudo make install

Create a verification script at /var/www/html/phpinfo.php:

<?php
phpinfo();
?>

Then check for the extensions in the output or use CLI:

php -m | grep -E 'pdo_mysql|gd|mcrypt'
  • Extension mismatch with PHP version (check php -v first)
  • Missing dependency packages (libgd-dev, libmcrypt-dev etc.)
  • Incorrect php.ini path (use php --ini to locate)

After installing extensions, add these to php.ini:

extension=pdo_mysql.so
extension=gd.so
extension=mcrypt.so

memory_limit = 2G
max_execution_time = 1800

When setting up Magento on a Linux server with pre-installed Apache/PHP, missing extensions are among the most common roadblocks. The error typically appears during system requirements verification with messages like:

PHP Extension pdo_mysql must be loaded
GD Library extension not available

For most Linux distributions, you'll want to use the native package manager rather than manual compilation. Here's how to approach this properly:

# For Debian/Ubuntu:
sudo apt-get install php-mysql php-gd php-mcrypt

# For CentOS/RHEL:
sudo yum install php-pdo php-gd php-mcrypt

After installation, create a quick test script (info.php) in your web root:

<?php
phpinfo();
?>

Access it via browser and search for these sections:
- PDO drivers
- GD Support
- mcrypt support

If extensions still don't appear after installation:

# Check the correct PHP version's config directory
ls /etc/php/7.4/mods-available/

# Enable the module explicitly
sudo phpenmod pdo_mysql
sudo systemctl restart apache2

Add these to your php.ini for optimal Magento performance:

memory_limit = 2G
max_execution_time = 1800
opcache.enable=1
opcache.memory_consumption=512

For cases where packages aren't available in default repos:

# Add third-party repos (example for Ubuntu)
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

# Install specific version extensions
sudo apt-get install php7.4-mysql php7.4-gd