IE盒子

搜索
查看: 96|回复: 0

docker-compose配置php项目:typecho

[复制链接]

1

主题

6

帖子

11

积分

新手上路

Rank: 1

积分
11
发表于 2023-3-26 17:11:20 | 显示全部楼层 |阅读模式
我代码审计的话,php环境的话用docker感觉比较舒畅233 (虽然我知道有某个XAMPP,但是有些“洁癖”的感觉 ~~其实就是容器化上瘾~~)
写笔记前顺便你逼乎分享一波吧,注意,实际生产环境的话你最好再检查一下配置,我是测试环境。仅供借鉴

  • git clone 命令克隆官方最新发布版
  • 主目录下编写 docker-compose.yml 如下:
version: "3"

services:
  blog_php:
    build:
      context: ./docker
      dockerfile: Dockerfile
    restart: always
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html
    environment:
      - TZ=Asia/Shanghai
    depends_on:
      - mysql
    networks:
      - web
    extra_hosts:
    - host.docker.internal:host-gateway
  mysql:
    image: mysql:5.7
    restart: always
    ports:
      - "3306:3306"
    env_file:
      - ./docker/env/mysql.env
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/logs:/var/log/mysql
      - ./mysql/conf:/etc/mysql/conf.d
    networks:
      - web

networks:
  web:3. Dockerfile 文件(位于 ./docker)
FROM php:8.1-apache

## Set proxy
RUN export all_proxy=http://172.17.0.1:20171

## Install dependencies and PHP extensions
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        libzip-dev \
        wget \
        git \
        unzip \
        libcurl4-openssl-dev \
        libonig-dev \
        libpng-dev && \
    rm -rf /var/lib/apt/lists/* && \
    docker-php-ext-install -j$(nproc) \
        pdo_mysql \
        curl \
        mbstring \
        gd && \
    pecl install xdebug && \
    docker-php-ext-enable xdebug

## COPY source-code to workdir
COPY . /var/www/html/
RUN chmod  -R 765 /var/www/html/

## COPY php.ini (include xdebug in php.ini)
COPY php.ini /usr/local/etc/php/

## Enable mod_rewrite and set the document root
RUN a2enmod rewrite && \
    sed -ri -e 's!/var/www/html!/var/www/html/!g' /etc/apache2/sites-available/*.conf && \
    sed -ri -e 's!/var/www/!/var/www/html/!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf && \
    echo "ServerName localhost" >> /etc/apache2/apache2.conf


CMD ["apache2-foreground"]php.ini文件(和Dockerfile放一起 ./docker)
[xdebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.idekey="VSCODE"mysql.env (位于 ./docker/mysql.env)
MYSQL_ROOT_PASSWORD=qwe123
MYSQL_DATABASE=blog
TZ=Asia/Shanghai然后就可以直接 docker-compose up -d 运行了。后期有修改需要用 --build 命令。


sql数据库地址填 docker容器地址,然后用户密码参考mysql.env
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表