Install Imagick for PHP and Apache on Windows

余生长醉 提交于 2019-12-17 06:06:44

问题


Steps I've taken so far:

  1. I have installed Imagick on my Win7 machine, and it's installed and running properly via command line.
  2. I've extracted the contents of php_imagick-3.1.2-5.6-ts-vc11-x86.zip available here into my \PHP\ext directory.
  3. Enabled the imagick.dll in php.ini
  4. Rebooted...
  5. No errors when starting Apache.
  6. I'm still getting the Fatal error: Class 'Imagick' not found error when I try to run a script that uses Imagick.

Current Versions:

  • Windows 7 x64
  • Apache 2.4.10 x86 VC11 (from Apachelounge)
  • PHP 5.6.3 x86 VC11 TS (from windows.php.net)
  • ImageMagick 6.9.0-0 Q16 x86 (from imagemagick.org)
  • Imagick DLL php_imagick-3.1.2-5.6-ts-vc11-x86.zip (from here)

I was running an older version of PHP and had Imagick working fine with that, then I updated PHP (and the Imagick DLLs along with it) and now I can't seem to get it to work.

Looking at phpinfo( ), I don't see Imagick listed there, so it doesn't seem to be loading the module at all. Which is weird, because I'm not getting any errors when starting Apache.

I've tried just about every write-up and walkthrough for installing Imagick for PHP on Windows, but they seem to all be written for older versions of PHP.

Can somebody help me get this installed and running? It seems like it's just missing one simple step that I can't seem to figure out. If you need any more info, please ask. I'll get you whatever I can to help.


回答1:


I have php 5.6 NTS x64 installed on Windows 8.1 pro for my Development System.

EDIT: This procedure worked with Windows 10 pro as well.

I was unable to get Imagick Working with PHP using an older release of ImageMagick as in the accepted answer and it was difficult to find mirrors with the exact safe binaries needed (the binaries on the mirror in the accepted answer downloaded as different versions than listed).

In all of the steps below, be sure to match your PHP architecture (x86/x64 and NTS/TS) to the binary's architecture. If you are using PHP x86 - replace the x64 version of the downloads with the x86 (or 32bit) version. The same applies to Thread-Safe (TS) and Non-Thread-Safe (NTS) versions of PHP.

I finally got it all working by performing the following:

  1. Navigate to https://pecl.php.net/package/imagick and download the latest DLL (3.3.0RC1) at time of this answer.

  2. Extract php_imagick.dll to D:\php5.6\ext
  3. Extract all CORE_RL_*.dll files to D:\php5.6 - Ensure D:\php5.6 is also added to the PATH of your system environment variables
  4. Add extension = php_imagick.dll to D:\php5.6\php.ini
  5. Restart Apache/PHP Built-In Web Server
  6. Check PHP Info to ensure the module is installed correctly

    Note the highlighted ImageMagick version (ImageMagick 6.9.1-2 Q16 x64) and the missing supported formats
  7. Download and install the matching version of ImageMagick to D:\php5.6\bin from http://www.imagemagick.org/script/binary-releases.php - Ensure that the Add Path to Environment Variables option is checked or manually add it

    .
  8. Load a command prompt (run as administrator which forces the system path variable to refresh) and ensure convert --version displays the correct version

  9. Delete the previously extracted CORE_RL_*.dll files in D:\php5.6 (they will be loaded via ImageMagick path - otherwise your PHP installation may become unstable with the PECL dlls)
  10. Restart Apache/PHP Built-In Web Server
  11. Check PHP Info to ensure module is still installed correctly and is now loading the Imagick supported formats

  12. Optionally download and install Ghostscript to D:\php5.6\bin to be able to convert PDFs to images from http://sourceforge.net/projects/ghostscript/ be sure to match the architecture for your installation

I did not need to add MAGICK_HOME for Imagick to work using the PHP Built-In Web Server or CGI, but may be required for Apache using mod_php. Be sure the user running PHP has permission to execute convert. This should be inherited via D:\php5.6\bin but in case you chose to install to C:\Program Files. you may have issues due to its restricted permissions.


Alternative for Image conversion

As noted in the comments, you can alternatively download the required ImageMagick version dependencies and extract the exe and dll files from within the bin directory directly into your D:\php5.6 directory. The dependencies can be found on PECL website http://windows.php.net/downloads/pecl/deps/

