关闭

五分钟利用docker搭建好php7.0.10+nginx服务环境

标签: nginxphp
2691人阅读 评论(0) 收藏 举报
分类:

/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
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:144157次
    • 积分:2128
    • 等级:
    • 排名:第18735名
    • 原创:79篇
    • 转载:12篇
    • 译文:2篇
    • 评论:10条
    文章分类
    最新评论