Macのapache+passenger+sinatra環境でcoffee-scriptを使う
この、sinatraでcoffee-scriptを使ってるアプリをMac(Leopard)のapache2で動かす。
https://github.com/shokai/sinatra-template
まずコーヒーをいれる
brew install coffee-script gem install coffee-script which coffee
node等も入る。
これで、自分でrubyからsinatraを起動すれば/usr/local/bin/coffeeにpathが通っているのでちゃんと動くのだが、apache+passengerからは動かない。
ExecJS::RuntimeError - SyntaxError: Parse error:
というエラーで、500 Internal Server Errorになってしまう。
apacheに環境変数を渡す
apacheにはenvvarsというファイルがあって、そこに
export PATH=/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/Developer/usr/bin:$PATH
書くと環境変数を読み込んでくれるらしい。
macのapacheに環境変数を渡す
/usr/sbin/envvarsがあったのでそこに↑を書いてみたんだけど、読み込まれなかった。
http://wiki.apache.org/httpd/DistrosDefaultLayout に、Macの場合はorg.apache.httpd.plistを編集しろとある
EnvironmentVariablesのkeyにhomebrewやmacportsのPATHを追加した。php - $PATH environment variable for apache2 on mac - Stack Overflowに書いてあった。
/System/Library/LaunchDaemons/org.apache.httpd.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string> </dict> <key>Label</key> <string>org.apache.httpd</string> <key>OnDemand</key> <false/> <key>ProgramArguments</key> <array> <string>/usr/sbin/httpd</string> <string>-D</string> <string>FOREGROUND</string> </array> <key>SHAuthorizationRight</key> <string>system.preferences</string> </dict> </plist>
これでapacheを再起動すれば環境変数が読み込まれて、coffee-scriptが動くようになった。
sudo apachectl restart