Using the PECL dependencies removes the need to directly download and run the matching ImageMagick version installer from the vendor's website.

With the PECL dependencies method there were issues with excluded files needed for PDF conversions using GhostScript.


Special Considerations

Be sure to rearrange your PATH System Environment Variable so that %SystemRoot%\system32\convert.exe does not override the D:\php5.6\bin\convert.exe.

By adding your PHP path to the left of system32, like so: PATH: D:\php5.6\bin;%SystemRoot%\system32;%SystemRoot%;...

This will force your system to look for executable files within D:\php5.6\bin prior to %SystemRoot%\system32

Replace D:\php5.6\bin\convert.exe with the path to where you installed ImageMagick or the path to where convert.exe is located

https://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection127121120120




回答2:


I finally got it working, here is what I had to do: (referenced from http://refreshless.com/blog/imagick-pecl-imagemagick-windows/)

  1. Install an older version of ImageMagick (6.7.7-5 Q16) available from this website.
  2. Install the PECL Imagick DLL files (php_imagick-3.1.2-5.6-ts-vc11-x86.zip) downloaded from this webpage, putting the php_imagick.dll file in the PHP ext directory, and the CORE_RL_*_.dll files in the Apache bin directory.
  3. Add an Environement variable called MAGICK_HOME to the machine, with the value of [ImageMagick install dir]\modules\coders.
  4. Restart apache and check phpinfo( ).

If this doesn't work for you, try different versions of the ImageMagick binaries, and different versions of the PECL libraries.




回答3:


Another solution that worked on 3 different windows installations (2 Windows 7 and 1 Windows 8.1) is to combine:

ImageMagick-6.7.9-10-Q16-windows.exe with

xampp-win32-1.8.3-5-VC11-installer.exe.

Of course you will have to add the php_imagick.dll to the php/ext folder and also add extension php_imagick.dll to php.ini. Restart apache after you do all of the above and if it complains about missing stuff, restart your computer.




回答4:


  1. Download proper extension version from http://windows.php.net/downloads/pecl/releases/imagick/ I picked 3.1.2 which is the latest non-beta at this time
    • Unzip and copy php_imagick.dll to PHP ext folder
    • add [PHP_IMAGICK] extension=php_imagick.dll to php.ini
    • Download recommended Imagick version and install from: http://imagemagick.org/script/binary-releases.php#windows ( I chose to have C headers and also COM objects during installation)
    • Restart apache
    • Check phpinfo() for Imagick section... there it is!



回答5:


Here's how I solved it

I had really struggled with all these answers. Looking back I realised most of them are correct except they leave out some very fine details that are crucial.

1). First and foremost, before you start downloading any libraries or DLLs you want to start with your php_info to find out these three very important parameters.

Run the PHP_Info and check:

  1. Architecture : x86 or x64. Your computer might be x64 but your php is running on x86 so don't assume
  2. Thread Safety : yes or no. Also very important.
  3. Your PHP Version

2). Download ImageMagick from: https://windows.php.net/downloads/pecl/deps/. My computer is x64 but my php is running x86 so I downloaded ImageMagick-7.0.--vc*-x86.zip

