Back to Homepage

PHP ImageMagick on Ubuntu 22.04

2 min read


PHP ImageMagick on Ubuntu 22.04

ImageMagick is a powerful tool for image manipulation, and integrating it with PHP can enhance your web development projects. In this tutorial, we'll guide you through the process of installing ImageMagick on Ubuntu 22.04


  1. A server or virtual machine running Ubuntu 22.04.

  2. SSH access to your Ubuntu server.

Step 1: Update and Upgrade:
Ensure your system is up-to-date by running these commands:

sudo apt update
sudo apt upgrade

Step 2: Install ImageMagick:
Install the ImageMagick package using the following command:

sudo apt install imagemagick

Step 3: Install ImageMagick Extension:
Next, install the ImageMagick extension with the following command:

sudo apt install php-imagick

Step 4: Restart PHP and Apache:
After installation, restart the PHP service and your web server (e.g., Apache) to enable the extension:

sudo systemctl restart php-fpm  # For PHP-FPM
sudo systemctl restart apache2  # For Apache

Step 5: Verify Installation:
You can verify that ImageMagick is enabled by creating a PHP info page. Create a file called phpinfo.php in your web server's document root with the following content:


Access this file in your web browser (e.g., http://server_ip/phpinfo.php) and search for "imagick." If you see an ImageMagick section, the extension is successfully installed.

Step 6: Testing PHP ImageMagick:
Create a sample PHP script to test ImageMagick functionality:

$img = new Imagick();
$img->newImage(200, 200, new ImagickPixel('blue'));
header("Content-Type: image/jpg");
echo $img;

Access this script in your browser. It should generate a 100x100 red image.

You've successfully installed PHP ImageMagick on Ubuntu 22.04. This powerful combination allows you to manipulate images dynamically in your PHP web applications. Enjoy exploring the capabilities of ImageMagick in your projects!

Follow @LaravelSage on X → Follow @LaravelSage on Facebook →
Aniket Singh

Aniket Singh

View All Articles

Full-stack developer with a knack for Merging creativity with technical expertise for standout solutions.

Related Articles

Top Laravel Packages for Building Powerful Applications

Top Laravel Packages for Building Powerful Applications

Are you ready to take your Laravel skills to the next level and build extraordinary applications? Look no further! In this blog post, we will unveil a treasure trove of top packages that will revolutionize your development process.

MarkdownX:  Markdown Editor by DevDojo

MarkdownX: Markdown Editor by DevDojo

It's a lightweight markup language used by developers, writers, and content creators for formatting text for various purposes, such as documentation, blog posts.

Subscribe for 20+ new Laravel tutorials every week

You can unsubscribe at any time. You'll also get -20% off my courses!

© 2024


Laravel Sage

   |    Privacy Policy