Looking for commands to install the PHP Imagick module on Ubuntu 24.04 server Linux, then here are the steps to follow. For those who don’t know, ImageMagick is an open-source imaging library that provides support for a range of different image file types and easy integration with the PHP programming language. We can use ImageMagick (IMAGICK) for many applications such as file format conversion, changing image size, crop images, color quantization, transparency, the morphology of shapes, and much more.
Steps to Install PHP-IMAGICK Extension on Ubuntu 24.04 LTS
So, let’s see the steps to install and use ImageMagick (IMAGICK) or php-imagick on Ubuntu 24.04 using its official repository. For its source code- visit the GitHub page.
Requirements
We don’t need anything special, just a user with sudo rights on Ubuntu 24.04 along with an active internet connection to download the required packages.
1. Update Ubuntu 24.04 packages
It is important before installing any package, run the system update command that will refresh the APT package list and install the latest available system updates.
sudo apt update && sudo apt upgrade
2. Installing php-imagick module on Ubuntu 24.04
Those who already have installed PHP and running some web application that requires the Imagick extension of PHP to perform certain tasks related to images, then using the command given in this Step, we can install it. For example, WordPress requires a php-imagick package or extension to enable image manipulation capabilities.
sudo apt-get install php-imagick
The above command will install the PHP Imagick extension for the default PHP version 8.3mavailable to install through the repository of Ubuntu 24.04. If you are looking for some other PHP version then first add the Ondrej repository given in the next step.
To check the extension is installed successfully, use:
php -m | grep imagick
Don’t forget to reload the Apache or Nginx web server after installing extensions:
sudo systemctl reload apache2
or
sudo systemctl reload nginx
3. Latest or older PHP using Ondrej repo (optional)
Those who don’t want to use the current version of the PHP instead of looking for some older or newer version can add the Ondrej PPA repository in Ubuntu 24.04 LTS.
To add it run:
sudo add-apt-repository ppa:ondrej/php
Now, to check what are versions of PHP available through it, we can use this syntax:
sudo apt search php
You can scroll up to find the available ones.
Now, let’s see how to install ImageMagick and PHP Imagick extension for different versions of PHP:
Note: Check which version of PHP is installed on your Ubuntu 24.04 server and then corresponding to that go for the command.
php -v
Here are the commands as per the version configured on your system, if you have multiple then install php-Imagick accordingly.
- For PHP5.6
sudo apt install imagemagick php5.6-Imagick
- For php7.0
sudo apt install imagemagick php7.0-Imagick
- For php7.1
sudo apt install imagemagick php7.1-Imagick
- For PHP7.2
sudo apt install imagemagick php7.2-Imagick
- For PHP7.3
sudo apt install imagemagick php7.3-Imagick
- For PHP7.4
sudo apt install imagemagick php7.4-Imagick
- For PHP8.0
sudo apt install imagemagick php8.0-Imagick
- For PHP8.1
sudo apt install imagemagick php8.1-Imagick
- For PHP8.2
sudo apt install imagemagick php8.2-Imagick
4. Verify Imagick.so PHP extension is loaded
Well, we have installed the Imagick extension successfully but how we will confirm that on our system, the PHP is loading Imagick for our web applications? For that, we will run the given command.
php -m
or to have details exactly about the extension you are looking for, we can use:
php -r 'phpinfo();' | grep imagick
If this is not enough then to confirm further we can create a file to load and view the current PHP configuration using a web browser. However, make sure you have Apache (sudo apt install apache
) or Nginx (sudo apt install nginx
) installed on your Ubuntu 24.04 system.
Create a PHP file under the www web-root directory:
sudo nano /var/www/html/info.php
Add the following PHP code line and save the file by pressing Ctrl+X, typing – Y, and then hitting the Enter key.
<?php
phpinfo();
?>
After that, open your browser and access the IP-address or domain of the Ubuntu 24.04 server where you have created the file, in the following way:
http://your-server-ip-addres/info.php
Note: Replace your-server-ip-addres with your actual IP or Domain.
You will have a web page with all the information about your currently installed PHP version along with the extensions you have activated to use.
5. Installing IMAGICK package (optional)
So far we have discussed how we can have the PHP Imagick extension but if you are developers who want to use the ImageMagick command line to edit the images using the command terminal then here is the command to have the full package of ImageMagick.
sudo apt install imagemagick imagemagick-doc
To confirm whether it has been installed or not run the given command which will tell you the version details of Imagick.
convert -version