LoginSignup
5
5

More than 5 years have passed since last update.

DockerでHHVM(PHP用仮想マシン)を動かす

Posted at

最後はhhvmです。hhvmとはPHPの仮想マシンで、素のPHPより早いそうです。今回はnginxと組み合わせて利用します。

hhvmは、PerlのCGIなどのようにHTTPサーバーにMIMEタイプを設定して使うのではなく、独自のサーバとして動作します。HTTPサーバーからサーバーにPHPファイルをなげて、処理をしてもらうという感じになるみたい。

hhvmのインストールに際して困ったところは特にないですが、nginxの定義ファイルについて今までどおりのCGIを使うつもりでやると、ちょっと面食らうかもしれません。

Dockerfile

さて、関連するところだけ抜粋

Dockerfile
## apt-get
# HTTP/HTTPS
RUN apt-get -y install nginx
# PHP
RUN apt-get update
RUN apt-get install -y  wget
RUN wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add -
RUN echo deb http://dl.hhvm.com/ubuntu trusty main | tee /etc/apt/sources.list.d/hhvm.list
RUN apt-get update
RUN apt-get install -y hhvm
・・・
## conf
# HTTP
ADD nginx/http.conf /etc/nginx/conf.d/
RUN mkdir /etc/nginx/ssl_certfile/
RUN rm /etc/nginx/sites-enabled/default
・・・
## EXPOSE
# HTTP/HTTPS
EXPOSE 80 443
http.conf
server {
  listen 80;

  root /usr/share/nginx/html;
  index index.html index.htm;

  server_name [サーバ名];

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  index  index.php index.html;
  try_files $uri $uri/ /index.php?q=$1;

  location ~ /*.php$ {
    include fastcgi_params;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$fastcgi_script_name;
  }
}

hhvmは今回コンテナ内で使うUbuntuのパッケージリストには含まれていないため、http://dl.hhvm.com/ubuntu をパッケージリストに追加してインストールします。

nginx/http.conflocation ~ ~は、PHPファイルを見つけたときの挙動を定義します。ここではPHPサーバー(hhvm)とnginxが同じコンテナにあるのでこれでよいですが、もし別コンテナで動かしている場合は、dockerの--linkオプションなどを利用してfastcgi_passに設定する必要があります。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5