一、准备php-fpm的Images
1、建立文件夹、文件备用
mkdir /data/bak/phpfpm
cd /data/bak/phpfpm
vi Dockerfile
vi sources.list
2、准备Dockerfile 文件
FROM php:5.6-fpm
MAINTAINER SnowFox <jingjie@gmail.com>
WORKDIR /working
# 设置时间环境变量
ENV TZ "Asia/Shanghai"
#使用国内的软件镜像源
RUN cp /etc/apt/sources.list /etc/apt/sources.list_back
ADD sources.list /etc/apt/sources.list
## Update Ubuntu
RUN apt-get update
## GD
RUN apt-get install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
RUN docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2
RUN docker-php-ext-install gd
RUN php -m | grep gd
RUN docker-php-ext-install pdo_mysql
RUN php -m | grep pdo_mysql
RUN apt-get clean
RUN apt-get autoclean
3、sources.list 替换系统的更新源
deb http://mirrors.ustc.edu.cn/debian/ stretch main non-free contrib
deb http://mirrors.ustc.edu.cn/debian/ stretch-updates main non-free contrib
deb http://mirrors.ustc.edu.cn/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.ustc.edu.cn/debian/ stretch main non-free contrib
deb-src http://mirrors.ustc.edu.cn/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.ustc.edu.cn/debian/ stretch-backports main non-free contrib
deb http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main non-free contrib
deb-src http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main non-free contrib
4、编译DockerFile
docker build -t snowfox/myphpfpm:v3 .
二、配置docker-compose
1、准备目录
mkdir /data/volume
cd /data/volume
mkdir nginx/conf.d
mkdir nginx/log
mkdir nginx/www/html
mkdir mysql/data
mkdir mysql/log
mkdir phpfpm/php/conf.d
2、nginx配置
vi nginx/conf.d/default.conf
server {
listen 80;
server_name _;
client_max_body_size 10m;
root /var/www/html/public;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
}
3、配置php扩展pdo-mysql、gd
vi phpfpm/php/conf.d/docker-php-ext-gd.ini
extension=gd.so
vi phpfpm/php/conf.d/docker-php-ext-pdo_mysql.ini
extension=pdo_mysql.so
4、制作compose文件
vi docker-compose.yml
version: "3"
services:
nginx:
image: nginx
container_name: nginx
ports:
- "80:80"
volumes:
- ./nginx/www/html:/var/www/html:rw
- ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro
- ./nginx/log:/var/log/nginx:rw
networks:
- net-php
depends_on:
- php
php:
image: snowfox/myphpfpm:v3
container_name: php
ports:
- "9000:9000"
volumes:
- ./phpfpm/php:/usr/local/etc/php:rw
- ./nginx/www/html:/var/www/html:rw
- ./phpfpm/log:/usr/local/var/log:rw
networks:
- net-php
- net-mysql
restart: always
command: php-fpm
mysql:
image: mysql:5.6.40
container_name: mysql
ports:
- "3306:3306"
volumes:
- ./mysql/data/mysql:/var/lib/mysql:rw
networks:
- net-mysql
environment:
MYSQL_ROOT_PASSWORD: snowfox@2X
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin
ports:
- "9008:80"
networks:
- net-mysql
- net-php
environment:
- PMA_HOST=mysql
- PMA_PORT=3306
links:
- mysql
depends_on:
- mysql
networks:
net-php:
net-mysql:
5、启动
docker-compose up -d
6、关闭
docker-compose down
三、ThinkPHP的部署
1、ThinkPHP 部署,上传到指定目录
/data/volume/nginx/www/html
2、数据库配置:application/database.php
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => 'mysql',
// 数据库名
'database' => 'snowfox',
// 用户名
'username' => 'root',
// 密码
'password' => 'snowfox@2X',
3、系统配置:application/config.php
// 应用调试模式
'app_debug' => false,
// 应用Trace
'app_trace' => false,
4、目录权限配置
chmod -R 777 runtime
chmod -R 777 publish/uploads
网友评论