|
我代码审计的话,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 |
|