Roots Discourse

Trellis with ImageMagick PHP extension

Hello,

I would like WordPress to use imagemagick for image processing. I’m not sure how to go about it. Right now, I modified the ansible dev.yml playbook and then

I added the role via ansible:

sudo ansible-galaxy install crushlovely.imagemagick

Then vagrant provision

The server is provisioned and seems to be happy:

PLAY [pixeline] ****************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [crushlovely.imagemagick : Install Imagemagick] ***************************
ok: [default] => (item=[u'imagemagick', u'libmagickcore-dev', u'libmagickwand-dev'])

PLAY RECAP *********************************************************************
default                    : ok=97   changed=1    unreachable=0    failed=0

But PHP does not agree: phpinfo(); does not list any “magick” component.

What am I doing wrong?

Thank you!
Alexandre.

Someone can correct me if I’m wrong, but I believe you need the php-imagick package which that ansible role doesn’t appear to install.

Perhaps there’s a more suitable ImageMagick role for PHP?

Edit: At a glance, I can’t seem to find an updated standalone role for ImageMagick that uses the Ubuntu 16+ package php-imagick– they all seem to use the legacy package name php5-imagick

php-imagick should exist in the PPA that Trellis uses for PHP7. See https://launchpad.net/~ondrej/+archive/ubuntu/php/+index?batch=75&memo=75&start=75

Add the following to group_vars/all/main.yml:

php_extensions_custom:
 - php-imagick

Then provision again

3 Likes

Thank you @swalkinshaw . I removed my changes to dev.yml and modified group_vars/all/main.yml following your instructions. then reprovisioned vagrant provision. No error reported, but still no go.

When adding php-imagick this way, does the extension get installed at the same time as PHP?
I’m asking because it does not appear in the log. This is what is shown:


TASK [mailhog : Ensure mailhog is enabled and will start on boot.] *************
ok: [default]

TASK [php : Add PHP 7.1 PPA] ***************************************************
ok: [default]

TASK [php : Install PHP 7.1] ***************************************************
ok: [default] => (item=[u'php7.1-cli', u'php7.1-common', u'php7.1-curl', u'php7.1-dev', u'php7.1-fpm', u'php7.1-gd', u'php7.1-mbstring', u'php7.1-mcrypt', u'php7.1-mysql', u'php7.1-opcache', u'php7.1-xml', u'php7.1-xmlrpc', u'php7.1-zip'])

TASK [php : Start php7.1-fpm service] ******************************************
ok: [default]

TASK [php : PHP configuration file] ********************************************
ok: [default]

TASK [xdebug : Install Xdebug] *************************************************
ok: [default]

Added php-imagick to the php role. Now it is listed in the log, but still no go.

Tried also with php7.1-imagick … Again, no error reported and log shows it is there, but phpinfo(); does not.

TASK [mailhog : Ensure mailhog is enabled and will start on boot.] *************
ok: [default]

TASK [php : Add PHP 7.1 PPA] ***************************************************
ok: [default]

TASK [php : Install PHP 7.1] ***************************************************
ok: [default] => (item=[u'php7.1-cli', u'php7.1-common', u'php7.1-curl', u'php7.1-dev', u'php7.1-fpm', u'php7.1-gd', u'php7.1-mbstring', u'php7.1-mcrypt', u'php7.1-mysql', u'php7.1-opcache', u'php7.1-xml', u'php7.1-xmlrpc', u'php7.1-zip', u'php7.1-imagick'])

TASK [php : Start php7.1-fpm service] ******************************************
ok: [default]

TASK [php : PHP configuration file] ********************************************
ok: [default]

TASK [xdebug : Install Xdebug] *************************************************
ok: [default]

ARF! had to manually reload the php7.1-fpm service.

vagrant ssh
sudo service php7.1-fpm reload

Works!

3 Likes

For anyone looking into that subject, here is the up-to-date way of adding the php-imagick extension (or at least this works for me):

/trellis/group_vars/all/main.yml

php_extensions_custom:
  php-imagick: "{{ apt_package_state }}"
5 Likes

So, once this is added in that file you have to re-provision the server right? Is there a way to do it without re-provisioning the entire server? I need to add this to a live site so I don’t want to screw with that if I don’t have to.

You will have to reprovision. You can limit the extend of that provision with Ansible’s “tags” feature if you want, though.

If you’re concerned about your live server, I’d recommend cloning it, and then running the provision against the clone to make sure it’s all okay.

2 Likes

For those new to Ansible and the Trellis setup - it might help to know that "{{ apt_package_state }}" here basically expands to "present" (apt_package_state is a variable, also defined in the main.yaml file).

(Posting this for others who dig around the forums and run across this, wondering how to install imagemagick.)

For some reason I can’t get this to work on my staging server. I set the

php_extensions_custom:
  php-imagick: "{{ apt_package_state }}"

block in /trellis/group_vars/all/main.yml as mentioned by @batruji, deployed, and reprovisioned. However, when I ssh into my server and run php -me the imagick module isn’t listed among the rest. I also tried manually reloading php with sudo service php7.4-fpm reload but no luck.

I’m not seeing any errors in the provisioning process, so I’m kind of stumped. Any ideas?

Trellis 1.4.0
PHP 7.4
Ansible 2.8.20

For those using recent versions of Trellis, Trellis is now installing imagemagick and php-imagick by default.

1 Like