3). Unzip and copy all DLLs from the unzipped 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. In my case, [zippeddownload]/bin/* ->copied to -> C:\Xampp\apache\bin

4). Go to http://pecl.php.net/package/imagick. You can select the zip link or just the DLL link. I prefer the DLL link. In my case I selected latest version 3.4.3. Which then took me to https://pecl.php.net/package/imagick/3.4.3/windows. Here we have to make another careful choice

  1. My php version is PHP 5.6
  2. Thread Safety is enabled
  3. Architecture php is running on is x86
  4. So I took 5.6 Thread Safe (TS) x86

5). Unzip and copy "php_imagick.dll" to the php ext folder. And all other DLL files to the php folder

6). Using an editor open php.ini. Search for "extension=" and add this line extension=php_imagick.dll as one of them.

7). Restart Xampp/Wamp or just restart Apache and run PHP_INFO again. Imagick should display. If you still can't see it refer to this link http://php.net/manual/en/imagick.setup.php#119084

Bonus tip: You might need to download visual c++ 14 runtime. From this link https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads I chose the latest version.




回答6:


1, First download right version php_imagick package depending on your situation, I use php_imagick-3.4.3-7.1-ts-vc14-x64.zip from:

https://windows.php.net/downloads/pecl/snaps/imagick/3.4.3/php_imagick-3.4.3-7.1-ts-vc14-x64.zip

2, Then unzip php_imagick-3.4.3-7.1-ts-vc14-x64.zip to C:/php_imagick folder

3, Next add extension=C:/php_imagick/php_imagick.dll in php.ini

4, Now add *.dll (except php_imagick.dll) to your apache vhost file, for example:

# enable imagick start ===========
SetEnv MAGICK_HOME "C:/php_imagick" 

LoadFile "C:/php_imagick/CORE_RL_bzlib_.dll"
LoadFile "C:/php_imagick/CORE_RL_cairo_.dll"
LoadFile "C:/php_imagick/CORE_RL_exr_.dll"
LoadFile "C:/php_imagick/CORE_RL_glib_.dll"
LoadFile "C:/php_imagick/CORE_RL_jp2_.dll"
LoadFile "C:/php_imagick/CORE_RL_jpeg_.dll"
LoadFile "C:/php_imagick/CORE_RL_lcms_.dll"
LoadFile "C:/php_imagick/CORE_RL_librsvg_.dll"
LoadFile "C:/php_imagick/CORE_RL_libxml_.dll"
LoadFile "C:/php_imagick/CORE_RL_lqr_.dll"
LoadFile "C:/php_imagick/CORE_RL_magick_.dll"
LoadFile "C:/php_imagick/CORE_RL_Magick++_.dll"
LoadFile "C:/php_imagick/CORE_RL_openjpeg_.dll"
LoadFile "C:/php_imagick/CORE_RL_pango_.dll"
LoadFile "C:/php_imagick/CORE_RL_png_.dll"
LoadFile "C:/php_imagick/CORE_RL_tiff_.dll"
LoadFile "C:/php_imagick/CORE_RL_ttf_.dll"
LoadFile "C:/php_imagick/CORE_RL_wand_.dll"
LoadFile "C:/php_imagick/CORE_RL_webp_.dll"
LoadFile "C:/php_imagick/CORE_RL_zlib_.dll"
LoadFile "C:/php_imagick/FILTER_analyze_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_aai_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_art_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_avs_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_bgr_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_bmp_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_braille_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_cals_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_caption_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_cin_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_cip_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_clip_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_clipboard_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_cmyk_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_cut_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dcm_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dds_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_debug_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dib_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_djvu_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dng_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dot_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dps_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_dpx_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_emf_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ept_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_exr_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_fax_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_fd_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_fits_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_fpx_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_gif_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_gradient_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_gray_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_hald_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_hdr_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_histogram_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_hrz_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_html_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_icon_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_info_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_inline_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ipl_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_jbig_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_jnx_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_jp2_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_jpeg_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_json_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_label_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mac_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_magick_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_map_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mask_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mat_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_matte_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_meta_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_miff_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mono_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mpc_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mpeg_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mpr_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_msl_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mtv_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_mvg_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_null_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_otb_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_palm_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pango_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pattern_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pcd_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pcl_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pcx_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pdb_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pdf_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pes_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pict_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pix_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_plasma_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_png_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pnm_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_preview_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ps_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ps2_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ps3_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_psd_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_pwp_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_raw_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_rgb_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_rgf_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_rla_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_rle_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_scr_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_screenshot_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_sct_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_sfw_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_sgi_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_sixel_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_stegano_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_sun_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_svg_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_tga_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_thumbnail_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_tiff_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_tile_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_tim_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ttf_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_txt_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_uil_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_url_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_uyvy_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_vicar_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_vid_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_viff_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_vips_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_wbmp_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_webp_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_wmf_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_wpg_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_xbm_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_xc_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_xcf_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_xpm_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_xps_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_xtrn_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_ycbcr_.dll"
LoadFile "C:/php_imagick/IM_MOD_RL_yuv_.dll"
LoadFile "C:/php_imagick/ImageMagickObject.dll"

# enable imagick end ===========

5, last restart apache



来源:https://stackoverflow.com/questions/27193631/install-imagick-for-php-and-apache-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!