前回 Docker 上の CentOS に Python 2.7 をインストールしましたが、そのイメージをつかって GAE for PHP の開発環境を作ってみます。
ポイントは以下の二点です。
- PHP の Memcache や Memcached 拡張がインストールされていると SDK のアプリがローカルで動作しないため、PHP はソースビルドでインストールする。
- SDK のツール類を Python 2.7 で動作させるようにスクリプトを変更する。
Dockerfile
# # 2016/01/30 # CentOS 6.7 + epel,remi,rpmforge # Python 2.7.11 # PHP 5.5.31 # GAE SDK 1.9.31 FROM takaya030/python27 MAINTAINER takaya030 # libraries RUN yum install -y libxml2-devel libxslt-devel libcurl-devel libpng-devel libicu-devel && \ yum clean all RUN yum install --enablerepo=epel -y libmcrypt libmcrypt-devel && \ yum clean all # php 5.5 RUN curl -Lso php-5.5.31.tar.gz http://jp2.php.net/get/php-5.5.31.tar.gz/from/this/mirror && \ tar xvzf php-5.5.31.tar.gz && \ cd php-5.5.31 && \ ./configure --prefix=/usr/local/php-5.5.31/ \ --enable-bcmath \ --enable-calendar \ --enable-ftp \ --enable-mbstring \ --enable-opcache \ --enable-phar \ --enable-soap \ --enable-sockets \ --enable-zip \ --disable-fileinfo \ --disable-flatfile \ --disable-posix \ --with-curl \ --with-gd \ --with-openssl \ --without-sqlite3 \ --without-pdo-sqlite \ --without-imap \ --without-kerberos \ --without-imap-ssl \ --without-interbase \ --without-ldap \ --without-mssql \ --without-oci8 \ --without-pgsql \ --without-pear \ --with-pdo-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-mysql=mysqlnd \ --with-config-file-path=/etc && \ make && make install && \ cp ./php.ini-production /etc/php.ini && \ cd .. && \ rm -r php-5.5.31 php-5.5.31.tar.gz # modify /etc/php.ini RUN sed -i -e "s/;date.timezone *=.*$/date.timezone = Asia\/Tokyo/" /etc/php.ini # symbolic links RUN ln -s /usr/local/php-5.5.31/bin/php /usr/local/bin/php && \ ln -s /usr/local/php-5.5.31/bin/php-cgi /usr/local/bin/php-cgi && \ ln -s /usr/local/php-5.5.31/bin/php-config /usr/local/bin/php-config && \ ln -s /usr/local/php-5.5.31/bin/phpize /usr/local/bin/phpize # Google App Engine SDK RUN curl -O https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.31.zip && \ unzip google_appengine_1.9.31.zip -d /usr/local/ && \ rm google_appengine_1.9.31.zip # modify gae scripts RUN sed -i -e "s/\/usr\/bin\/env *python/\/usr\/bin\/env python2.7/" /usr/local/google_appengine/*.py # composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # phpunit RUN curl -L https://phar.phpunit.de/phpunit-old.phar > /usr/local/bin/phpunit && \ chmod +x /usr/local/bin/phpunit # git RUN yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker && \ yum clean all && \ curl -O https://www.kernel.org/pub/software/scm/git/git-1.9.5.tar.gz && \ tar xvzf git-1.9.5.tar.gz && \ cd git-1.9.5 && \ make configure && \ ./configure --prefix=/usr/local && \ make all && \ make install && \ cd .. && \ rm -r git-1.9.5 git-1.9.5.tar.gz EXPOSE 22 8080 8000 CMD ["/usr/sbin/sshd","-D"]
イメージのビルド
docker@dev:~$ docker build -t takaya030/gaeweb
イメージの確認
docker@dev:~$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE takaya030/gaeweb latest 1a012686df3d 28 hours ago 1.004 GB takaya030/python27 latest b63358cbd426 28 hours ago 693.3 MB centos 6 a005304e4e74 7 months ago 203.1 MB busybox latest 8c2e06607696 9 months ago 2.433 MB
動作確認
コンテナの起動
docker@dev:~$ docker run -d -p 2022:22 -p 8080:8080 -p 8000:8000 --name gaeweb -h gaeweb takaya030/gaeweb
コンテナへのログイン
$ ssh -p 2022 gae@192.168.99.100
ホームディレクトリに helloworld ディレクトリを作成して、そこに下記の 2 ファイルを作る
helloworld.php
<?php phpinfo();
app.yaml
application: helloworld version: 1 runtime: php55 api_version: 1 handlers: - url: /.* script: helloworld.php
開発用サーバーの起動
[gae@gaeweb ~]$ /usr/local/google_appengine/dev_appserver.py --php_executable_path=/usr/local/bin/php-cgi --host=0.0.0.0 --admin_host=0.0.0.0 helloworld/
Web ブラウザで http://192.168.99.100:8080 にアクセスして以下のように表示されれば成功です。
参考サイト
変更履歴
- (2016/02/05) Dockerfile の記述変更
- (2016/02/05) Dockerfile に git のインストールを追加