As part of my web server update from PHP 7.2 to PHP 7.4, I had to uninstall ImageMagick. Since WordPress prefers ImageMagick for image processing, here are the steps I followed to reinstall it. From start to finish, it took me under five minutes.
Before proceeding, this article assumes you have some server knowledge, understand configuring a web server and the web server’s configuration options, have the privileges to update your server, and have a method to recover the original server state if things go sideways.
Step 1: If not already installed, install the php-devel and gcc packages.
$ sudo yum install php-devel gcc
To check if the packages are installed, use the following commands. If either command returns an empty result (or both do), you’ll need to install that package (or both).
$ sudo yum list installed | grep php-devel $ which gcc
Step 2: Install the ImageMagick packages
$ sudo yum install ImageMagick ImageMagick-devel ImageMagick-perl
Step 3: Compile ImageMagick packages.
$ sudo pecl install imagick
Step 4: Change the permissions on the compiled module.
$ sudo chmod 755 /usr/lib64/php/modules/imagick.so
Step 5: Add imagick to the libraries that are loaded when php starts.
$ cd /etc/php.d $ sudo vim 20-imagick.ini
You can use either vim or nano to create and edit the 20-imagick.ini file. When the file opens, enter the following lines (first line is just a comment describing file purpose).
; Enable ImageMagick extension module extension=imagick
Step 6: Restart the php service (php-fpm in my case), and then restart the web service.
$ sudo systemctl restart php-fpm $ sudo systemctl restart httpd
If all goes well, you should have ImageMagick installed and running on your server in 5 minutes or less.
h/t to @AwkDenver for his answer to this question on StackOverflow which was a huge help and served as the basis for these instructions.
Disclaimer: These instructions applied to my specific development environment. What I’m hinting at, in not so many words, is that these instructions may require adjustment based on the specifics of your setup. I am more than happy to entertain questions in the comments and will do my best to assist with any issues you may run into during the upgrade process, but I cannot guarantee timely and/or accurate responses.
Also, keep in mind that the instructions were created May 2021 and that certain steps may or may not be necessary as various pieces of the technology stack are updated by their respective owners.
Pingback: Amazon Linux 2: Upgrading from PHP 7.2 to PHP 7.4 - Gregg Borodaty
Thanks for this!
I’ve followed your guide, but the latest WordPress on AL2 still complains that imagick is not loaded or disabled.
I ran php -s -i | grep imagick , and the results show:
imagick module => enabled
imagick module version => 3.7.0
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.allow_zero_dimension_images => 0 => 0
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.skip_version_check => 0 => 0
I’ve spent hours trying to find a solution, but no luck. Any help would be so appreciated!
Outside of a doing a bunch of google searches, I would set up a page to run phpinfo(). Review the output of the page to see if you see the information for the imagick module. If it is not there, make sure that the permissions are set properly on the module, that it is enabled, and that the correct php service is restarted (steps 4-6). In my case, it’s php-fpm, but it could be something different in your case depending on how you have the server setup to process php files.
Sorry I can’t offer more specific help, but it’s difficult without knowing a lot more detail about your server setup.
I should be more specific. As of today “the latest” WordPress is version 5.9.2. I’m running PHP 7.4.
Good instructions, worked for me.
I found it was necessary to install php-pear, before Step 3. $ sudo pecl install imagick
$ sudo yum install php-pear
Thank you so much for all the steps; I can install it successfully.
Any idea how to update maria’s DB from the previous version to the latest? I am running a WordPress blog.
A post on how to update MariaDb is on my to-do list. Hopefully I’ll get it to sooner rather than later!
Thank you, this helped me.