1. 程式人生 > >五分鐘利用docker搭建好php7.0.10+nginx服務環境

五分鐘利用docker搭建好php7.0.10+nginx服務環境

/home/wwwroot/ 為網站根目錄
自動建立一個叫www的帳號,給網站、nginx、php專用
上面的域名為website.com,可以按需進行更改。
多域名的時候,進去~/nginx_config 複製多一份,進行修改即可

將下面文字儲存為script.sh檔案
在linux命令列下輸入
sudo ./script.sh
即可一鍵搭建

系統:centos 7.0

#! /usr/bin

yum install -y docker
PHP_VERSION=7.0.10

# PHP_VERSION 可以改為以下PHP版本的FPM
#7.0.10
#7.0
#7
#5.6.25
#5.6
#5 service start docker docker rm -f php docker rm -f nginx groupadd -g 2016 www adduser -g 2016 -u 2016 www mkdir -p /home/wwwroot/ chown -R www:www /home/wwwroot/ chmod -R 755 /home/wwwroot/ { \ echo "<?php"; \ echo "echo '<h1>This is one key web service for Docker.</h1>';"; \ echo
"echo 'php version is ${PHP_VERSION}';"; \ } | tee /home/wwwroot/index.php docker pull php:${PHP_VERSION}-fpm mkdir ~/php_config/ curl -o ~/php_config/php.ini https://raw.githubusercontent.com/php/php-src/php-${PHP_VERSION}/php.ini-production docker run --name php \ -v /home/wwwroot:/home/wwwroot \ -v ~/php_config/php.ini:/usr/local/etc/php/php.ini \ -p 9000
:9000 \ -d php:${PHP_VERSION}-fpm docker exec -it php sed -i "s/33/2016/g" /etc/passwd docker exec -it php sed -i "s/33/2016/g" /etc/group docker pull nginx mkdir ~/nginx_config/ { \ echo "server"; \ echo "{"; \ echo " listen 80;"; \ echo " server_name website.com www.website.com;"; \ echo " index index.html index.htm index.php;"; \ echo " root /home/wwwroot/;"; \ echo ""; \ echo " location ~ \.php {"; \ echo " # try_files $uri =404;"; \ echo " fastcgi_pass php:9000;"; \ echo " fastcgi_index /index.php;"; \ echo " include fastcgi_params;"; \ echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"; \ echo " }"; \ echo ""; \ echo " location /nginx_status"; \ echo " {"; \ echo " stub_status on;"; \ echo " access_log off;"; \ echo " }"; \ echo ""; \ echo " location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\$"; \ echo " {"; \ echo " expires 30d;"; \ echo " }"; \ echo ""; \ echo " location ~ .*\.(js|css)?\$"; \ echo " {"; \ echo " expires 12h;"; \ echo " }"; \ echo ""; \ echo " location ~ /\."; \ echo " {"; \ echo " deny all;"; \ echo " }"; \ echo "}"; \ } | tee ~/nginx_config/website.conf docker run --name nginx -v /home/wwwroot:/home/wwwroot -v ~/nginx_config:/etc/nginx/conf.d --link php:php -p 80:80 -p 443:443 -d nginx docker exec -it nginx sed -i "s/104:107/2016:2016/g" /etc/passwd docker exec -it nginx sed -i "s/107/2016/g" /etc/group docker restart nginx