Installing ImageMagick and the imagick PHP module on Shared hosting

This article only explains how to install a custom version of ImageMagick using a custom version of PHP. It does not explain how to use ImageMagick itself.

Visit the following article for instructions on using DreamHost's pre-installed ImageMagick with MediaWiki One-Click Installs on DreamHost:

ImageMagick is a free software suite used to convert and edit images and is installed by default on all DreamHost servers. To view the current version, log in to your server via SSH and then run the following command:

[server]$ dpkg -l | grep magick

For further details on ImageMagick, visit the following site:

Preparing the environment

Installing a custom version of ImageMagick is only possible if you're using a custom version of PHP. This means you must first install a custom version under your SHELL user. Once installed, proceed with the following sections.

  1. Log into your server via SSH.
  2. Install a custom version of PHP under your SHELL user.

    Make sure you've completely followed the steps to install a custom version of PHP. Your SHELL environment must be running this new version before you can proceed.

  3. Make sure you're in your user's main directory, and not your domain's directory.
  4. Create a "build" directory where all the required tools are downloaded, configured, and then compiled:
    [server]$ mkdir build
  5. Create a "local" directory where all the required tools are deployed:
    [server]$ mkdir local

Installing ImageMagick

Once you have created the /build and /local directories, proceed with the following commands. This example uses version 7.0.7-28.

[server]$ cd build
[server]$ wget "http://www.imagemagick.org/download/ImageMagick.tar.gz"
[server]$ tar zxvf ImageMagick.tar.gz
[server]$ cd ImageMagick-7.0.7-28
[server]$ ./configure --prefix=$HOME/local --enable-shared --enable-symbol-prefix
[server]$ make 
[server]$ make install

If everything runs smoothly, up-to-date ImageMagick binaries, libs collection, documentation, and so on are available in your "local" directory (and sub-directory).

Start using this "local" directory by running the following command:

[server]$ export PATH=$HOME/local/bin:$PATH

Finally, check the version:

[server]$ convert --version
Version: ImageMagick 7.0.7-28 Q16 x86_64 2018-04-29 http://www.imagemagick.org

Building the Imagick PHP module

  1. Navigate to your 'build' directory:
    [server]$ cd $HOME/build
    
  2. Visit http://pecl.php.net/package/imagick and choose the version you wish to use.
  3. Run the following commands based on the version you're using. This example uses 3.4.3:
    [server]$ wget https://pecl.php.net/get/imagick
    [server]$ tar zxvf imagick
    [server]$ cd imagick-3.4.3
    
  4. Run the following to ensure that imagick compiles smoothly. Make sure to change 'username' to your actual SHELL username:
    [server]$ /home/username/local/bin/phpize
    [server]$ export PKG_CONFIG_PATH=$HOME/local/lib/pkgconfig
    [server]$ ln -s $HOME/local/include/ImageMagick-7 $HOME/local/include/ImageMagick
    [server]$ ./configure --prefix=$HOME/local --with-imagick=$HOME/local
    [server]$ make

    You may see a few compilation warnings, which you can safely ignore. Look for the following which ensures a successful installation:

    Libraries have been installed in:
      /home/username/build/imagick-3.4.3/modules
    
  5. To finish, run make install to copy the module to your custom extensions directory:
    [server]$ make install
    Installing shared extensions:     /home/username/local/lib/php/extensions/no-debug-non-zts-20170718/
    Installing header files:          /home/username/local/include/php/

Configuring PHP to use this extension

Since you installed a custom version of PHP 7.2.5, there is no php.ini file. Create it in the /local/lib directory. For example:

[server]$ touch $HOME/local/lib/php.ini

This creates the file. Then, kill off any running PHP processes to ensure PHP is aware of this new config file:

[server]$ killall -9 php-cgi

You can see it's now being used by creating a phpinfo.php file:

Visit your site to view the file. In the first block, 'Loaded Configuration File' points to the file you just created. On that page, search for extension_dir which points to the following:

/home/username/local/lib/php/extensions/no-debug-non-zts-20170718

Finally, run the following command. This adds a line to your php.ini file that points to the imagick.so module within the 'extensions' directory:

[server]$ echo "extension = $HOME/local/lib/php/extensions/no-debug-non-zts-20170718/imagick.so" >> $HOME/local/lib/php.ini

Visit your phpinfo.php file again where the 'imagick' block exists with your new version.

See also

Did this article answer your questions?

Article last updated PST.