From 05ecf5b3dfa8a862d4baf0d5f73ebf53b56af38e Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Fri, 24 May 2024 20:26:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=AE=9E=E9=AA=8C=E6=80=A7?= =?UTF-8?q?=E7=9A=84docker=E5=AE=B9=E5=99=A8=E5=AE=89=E8=A3=85=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 46 +++++++++++++++++++++------------------------- conf/apache.conf | 24 ++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 25 deletions(-) create mode 100644 Dockerfile create mode 100644 conf/apache.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca0d7dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# 使用官方 PHP 镜像并指定版本 +FROM php:8.2-apache + +# 安装 Redis 扩展和其他必要的 PHP 扩展 +RUN apt-get update && apt-get install -y git sudo libmagickwand-dev libzip-dev unzip libxslt-dev libgmp-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libfreetype6-dev libbz2-dev libldap2-dev zlib1g-dev libsqlite3-dev \ + && docker-php-ext-install zip xsl gmp curl bcmath gd mysqli ldap pdo pdo_mysql pdo_sqlite soap intl pcntl \ + && pecl install imagick redis \ + && docker-php-ext-enable imagick redis +RUN pecl install memcache \ + && docker-php-ext-enable memcache + +# 复制自定义的 Apache 配置文件 +COPY conf/apache.conf /etc/apache2/sites-available/000-default.conf + +# 启用 Apache 的 mod_rewrite 模块 +RUN a2enmod rewrite && a2enmod ssl + +# 设置 PHP 相关配置参数 +RUN echo "max_execution_time = 360" > /usr/local/etc/php/conf.d/custom-php.ini \ + && echo "memory_limit = 1G" >> /usr/local/etc/php/conf.d/custom-php.ini \ + && echo "post_max_size = 512M" >> /usr/local/etc/php/conf.d/custom-php.ini \ + && echo "upload_max_filesize = 512M" >> /usr/local/etc/php/conf.d/custom-php.ini \ + && echo "expose_php = Off" >> /usr/local/etc/php/conf.d/custom-php.ini + +# 复制 PHP 源代码到容器中 +COPY . /var/www/html/ + +RUN mkdir /var/www/.cache +RUN chown -R www-data:www-data /var/www/.cache +RUN chmod -R 755 /var/www/.cache +RUN chown -R www-data:www-data /var/www/html +RUN chmod -R 755 /var/www/html + +# 使用 composer 安装依赖 +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ + && cd /var/www/html/ +RUN sudo -u www-data composer install + +EXPOSE 80 443 \ No newline at end of file diff --git a/README.md b/README.md index 23b7957..f859e48 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,26 @@ Garnet 1.0.8 / Redis 7.0.15 环境搭建 ------------ +### Docker (测试) + +```bash +docker network create my-network +docker run -d --name mariadb-container \ + -v /home/chenx221/db.sql:/docker-entrypoint-initdb.d/db.sql \ + -e MYSQL_ROOT_PASSWORD=chenx221 \ + --network=my-network \ + mariadb:latest +docker run -d --name redis-container \ + --network=my-network \ + redis +docker run -d -p 80:80 -p 443:443 \ + -v /home/chenx221/fullchain1.pem:/etc/ssl/fullchain1.pem \ + -v /home/chenx221/privkey1.pem:/etc/ssl/privkey1.pem \ + -v /home/chenx221/data:/var/www/html/data \ + -v /home/chenx221/.env:/var/www/html/.env \ + --network=my-network \ + chenx221-yii2-netdisk +``` ### For Windows @@ -308,31 +328,7 @@ xdebug.client_host = 127.0.0.1 xdebug.client_port= 9003 xdebug.remote_handler=dbgp ``` -```bash -sudo nano /etc/php/8.2/cli/php.ini -``` -修改 -```ini -max_execution_time = 360 -post_max_size = 2G -upload_max_filesize = 2G -``` -增加 -```ini -date.timezone = "Asia/Shanghai" -[xdebug] -xdebug.mode =debug -xdebug.output_dir ="/tmp" -xdebug.show_local_vars=0 -xdebug.log="/tmp/xdebug.log" -xdebug.log_level=7 -xdebug.profiler_output_name=trace.%H.%t.%p.cgrind -xdebug.use_compression=false -xdebug.discover_client_host = true -xdebug.client_host = 127.0.0.1 -xdebug.client_port= 9003 -xdebug.remote_handler=dbgp -``` + ```bash sudo systemctl restart apache2 ``` diff --git a/conf/apache.conf b/conf/apache.conf new file mode 100644 index 0000000..6e984f0 --- /dev/null +++ b/conf/apache.conf @@ -0,0 +1,24 @@ +# HTTP 配置,监听端口 80,并重定向到 HTTPS + + ServerName demo.chenx221.cyou + + RewriteEngine On + RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L] + + +# HTTPS 配置,监听端口 443 + + ServerName demo.chenx221.cyou + + DocumentRoot "/var/www/html/web" + + Options +Indexes +Includes +FollowSymLinks +MultiViews + AllowOverride All + Require all granted + LimitRequestBody 2147483648 + + + SSLEngine on + SSLCertificateFile "/etc/ssl/fullchain1.pem" + SSLCertificateKeyFile "/etc/ssl/privkey1.pem" + \ No newline at end of file