Imagick is a popular PHP extension that allows you to create and modify images using the ImageMagick library. Installing Imagick can vary depending on your operating system. This guide will walk you through the installation process on AlmaLinux 8 and 9, Ubuntu 22.04 and 24, RockyLinux (latest versions), and CloudLinux 8 and 9.
Table of Contents
- Prerequisites
- Installing Imagick on AlmaLinux 8 and 9
- Installing Imagick on Ubuntu 22.04 and 24
- Installing Imagick on RockyLinux (Latest Versions)
- Installing Imagick on CloudLinux 8 and 9
- Verifying the Installation
- Common Issues and Troubleshooting
- Conclusion
1. Prerequisites
Before you begin, ensure you have the following:
- Root or sudo access to the server.
- PHP installed on your system.
- Development tools and libraries required for building software from source.
2. Installing Imagick on AlmaLinux 8 and 9
AlmaLinux is a fork of Red Hat Enterprise Linux (RHEL) and is compatible with CentOS. Here’s how to install Imagick:
Step 1: Update Your System
sudo dnf update -y
Step 2: Install EPEL Repository
The EPEL (Extra Packages for Enterprise Linux) repository contains additional packages.
sudo dnf install epel-release -y
Step 3: Install ImageMagick and PHP Modules
sudo dnf install ImageMagick ImageMagick-devel -y
sudo dnf install php php-devel php-pear -y
Step 4: Install Imagick Extension Using PECL
sudo pecl install imagick
During installation, you may be prompted with questions. Press Enter to accept default values.
Step 5: Enable the Imagick Extension
Add the extension to your PHP configuration:
echo "extension=imagick.so" | sudo tee /etc/php.d/20-imagick.ini
Step 6: Restart Web Server
If you’re using Apache:
sudo systemctl restart httpd
If you’re using Nginx with PHP-FPM:
sudo systemctl restart php-fpm
sudo systemctl restart nginx
3. Installing Imagick on Ubuntu 22.04 and 24
Ubuntu makes it straightforward to install Imagick via the package manager.
Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
Step 2: Install ImageMagick and PHP Imagick Extension
sudo apt install php-imagick -y
This command installs both ImageMagick and the Imagick PHP extension.
Step 3: Restart Web Server
If you’re using Apache:
sudo systemctl restart apache2
If you’re using Nginx with PHP-FPM:
sudo systemctl restart php7.4-fpm # Replace 7.4 with your PHP version
sudo systemctl restart nginx
4. Installing Imagick on RockyLinux (Latest Versions)
RockyLinux is another RHEL-based distribution, so the steps are similar to AlmaLinux.
Step 1: Update Your System
sudo dnf update -y
Step 2: Install EPEL Repository
sudo dnf install epel-release -y
Step 3: Install ImageMagick and PHP Modules
sudo dnf install ImageMagick ImageMagick-devel -y
sudo dnf install php php-devel php-pear -y
Step 4: Install Imagick Extension Using PECL
sudo pecl install imagick
Step 5: Enable the Imagick Extension
echo "extension=imagick.so" | sudo tee /etc/php.d/20-imagick.ini
Step 6: Restart Web Server
For Apache:
sudo systemctl restart httpd
For Nginx with PHP-FPM:
sudo systemctl restart php-fpm
sudo systemctl restart nginx
5. Installing Imagick on CloudLinux 8 and 9
CloudLinux is a commercial OS based on CentOS/RHEL, designed for shared hosting providers. Installation steps can differ based on whether you’re using CageFS or ALT-PHP.
If Using CageFS and ALT-PHP
CloudLinux uses multiple PHP versions managed via ALT-PHP.
Step 1: Update Your System
sudo yum update -y
Step 2: Install ImageMagick
sudo yum install ImageMagick ImageMagick-devel -y
Step 3: Install Imagick for All PHP Versions
for version in alt-php{70,71,72,73,74,80,81}; do
yum install $version-pecl-imagick -y
done
Step 4: Update CageFS Skeleton
cagefsctl --force-update
If Not Using ALT-PHP
Follow the same steps as for AlmaLinux or RockyLinux, using PECL to install the Imagick extension.
6. Verifying the Installation
Create a PHP file to verify that Imagick is installed and enabled.
Step 1: Create a PHP Info File
echo "<?php phpinfo();" | sudo tee /var/www/html/info.php
Replace /var/www/html/
with your web root directory if it’s different.
Step 2: Access the PHP Info Page
Navigate to http://your-server-ip/info.php
in your web browser.
Step 3: Search for Imagick Section
Scroll down and look for the Imagick section to confirm it’s installed.
Security Tip:
Delete the info.php
file after verification to prevent exposing sensitive information.
sudo rm /var/www/html/info.php
7. Common Issues and Troubleshooting
Issue 1: PECL Command Not Found
Solution:
Install PHP Pear, which includes PECL.
sudo dnf install php-pear -y # For AlmaLinux, RockyLinux, CloudLinux
sudo apt install php-pear -y # For Ubuntu
Issue 2: Imagick Not Appearing in phpinfo()
Solution:
- Ensure the
imagick.so
extension is correctly referenced in yourphp.ini
or in a separate.ini
file within thephp.d
orconf.d
directory. - Restart your web server to apply changes.
Issue 3: Missing ImageMagick Devel Package
Solution:
Install the development package for ImageMagick:
sudo dnf install ImageMagick-devel -y # For RHEL-based systems
sudo apt install libmagickwand-dev -y # For Ubuntu
Issue 4: Conflicts with Multiple PHP Versions
Solution:
Ensure you’re installing Imagick for the correct PHP version. Use the appropriate PHP binary during installation.
8. Conclusion
Installing Imagick enhances your PHP environment’s ability to manipulate images, which is crucial for applications like WordPress, Drupal, and other CMS platforms. While the installation steps are similar across different operating systems, slight differences exist, especially with CloudLinux due to its specialized environment.
Always make sure to:
- Match the Imagick extension version with your PHP version.
- Restart your web server after installation.
- Verify the installation to ensure everything is working correctly.
By following this guide, you should have Imagick up and running on your server, ready to handle image processing tasks efficiently.