使用Docker制作nginx+php的镜像,这里的镜像是centos + nginx 1.9.7 + php 5.6.14
首先下载到nginx和php:
- nginx-1.9.5.tar.gz 下载:http://nginx.org/en/download.html
- php-5.6.14.tar.gz 下载:http://php.net/downloads.php
以及扩展包so:
- memcache-2.2.4.tgz
- redis的php so包这里下载:https://github.com/nicolasff/phpredis/zipball/master
先安装yum的第三方源:
wget http://www.atomicorp.com/installers/atomic
sh ./atomic
安装步骤
第一步,使用docker centos镜像为基础
第二步,yum安装一大堆需要的包:
yum install -y openssh-clients
yum install -y gcc gcc-c++ kernel-devel
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum install -y php-mcrypt libmcrypt libmcrypt-devel
yum install -y libxml2 libxml2-devel
yum install -y bzip2 bzip2-devel
yum install -y curl-devel
yum install -y libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64
yum install -y libjpeg-turbo libjpeg-turbo-devel libjpeg-turbo-static libjpeg-turbo-utils
yum install -y libc-client.x86_64
yum install -y uw-imap-devel
yum install -y libxslt-devel
yum install -y zip unzip autoconf
第三步,安装nginx:
./configure --with-http_ssl_module
nginx安装完后,安装目录为:/usr/local/nginx
查看nginx安装哪些模块可以使用命令:
/usr/local/nginx/sbin/nginx -V
第四步,安装php:
./configure --prefix=/usr/local/php --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr/local/libxml --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr/local/libpng --enable-gd-native-ttf --with-openssl --with-fpm-user=www --with-fpm-group=www --with-libdir=lib64 --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --enable-xml --enable-shmop --enable-session --enable-ctype --with-iconv-dir --with-iconv
php安装完后,安装目录为:/usr/local/php
第五步,安装memcache的php扩展:
下载地址:https://pecl.php.net/package/memcache
tar -zvxf memcache-2.2.4.tgz
cd memcache-2.2.4
/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
make && make install
第六步,安装redis的php扩展:
wget https://github.com/nicolasff/phpredis/zipball/master -O php-redis.zip
unzip php-redis.zip
cd php-redis
/usr/local/php/bin/phpize
./configure --enable-redis --with-php-config=/usr/local/php/bin/php-config
make && make install
第七步,安装mongodb的php扩展:
下载地址:https://pecl.php.net/package/mongo
wget https://pecl.php.net/get/mongo-1.6.11.tgz
tar -zvxf mongo-1.6..tgz
cd mongo-1.6.
/usr/local/php/bin/phpize
./configure --enable-mongo--with-php-config=/usr/local/php/bin/php-config
make && make install
第八步,php加入memcache、redis、mongodb扩展支持:
打开/usr/local/php/etc/php.ini,加入扩展:
extension = redis.so
extension = memcache.so
extension = mongo.so
完成。
附:
为减小镜像包的大小,安装完后,使用命令清除安装包:
make clean
yum clean all
更多的php扩展包可以到这里下载:
https://pecl.php.net/packages.php
启动php-fpm命令:
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf
启动nginx命令:
/usr/local/nginx/sbin/nginx
docker启动命令为:
docker run -dt --name nginx-php --privileged=true -v /home/www/nginx_logs:/usr/local/nginx/logs -v /home/www/src:/usr/local/nginx/html -p 80:80 -p 443:443 img-nginx-php