Oct 1, 2012

Teaching the Webserver of MacOS 10.8 to use Imagemagick

The problem: MacOS 10.8 Mountain Lion screws up quite a bit of the built-in web server functionality. Since I wanted to have a fully functional web server for testing purposes I wanted to use the built-in system and didn't want to install an additional MAMP server (you can find one for free in the xampp project). Additionally, the cgi script used relied on imagemagick for thumbnails so the apache server should work with that.

Steps to do:

  • Follow coolestguyplanettech.org (thanks for all the information) to get apache running with php, phpmyadmin and mySQL with user directories appropriate to your needs
  • Install imagemagick using Macports
  • Since the apache server runs as user _www in group _www you need to change the path variable for it so that apache can find convert (it doesn't use your path variable)
    For this you need to change the launchd file (thanks to this stackoverflow entry):
To do this open a terminal and cast the following command
sudo nano /System/Library/LaunchDaemons/org.apache.httpd.plist
After having put in your password, this will open a text editor with the file specified in the path. With the arrow keys navigate to the end of the file.
Mark the following section in this blog entry and copy it
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string>
</dict>
In the terminal navigate to the line before </dict>, create a new line and paste the upper section via an "alt+click" or right click and "paste". The file should look like this now:
[...]
<key>SHAuthorizationRight</key>
<string>system.preferences</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin</string>
</dict>
</dict>
</plist>
Save the file by casting the key codes command+o, return (this writes the file), and command+x (this closes nano). Now you need to restart apache. Do not only give a restart, but stop and start the apache with the commands
sudo apachectl stop
sudo apachectl start
Since the path variable is updated you should now be able to use a fully functional "convert" in your php/perl scripts.
Happy converting pictures with your apache test server.

Update
I noticed a ridiculously large log file being saved by Time Machine regularly after working with the MacOS apache. Solution: navigate to the apache configuration file /private/etc/apache2/httpd.conf and set the warn level to "emerg" using e.g. nano.

No comments: