Docker 安装 nginx+php7.4+mysql5.7, 并安装gd和mysql扩展

原创
09/03 10:05
阅读数 115

1、安装Mysql数据库

创建目录   
mkdir -p ~/Documents/WORK/docker/mysql/data ~/Documents/WORK/docker/mysql/logs ~/Documents/WORK/docker/mysql/conf

启动mysql  
docker run --name mysql-5.7 -p 3306:3306 \
-v ~/Documents/WORK/docker/mysql/conf/mysql.conf.d:/etc/mysql/mysql.conf.d \
-v ~/Documents/WORK/docker/mysql/conf/conf.d:/etc/mysql/conf.d \
-v ~/Documents/WORK/docker/mysql/logs:/var/log/mysql \
-v ~/Documents/WORK/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=12345678 \
-d mysql:5.7

2、安装php-fpm、nginx

创建目录   
mkdir -p ~/Documents/WORK/docker/nginx/conf.d ~/Documents/WORK/docker/nginx/php ~/Documents/WORK/docker/nginx/conf/php-fpm ~~/Documents/WORK/docker/nginx/www &&  cd ~~/Documents/WORK/docker/nginx/conf.d && sudo touch default.conf

启动fpm     
docker run --name php7-fpm -p 9000:9000 \
--link mysql-5.7:mysql \
-v ~/Documents/WORK/docker/nginx/www:/var/www/html \
-v ~/Documents/WORK/docker/nginx/conf/php-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro \
-v ~/Documents/WORK/docker/nginx/conf/php/php.ini:/usr/local/etc/php/php.ini:ro \
-d php:7.4-fpm

启动nginx 
docker run --name php-nginx -p 80:80 \
    -v ~/Documents/WORK/docker/nginx/www:/var/www/html:ro \
    -v ~/Documents/WORK/docker/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
    --link php7-fpm:php \
    -d nginx:stable

3、安装php扩展gd iconv pdo_mysql

注:转自https://www.cnblogs.com/-mrl/p/13283386.html

# 进入容器
docker exec -it php7-fpm bash

# 安装`pdo_mysql`扩展:
docker-php-ext-install pdo_mysql

# 单独安装`gd`扩展
apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
   && docker-php-ext-configure gd --with-freetype --with-jpeg \
   && docker-php-ext-install -j$(nproc) gd

# 安装`gd`和`iconv`扩展(如果失败, 请去官网复制):
apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
   && docker-php-ext-install -j$(nproc) iconv \
   && docker-php-ext-configure gd --with-freetype --with-jpeg \
   && docker-php-ext-install -j$(nproc) gd

# 安装`zip`扩展:
apt-get update && apt-get install -y --no-install-recommends libzip-dev \
   && rm -r /var/lib/apt/lists/* \
   && docker-php-ext-install -j$(nproc) zip

# 安装`intl`扩展:
apt-get update && apt-get install -y zlib1g-dev libicu-dev g++ \
   && docker-php-ext-configure intl \
   && docker-php-ext-install intl

# 大一统命令(安装`pdo_mysql`,`gd`,`iconv`,`zip`,`intl`):
apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev --no-install-recommends libzip-dev zlib1g-dev libicu-dev g++ \
   && docker-php-ext-install pdo_mysql \
   && docker-php-ext-install -j$(nproc) iconv \
   && docker-php-ext-configure gd --with-freetype --with-jpeg \
   && docker-php-ext-install -j$(nproc) gd \
   && docker-php-ext-install -j$(nproc) zip \
   && docker-php-ext-configure intl \
   && docker-php-ext-install intl

# 退出容器
exit

4、nginx配置文件

下载/nginx/conf/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    location / {
        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$ {
        root   /var/www/html;
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

php-fpm 重启

kill -USR2 1

查看容器目录映射关系

docker inspect -f "{{.Mounts}}" nginx

5、查看错误日志

docker logs 容器id或名称,如:php-nginx
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部