I recently upgraded my aging mid-2009 Macbook Pro from OS X 10.6.8 (Snow Leaopard) to 10.9 (Mavericks) and am reaping the usual problems of apps not working the same any more. The latest debacle is that ImageMagick no longer works on my local web sites.
When I first installed ImageMagick on Snow Leopard, this post at Unreal Expectations was super helpful. Unfortunately, things didn't go so well this time around. This post is just a summary of the bumps I encountered along the way.
First of all, one thing to note is that upgrading XAMPP by running the installer for a newer version on top of an already-installed version is unreliable in my experience. I made the mistake of not backing up the whole /Application/XAMPP folder, and ended up losing all my database tables. Woops! What I should have done is run a mysqldump on my databases to export all my data into sql files that I could then later import, something like so: mysqldump -u root -p a_database_name > the_data.sql . Alas, I did not, and I have paid for it dearly.
Anyway, so I got to the point of deciding to just uninstall XAMPP and start from scratch. I got the XAMPP 1.8.3 installer from the official website, and installed it.
First problem: re-activating my virtual hosts.
One thing I did do was save my httpd-vhosts.conf file, and all the symbolic links I'd used in the htdocs folder, so I moved those back into their respective locations in etc/extra and htdocs.
Having done so, I tried loading one of my local sites, and all it did was redirect me to the XAMPP control panel.
I'd forgotten to restart apache. *facepalm* So I restarted apache using the XAMPP OS X Manager app.
Still nothing.
I'd forgotten to uncomment this line in /Applications/XAMPP/etc/httpd.conf *facedesk*:
Include etc/extra/httpd-vhosts.conf
Problem #2: 403 Error
I was all excited to see my site upon a browser refresh, but I was greeted with a 403:
Access forbidden!There were two things going on here. First, I hadn't reset my folder permissions in htdocs to make them read/executable by the server process.
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
sudo chgrp -R www /Applications/XAMPP/htdocs
sudo chmod -R 775 /Applications/XAMPP/htdocs
I also needed to add a Require all granted directive to my httpd-vhosts.conf file. One note here: in my previous installation I didn't need this directive because I had included it in my httpd.conf file like so:
<Directory />
AllowOverride none
Require all granted
</Directory>
But that opens up access to the root server directory to anyone, which doesn't seem good. It's not so bad because I never have this server listening on a public port, but still, I should learn good practices, and the right way to do this is to use the directive in the vhost config itself, like so:
(In httpd-vhosts.conf)
<VirtualHost *:80>
... other vhost stuff ...
<Directory "/Applications/XAMPP/htdocs/xampp">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
So after restarting apache again, the site loads! Huzzah!
Progress: Re-installing ImageMagick
There are two parts to installing ImageMagick for use in apache. First, you install the ImageMagick application. I used MacPorts to do so:
sudo port install ImageMagick
Then you need to install the imagick extension. I used pecl:
sudo pecl install imagick
Pecl should stick a file called imagick.so into /Applications/XAMPP/xampfiles/lib/php/extensions/no-debug-non-zts-<somenumber>/. You may need to change the file permissions of this file if it's not executable already:
sudo chmod 755 /Applications/XAMPP/xampfiles/lib/php/extensions/no-debug-non-zts-20100525/imagick.so
And make sure there is a line like this in /Applications/XAMPP/etc/php.ini:
extension="imagick.so"
And while you're in php.ini, make sure that extension_dir is set to the path to the folder in which imagick.so is now sitting.
Problem the next: imagick.so doesn't load
After restarting apache and attempting to load a page that uses ImageMagick, I got the classic error telling me that ImageMagick still isn't working:
Fatal error: Class 'Imagick' not found in blah blah blah
I checked my phpinfo (by using the php -i command) and noticed that indeed there is no reference to imagick anywhere. Digging a bit deeper, I checked my php error log (the location of which is determined by the error_log setting in the php info) and noticed the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525/imagick.so' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20100525/imagick.so, 9): Library not loaded: /opt/local/lib/libfreetype.6.dylib
Referenced from: /opt/local/lib/libMagickWand-6.Q16.1.dylib
Reason: Incompatible library version: libMagickWand-6.Q16.1.dylib requires version 17.0.0 or later, but libfreetype.6.dylib provides version 15.0.0 in Unknown on line 0
The problem here is that the ImageMagick library I'm using links a different version of libfreetype.6.dylib than what is used in my XAMPP installation. The fix is to copy the Macports version of this library into the XAMPP directory (but make a backup of the XAMPP one before you do this, of course):
cp /opt/local/lib/libfreetype.6.dylib /Applications/XAMPP/xampfiles/lib
Problems, more problems: apache no longer restarts
When I went to try restarting apache this time, it didn't even stop for me any more. So I went to the commandline:
apachectl start
Yielded a similar error as before. This time it's complaining about libpng:
When I went to try restarting apache this time, it didn't even stop for me any more. So I went to the commandline:
apachectl start
Yielded a similar error as before. This time it's complaining about libpng:
Syntax error on line 522 of /Applications/XAMPP/xamppfiles/etc/httpd.conf: Syntax error on line 10 of /Applications/XAMPP/xamppfiles/etc/extra/httpd-xampp.conf: Cannot load modules/libphp5.so into server: dlopen(/Applications/XAMPP/xamppfiles/modules/libphp5.so, 10): Library not loaded: /opt/local/lib/libpng15.15.dylib\n Referenced from: /Applications/XAMPP/xamppfiles/lib/libfreetype.6.dylib\n Reason: Incompatible library version: libfreetype.6.dylib requires version 33.0.0 or later, but libpng15.15.dylib provides version 25.0.0
So I do the same thing as previously, backing up the libpng in the XAMPP folder and moving in the Macports one:
cp /opt/local/lib/libpng15.15.dylib /Applications/XAMPP/xampfiles/lib
Now apache starts and stops happily. But there's another php error now again. This time we need to update libexpat:
cp /opt/local/lib/libexpat.1.dylib /Applications/XAMPP/xampfiles/lib
And at last, I have a functioning apache and a functioning ImageMagick extension in OS X Mavericks! That seemed like too much work.