cat /etc/redhat-release
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
docker pull php-fpm 5.7
docker pull nginx
docker run --name myphp-fpm -v /docker-fist/nginx/www:/www -d php:5.6-fpm
docker run --name runoob-php-nginx -p 8083:80 -d \
-v /docker-fist/nginx/www:/usr/share/nginx/html:ro \
-v /docker-fist/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
--link myphp-fpm:php \
nginx
去first-docker/nginx/conf.d/ 创建并编辑文件 default.conf
server {
listen 80;
server_name localhost;
location / {
# 增加伪静态
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
首先进入php的容器:
docker exec -it [容器标识] /bin/bash
php-fpm -m 查看已经加载的扩展
php-fpm --help 获取帮助信息
docker-php-ext-install mysqli && docker-php-ext-enable mysqli
安装好了后重启php容器
docker stop [php容器标识]
docker start [容器标识]
!! 原本输的是gd2 报错里提示叫输入gd
docker-php-ext-install gd && docker-php-ext-enable gd
报了个错误:
[gd:png.h not found!]
执行命令更新下:
apt-get update
然后试试 还不行就再升级一下
sudo apt-get upgrade
默认是不带jpeg的 那么需要执行下面命令让gd支持jpeg :
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
cd /usr/local/bin/
./docker-php-source extract
#设置参数
./docker-php-ext-configure gd --with-jpeg=/usr/include --with-freetype=/usr/include/
----若上面这条命令报错 请改成这条
./docker-php-ext-configure gd --with-jpeg-dir=/usr/include --with-freetype-dir=/usr/include/
所以不知道是先安装gd 还是先扩展jpeg ! 我理解的是先安装了gd 看有没有jpeg 再选择是否执行jpeg的命令
docker-php-ext-install pdo_mysql && docker-php-ext-enable pdo_mysql
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
#允许静态资源跨域请求
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, token, platform';
expires 30d;
access_log off;
}