Logo

How to Install PHP Imagick Extension on Ubuntu 22.04?

How to Install PHP Imagick Extension on Ubuntu 22.04?

How to Install PHP Imagick Extension on Ubuntu 22.04?

Installing the PHP Imagick extension on Ubuntu is essential for developers who want to leverage the powerful image processing capabilities provided by the Imagick library. This guide will walk you through the installation process for various PHP versions on Ubuntu 22.04. The steps are straightforward and applicable to other recent Ubuntu versions as well.

Prerequisites :

Before you start, ensure you have the following:

  • A running instance of Ubuntu 22.04.
  • Root or sudo privileges.
  • PHP installed on your server.

Step 1 : Update Your Package List :

First, update your package list to ensure you have the latest information on the newest versions of packages and their dependencies:

				
					sudo apt-get update

				
			

Step 2 : Install the PHP Imagick Extension :

Depending on your PHP version, run the appropriate command from the list below to install the Imagick extension:

For PHP 8.3 :

				
					sudo apt-get install php8.3-imagick

				
			

For PHP 8.2 :

				
					sudo apt-get install php8.2-imagick

				
			

For PHP 8.1 :

				
					sudo apt-get install php8.1-imagick

				
			

For PHP 8.0 :

				
					sudo apt-get install php8.0-imagick

				
			

For PHP 7.4 :

				
					sudo apt-get install php7.4-imagick

				
			

Step 3 : Restart Your Web Server :

After installing the Imagick extension, you need to restart your web server to load the new extension. If you are using Apache, you can restart it with the following command :

				
					sudo service apache2 restart

				
			

For Nginx with PHP-FPM, use the following commands:

				
					sudo service php7.x-fpm restart   # Replace 7.x with your PHP version, e.g., php7.4-fpm
sudo service nginx restart

				
			

Step 4 : Verify the Installation :

To verify that the Imagick extension is installed and enabled, you can use two methods:

Method 1 : Command Line

Run the following command:

				
					php -m | grep -i imagick

				
			

If the extension is installed, you will see imagick in the output.

Method 2 : PHP Info Page

Create a PHP file (e.g., info.php) in your web server’s root directory with the following content:

				
					<?php
phpinfo();
?>

				
			

Access this file via your web browser (e.g., http://your-server-ip/info.php). Look for a section that mentions “imagick.” If you see it, the extension is successfully installed and enabled.

Conclusion :

By following these steps, you should have the PHP Imagick extension installed and running on your Ubuntu 22.04 server. This extension will allow you to perform advanced image processing tasks directly from your PHP scripts.

Happy coding!

Scroll to Top