ubuntu12.04にmod_mrubyをインストールしたときの手順メモ
MacのVirtualBox上にubuntu12.04を入れて、そこにmod_mrubyをインストールしました。以下のURLを参考にさせて頂きました。
http://d.hatena.ne.jp/techmedia-think/20120618/1340021311
ubuntu上で以下のコマンドを実行していきます。最小構成でのインストール直後の状態です。
開発ツールインストール
# aptitude install build-essential # aptitude install libreadline-dev libssl-dev zlib1g-dev # aptitude install git-core curl
aprのインストール
# cd /var/tmp # mkdir work # cd work/ # wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-1.4.6.tar.gz # wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-util-1.4.1.tar.gz # tar zxf apr-1.4.6.tar.gz # cd apr-1.4.6/ # ./configure # make # make install # cd .. # tar zxf apr-util-1.4.1.tar.gz # cd apr-util-1.4.1/ # ./configure --with-apr=/usr/local/apr # make # make install # cd ..
pcreのインストール
# wget -O pcre-8.32.tar.gz "http://sourceforge.jp/frs/g_redir.php?m=jaist&f=%2Fpcre%2Fpcre%2F8.32%2Fpcre-8.32.tar.gz" # tar zxf pcre-8.32.tar.gz # cd pcre-8.32/ # ./configure # make # make install # cd ..
apacheのインストール
# wget http://ftp.kddilabs.jp/infosystems/apache//httpd/httpd-2.4.3.tar.gz # tar zxf httpd-2.4.3.tar.gz # cd httpd-2.4.3/ # ./configure --enable-mods-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr # make # make install # cd .. # /usr/local/apache2/bin/apachectl start usr/local/apache2/bin/httpd: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory # ln -s /usr/local/lib/libpcre.so.1 /lib/libpcre.so.1 # /usr/local/apache2/bin/apachectl start
Rubyインストール
# aptitude install ruby1.9.1 # gem install rake
mod_mrubyのインストール
# git clone https://github.com/matsumoto-r/mod_mruby.git # cd mod_mruby/ # git submodule init # git submodule update # cd mruby/ # rake CFLAGS="-O3 -fPIC" ・・・ rake aborted! Command failed with status (127): ["bison" -o "build/host/src/y.tab.c" "src/p...] tasks/mruby_build_commands.rake:29:in `_run' tasks/mruby_build_commands.rake:169:in `run' src/mruby_core.rake:14:in `block (2 levels) in <top (required)>' Tasks: TOP => default => all => bin/mruby => build/host/bin/mruby => build/host/lib/libmruby.a => build/host/src/y.tab.o => build/host/src/y.tab.c ・・・ # aptitude install bison # rake CFLAGS="-O3 -fPIC" # cd .. # vi Makefile.in //以下2行を修正 APXS=/usr/local/apache2/bin/apxs APACHECTL=/usr/local/apache2/bin/apachectl # ./configure # make # make install ※Warningは無視していいとのこと。 https://twitter.com/kyonfuee/statuses/282029734152507392 # /usr/local/apache2/bin/apachectl restart
mod_mrubyのサンプル作成
# cd /usr/local/apache2 # vi htdocs/test.mrb r = Apache::Request.new() r.content_type = "text/html" Apache.rputs("<h1>test</h1>") r.filename = "/usr/local/apache2/htdocs/index.html" Apache.return(Apache::OK) # vi conf/httpd.conf ・・・ AddHandler mruby-script .mrb //追記 ・・・ <IfModule mruby_module> //追記 mrubyTranslateNameFirst /usr/local/apache2/htdocs/test.mrb </IfModule> # bin/apachectl restart
適当なURLにアクセスして、
うまくでっかい文字でtestとIt works!が表示されればOKです。