[Linux] - Docker製做nginx+php

使用Docker製做nginx+php的鏡像,這裏的鏡像是centos + nginx 1.9.7 + php 5.6.14php


 

首先下載到nginx和php:html

  1. nginx-1.9.5.tar.gz  下載:http://nginx.org/en/download.html
  2. php-5.6.14.tar.gz    下載:http://php.net/downloads.php

 

以及擴展包so:mysql

  1. memcache-2.2.4.tgz
  2. redis的php so包這裏下載:https://github.com/nicolasff/phpredis/zipball/master

 

先安裝yum的第三方源:nginx

wget http://www.atomicorp.com/installers/atomic
sh ./atomic

 


 

 

安裝步驟git

 

第一步,使用docker centos鏡像爲基礎github

第二步,yum安裝一大堆須要的包:redis

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:sql

./configure --with-http_ssl_module

nginx安裝完後,安裝目錄爲:/usr/local/nginxmongodb

查看nginx安裝哪些模塊能夠使用命令:docker

/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.11.tgz
cd mongo-1.6.11
/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
相關文章
相關標籤/搜索