加入实验性的docker容器安装方法

This commit is contained in:
Chenx221 2024-05-24 20:26:01 +08:00
parent d0b7807a36
commit 05ecf5b3df
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
3 changed files with 84 additions and 25 deletions

39
Dockerfile Normal file
View File

@ -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

View File

@ -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 ### For Windows
@ -308,31 +328,7 @@ xdebug.client_host = 127.0.0.1
xdebug.client_port= 9003 xdebug.client_port= 9003
xdebug.remote_handler=dbgp 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 ```bash
sudo systemctl restart apache2 sudo systemctl restart apache2
``` ```

24
conf/apache.conf Normal file
View File

@ -0,0 +1,24 @@
# HTTP 配置,监听端口 80并重定向到 HTTPS
<VirtualHost *:80>
ServerName demo.chenx221.cyou
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
# HTTPS 配置,监听端口 443
<VirtualHost *:443>
ServerName demo.chenx221.cyou
DocumentRoot "/var/www/html/web"
<Directory "/var/www/html/web">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
LimitRequestBody 2147483648
</Directory>
SSLEngine on
SSLCertificateFile "/etc/ssl/fullchain1.pem"
SSLCertificateKeyFile "/etc/ssl/privkey1.pem"
</VirtualHost>