imagick php установка ubuntu
Рука помощи
19.07.2018
Установка расширения Imagick для PHP на Ubuntu
Установку похожего расширения gmagick, которое использует GraphicsMagick, я описывал ранее «Установка расширения gmagick для php на базе Ubuntu»
Каждый сам выбирает, с каким расширением работать, но иногда необходимо установить какое-то конкретное ввиду того, что оно используется в готовом программном продукте.
В данной заметке рассмотрим установку расширения Imagick для PHP 7.0 на ОС Ubuntu 16.04
Устанавливаем ImageMagick и необходимые библиотеки
sudo apt-get install imagemagick libmagickwand-dev
Если у Вас отсутствуют данные пакеты при установке расширения PHP, Вы будете получать сообщения об ошибках
checking ImageMagick MagickWand API configuration program. checking Testing /usr/local/bin/MagickWand-config. Doesn’t exist
checking Testing /usr/bin/MagickWand-config. Doesn’t exist
checking Testing /usr/sbin/bin/MagickWand-config. Doesn’t exist
checking Testing /opt/bin/MagickWand-config. Doesn’t exist
checking Testing /opt/local/bin/MagickWand-config. Doesn’t exist
configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
Данное расширение устанавливается через PECL, официальная страница http://pecl.php.net/package/imagick
Если установка прошла успешно, в конце Вы увидите сообщения
configuration option «php_ini» is not set to php.ini location
You should add «extension=imagick.so» to php.ini
Включаем данное расширение в конфигурации PHP
sudo echo «extension=imagick.so» >> /etc/php/7.0/mods-available/imagick.ini
sudo phpenmod imagick
sudo service apache2 reload
Если у Вас появилось сообщение о следующей ошибке
это означает, что не установлен пакет php-dev, устанавливаем его
sudo apt-get install php7.0-dev pkg-config
Установка модулей PHP (Debian / Ubuntu)
Ниже мы рассмотрим установку модулей PHP на сервер с операционной системой Ubuntu или Debian.
Создание phpinfo-скрипта
В процессе установки модулей нам потребуется получать информацию о параметрах PHP на сервере, поэтому в первую очередь разместим скрипт phpinfo.php в директории сайта.
Для этого подключитесь к серверу по SSH и выполните следующие шаги:
1. Перейдите в директорию сайта:
2. Создайте файл phpinfo.php:
3. Добавьте в него следующее содержимое:
4. Сохраните изменения (нажмите Ctrl+x для выхода из nano, далее Y для сохранения изменений и Enter).
После перейдите по адресу http://вашдомен/phpinfo.php, и в браузере будет отображена информация о настройках PHP.
Установка модулей на примере imagick
Рассмотрим установку модулей php на примере модуля imagick.
1. Уточните имя пакета.
Если вы не уверены в точном названии пакета, можно воспользоваться командой ниже, указав часть названия пакета. Для PHP названия большинства библиотек будут начинаться с «php».
Вывод команды выглядит примерно следующим образом:
В данном случае нам будет нужен пакет php-imagick.
2. Обновите информацию из репозиториев:
3. Установите библиотеку:
4. Проверьте, какая директория задана для расширений. Для этого нужно на странице http://вашдомен/phpinfo.php найти параметр «extension_dir»:
Перейдите в указанную директорию:
Проверьте, есть ли в ней установленная библиотека:
Если библиотека присутствует, она будет выведена в консоли:
Перейдите в указанную директорию и просмотрите ее содержимое:
Если конфигурационный файл с директивой, подключающей библиотеку, успешно создан, он будет выведен в консоли:
Если файл отсутствует, воспользуйтесь командой ниже, чтобы его создать:
6. Перезагрузите веб-сервер Apache:
7. Обновите страницу http://вашдомен/phpinfo.php и найдите установленный модуль, чтобы убедиться, что все в порядке:
Подключение внешних библиотек
Если вам требуется подключить библиотеку, скачанную не из репозитория, необходимо:
3. Создать конфигурационный файл:
4. Указать в данном файле директиву и сохранить изменения:
5. Перезапустить Apache:
6. Обновить страницу http://вашдомен/phpinfo.php и убедиться, что библиотека установлена.
Если файл библиотеки был размещен в другой директории, то на шаге 4 необходимо в директиве extension указать соответствующий путь, например:
How to Install and Enable Imagick for PHP 7 on Ubuntu 20.04
Imagick is a PHP extension that allows you to manipulate images. Some libraries or packages require that Imagick be installed on your server. However, because Imagick is optional, it’s not installed with PHP by default. Here’s how to install and enable Imagick on your Ubuntu server.
Installation
First thing, download and install Imagick. In Terminal, run the following commands. This will install Imagick for PHP 7:
Verify that Imagick is now installed. This command should output the word imagick if it was installed successfully:
imagick.so
Find out the directory where your PHP extensions are installed. This command should output the path to that directory (example: /usr/lib/php/20190902, your path may be different):
Verify that the file imagick.so exists in that directory:
Edit php.ini
Now we need to edit the php.ini configuration file. To find out where this file is located, we need to look at the current php configuration. To do that, create a php info file that you can access from your browser. You may call it phpinfo.php:
Load that file in your browser and look for the Loaded Configuration File setting. It should have the path to the php.ini file we need to edit (the path to your php.ini file may be different than what’s shown in this example):
Open that php.ini file:
Add the following line (you may add it at the end of the file) and save it:
Restart
If you’re doing this in your local development environment, restart your computer or virtual machine. If you’re doing this on an actual server, restart it. You may want to try restarting your web server only (apache, nginx, etc), but this may not work. It’s more effective to just do a restart on the machine so that all the changes take effect.
How to Install ImageMagick for PHP on Ubuntu 18.04
Overview
ImageMagick is a popular multi-platform image manipulation tool. Web applications often use the library for its high performance with operations against uploaded images, such as resizing and format conversions, for example.
To use the ImageMagick library with PHP applications, such as WordPress, we must first install the library and then it’s corresponding PHP class. This tutorial will show you how to do so on Ubuntu 18.04.
Installing ImageMagick with Apt
ImageMagick version 6.9.2 is available from the default Ubuntu repositories, and it can simply be installed by running the apt install command.
The following command will install the latest version available in the Ubuntu source repositories.
And to install a specific version of a package we specify it with the apt install command. For example, to install version 6.9.7.4 you would run the following command.
Installing Imagick PHP Extension
Version 3.4.3 of the Imagick PHP extension is available from the Ubuntu’s repositories. Like ImageMagick, to do an imagick php install we can simply run the apt install command.
If you require a previous version of php-imagick, you can list the version available from the Ubuntu repositories using the apt list command. This would be useful in the event that the latest patch introduces regressions, which is fairly uncommon.
Restart Apache Web Server
Installing the module alone isn’t enough. In order for any new PHP extension to be used with your web application Apache must be restarted.
Verify Installation
Run the following command to verify the installation.
If the installation was successful, the output of the command will simply show one line, and it will only contain the name of the module imagick.
For a much more detailed verification of whether the PHP module was installed correctly, use the phpinfo() method.
From the command line, run the following command
Which will output the following information, where the modules status is shown as enabled.
Alternatively, by adding the phpinfo() function to a php script, and then accessing the script from a web browser, we are able to see the module is installed and enabled.
PHP Info Imagick Module
Установка и настройка
Содержание
User Contributed Notes 22 notes
Steps to Install ImageMagick on UwAmp for Windows:
as of March 31, 2016
Detailed guide for newbies like me.
My PHP version is: 5.6.18, and Thread Safety is Yes from
Step #1, so I downloaded:
5.6 Thread Safe (TS) x86
I got: php_imagick-3.4.1-5.6-ts-vc11-x86.zip
5. Unzip and copy «php_imagick.dll» to the php extension folder:
Note: this ZIP also contains dlls which other guides says
to extract to the extension folder of apache.
NO NEED TO DO IT. Step #3 has taken care of it.
6. Edit «php.ini» and add at the very end (could be
anywhere I suppose):
For super newbies: click the edit button in the UwAmp UI,
«php_uwamp.ini» will open and edit it. It will be copied to
the correct php.ini when UwAmp is restarted. I had
trouble at first since there are several php*.ini scattered
all over.
8. Check PHPInfo
scroll to section (or find): imagick
number of supported formats: 234
If there is no «imagick» section or «supported format» is 0,
something went wrong.
Steps to Install ImageMagick on UwAmp for Windows:
as of March 31, 2016
Detailed guide for newbies like me.
Took a long time to get it to work.
So I followed these steps, clobbered from various sources
to get it to work.
1. Open PHPInfo and check:
Architecture = x86 or x64
Thread Safety = yes or no
2. Download ImageMagick from:
In my case I downloaded: ImageMagick-6.9.3-7-vc11-x86.zip
because the Architecture under PHPInfo is x86
as for vc11 or vc14
search google for «visual c++ 11 runtime» or
«visual c++ 14 runtime» and install it
3. Unzip and copy all dlls from the bin subfolder to the
Apache bin directory. It’s a bunch of CORE_RL_*.dll
and IM_MOD_RL_*.dll plus a few other dlls.
it is important to install correct version of Visual C++ redistributable Package.
To install on Ubuntu or Debian, using the package manager, use:
sudo apt-get install php5-imagick
sudo service apache2 reload
After 2 hours of looking for help from different documentation & sites, I found out none of them are complete solution. So, I summary my instruction here:
1) yum install php-devel
2) cd /usr
3) wget http://pear.php.net/go-pear
4) php go-pear
5) See the following line in /etc/php.ini [include_path=».:/usr/PEAR»]
6) pecl install imagick
7) Add the following line in /etc/php.ini [extension=imagick.so]
8) service httpd restart
Hopefully, I can save other engineer effort & time. Good luck!
install php via «Homebrew», then:
$ brew install php53-imagick
and then:
reload php-fpm (or restart apache)
Simple way to install ImageMagick on your linux machine(RHEL5,Cent OS 5)
#yum install ImageMagick*
#pecl install imagick sometimes you may have ask to install gcc compiler. if so execute #yum install gcc*
added the extension on php.ini
#echo «extension=imagick.so» >> /etc/php.ini
#service httpd restart
For installing imagick in Windows do the following:
1. Download and install the ImageMagick API from http://www.imagemagick.org/script/binary-releases.php#windows. (In my case, I installed the lastest version: ImageMagick-6.9.2-10-Q16-x64-dll.)
2. Go to http://pecl.php.net/package/imagick and choose the version of imagick that best suits your PHP version. (Because I had PHP 5.4 I downloaded «php_imagick-3.3.0-5.4-ts-vc9-x86.zip».
3. Extract the contents of the zip file and go to the directory where the files were extracted.
4. Copy the php_imagick.dll in yout PHP’s ext folder.
5. All the other dll that you extracted from the zip file can go into apache’s bin directory. In my case, I have apache 2.2 and the bin directory is at: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin.
6. Activate the extention in your PHP.ini file by adding the following:
[Imagick]
extension: «C:\Program Files (x86)\PHP\ext\php_imagick.dll»
7. Restart apache
8. Sit back and relax
If you want to install ImageMagick on Nginx for Windows, in addition to setting php_imagick.dll extension, you should set an environment variable like so:
— First download ImageMagick package (if you haven’t already) *
https://windows.php.net/downloads/pecl/deps/
— Extract it to any folder for example «C:\ImageMagick-xxx\»
— Edit the «PATH» variable and add a new entry with value «C:\ImageMagick-xxx\bin»
* Note: The ImageMagick package you download should match your php Compiler (i.e Visual C++ 2017), Architecture (i.e x86 or x64) and «Thread Safety». All of these can be viewed from php_info()
I too had the error «Please provide a path to MagickWand-config or Wand-config program.» when installing on linux (in this case CentOS aka Red Hat).
The simple solution was to ensure «ImageMagick-devel» and NOT «ImageMagick» package was in place. Next comes the standard command:
pecl install imagick
Lastly, and as per the otherwise flawless instructions, edit php.ini to include:
extension=imagick.so
So, your installation in general works so that you can display the output from a PHP script— even phpinfo(); works. Great start. If not, you likely have bigger problems or are compiling imagick into PHP. Best of luck.
But, back to where we are; PHP in general works, except the imagick extension isn’t working or needs installed or something.
There is some very helpful information in the phpinfo(); output blocks.
(If phpinfo(); means nothing to you, hit the google. We’ll wait.)
This is nice when the machine you are working on has multiple php.ini files and unused configurations littered about. phpinfo(); will tell you where the resources being used can be located in the file system.
Helpful to me, thought I’d share.
Recently I had to install ImageMagick on FreeBSD. The following commands achieved this without a problem.
cd /usr/ports/graphics/ImageMagick-nox11/
make install clean
service apache22 stop
cd /usr/ports/graphics/pecl-imagick/
make install clean
service apache22 start
NOTE: For some of the package dependencies you will be prompted to select optional add-ons. I left all the config options untouched except for those which provided integration with the X11 system. Those once I disabled.
imagick 2.2.2 might have a problem loading in PHP 5.3 by giving following error at start-up:
in this case, revert to PHP 5.2.8 and imagick-2.2.0 will work just fine.
I have php 5.3.1 running on apache on windows (with xampp)
to get this working i installed the appropriate image magick from here http://imagemagick.org/script/binary-releases.php#windows
Then i needed the php_imagick.dll for vc6 (because im on apache not iis).
Windows installation is a bit more tricky since «pecl install imagick» does NOT work properly.
Here’s how I installed it:
1/ Install ImageMagick software http://www.imagemagick.org/script/binary-releases.php#windows
2/ Download pecl-5.2-dev.zip (choose the version relevant to your PHP) from http://snaps.php.net/
3/ Copy php_imagick.dll from the archive you’ve downloaded to your PHP extention folder.
4/ Add the following line to php.ini (in the exntentions section):
extension=php_imagick.dll
5/ Restart your server
6/ Try the example script to see all went well
Sins I tried around a lot and searched the net to find a working dll for ImageMagic and PHP5.4, with bad results I at last found one working.
There is a guy (Mikko) that has a blog and he wrote about this and and have compiled a working solution. You find his blog about this here: http://valokuva.org/?m=201211.
Hope that this helps others as well.
Addendum to Ian Co’s «Steps to Install ImageMagick for Windows» specifically for Uniform Server Z and how to fix if you get an empty list of ImageMagick supported formats):
Thanks to Ian Co’s comments above for setting me in the right direction.
My Uniform Server is installed to B:\UniServerZ, adjust the following steps to your specific installation.
If you’ve been messing around with a gazillion solutions like me, first delete any previous copies of imagemagick dll-s (i.e. IM_MOD_RL. dll-s, CORE_RL. dll-s) from your sysem, i.e. I had copied them to C:\Windows\system, B:\UniServerZ\core\php56, B:\UniServerZ\core\php56\extensions.
Extract contents of bin folder to B:\UniServerZ\core\php56 (or whichever vresion of php you are using)
Extract php_imagemagick.dll ONLY (and not the other dll-s) to B:\UniServerZ\core\php56\extensions
Previously I had tried ImageMagick-6.9.3-7-vc11-x86.zip and ImageMagick-6.9.3-7-vc14-x86.zip but the dll-s here did not work, perhaps because Uniform Server was compiled using VC9? and these were compiled with later versions!? What a mess.
I had also tried creating a C:\ImageMagick and adding it to PATH user-level and to MAGICK_HOME system-level environment variables, but this proved unnecessary (although it also works).