Skip to content

Commit b54fffe

Browse files
committed
分类支持多个层级
1 parent 2cb6b54 commit b54fffe

18 files changed

Lines changed: 369 additions & 29 deletions

File tree

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM php:7.0-fpm-alpine
2+
3+
# Install system dependencies
4+
RUN apk add --no-cache \
5+
git \
6+
curl \
7+
libpng-dev \
8+
oniguruma-dev \
9+
libxml2-dev \
10+
zip \
11+
unzip \
12+
libzip-dev \
13+
ttf-dejavu \
14+
ttf-freefont
15+
16+
# Install PHP extensions
17+
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
18+
19+
# Get Composer 1.10 (compatible with PHP 7.0)
20+
COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer
21+
22+
# Set working directory
23+
WORKDIR /var/www/html
24+
25+
# Copy project files
26+
COPY . .
27+
28+
# Set git security directory
29+
RUN git config --global --add safe.directory /var/www/html
30+
31+
# Set memory limit for Composer
32+
ENV COMPOSER_MEMORY_LIMIT=-1
33+
34+
# Install project dependencies
35+
RUN composer install --no-interaction --no-dev --optimize-autoloader
36+
37+
# Set correct permissions
38+
RUN mkdir -p /var/www/html/storage/framework/sessions \
39+
/var/www/html/storage/framework/views \
40+
/var/www/html/storage/framework/cache \
41+
/var/www/html/storage/logs \
42+
/var/www/html/storage/app/public \
43+
/var/www/html/bootstrap/cache \
44+
/var/www/html/public/vendor/captcha/fonts
45+
46+
RUN chown -R www-data:www-data /var/www/html/storage \
47+
/var/www/html/bootstrap/cache \
48+
/var/www/html/public/vendor/captcha
49+
50+
RUN chmod -R 775 /var/www/html/storage \
51+
/var/www/html/bootstrap/cache \
52+
/var/www/html/public/vendor/captcha

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"type": "project",
88
"require": {
99
"ext-json": "*",
10-
"php": ">=5.5.9",
10+
"php": ">=5.6.0",
1111
"laravel/framework": "5.1.*",
12-
"modstart/modstart-laravel5": "dev-master"
12+
"modstart/modstart-laravel5": "dev-master",
13+
"league/commonmark": "0.18.5",
14+
"league/commonmark-ext-table": "0.9.0"
1315
},
1416
"minimum-stability": "dev",
1517
"prefer-stable": true,

docker-compose.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: '3'
2+
3+
services:
4+
php:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
platform: linux/amd64
9+
volumes:
10+
- .:/var/www/html
11+
environment:
12+
- DB_HOST=mysql
13+
- DB_PORT=3306
14+
- DB_DATABASE=modstart_blog
15+
- DB_USERNAME=modstart
16+
- DB_PASSWORD=secret
17+
networks:
18+
- app-network
19+
20+
nginx:
21+
image: nginx:alpine
22+
platform: linux/amd64
23+
ports:
24+
- "8000:80"
25+
volumes:
26+
- .:/var/www/html
27+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
28+
depends_on:
29+
- php
30+
networks:
31+
- app-network
32+
33+
mysql:
34+
image: mysql:5.7
35+
platform: linux/amd64
36+
ports:
37+
- "3306:3306"
38+
environment:
39+
MYSQL_DATABASE: modstart_blog
40+
MYSQL_ROOT_PASSWORD: root
41+
MYSQL_PASSWORD: secret
42+
MYSQL_USER: modstart
43+
command: --default-authentication-plugin=mysql_native_password
44+
volumes:
45+
- dbdata:/var/lib/mysql
46+
networks:
47+
- app-network
48+
49+
networks:
50+
app-network:
51+
driver: bridge
52+
53+
volumes:
54+
dbdata:
55+
driver: local

docker/nginx/default.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
index index.php index.html;
4+
error_log /var/log/nginx/error.log;
5+
access_log /var/log/nginx/access.log;
6+
root /var/www/html/public;
7+
8+
location / {
9+
try_files $uri $uri/ /index.php?$query_string;
10+
}
11+
12+
location /install/ping {
13+
try_files $uri $uri/ /index.php?$query_string;
14+
access_log off;
15+
}
16+
17+
location ~ \.php$ {
18+
try_files $uri =404;
19+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
20+
fastcgi_pass app:9000;
21+
fastcgi_index index.php;
22+
include fastcgi_params;
23+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
24+
fastcgi_param PATH_INFO $fastcgi_path_info;
25+
}
26+
27+
# 禁止访问 .htaccess 文件
28+
location ~ /\.ht {
29+
deny all;
30+
}
31+
}

docker/php/Dockerfile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM php:8.1-fpm-bullseye
2+
3+
# 安装系统依赖
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
curl \
7+
libpng-dev \
8+
libonig-dev \
9+
libxml2-dev \
10+
zip \
11+
unzip \
12+
libfreetype6-dev \
13+
libjpeg62-turbo-dev \
14+
libpng-dev \
15+
zlib1g-dev
16+
17+
# 安装 PHP 扩展
18+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
19+
&& docker-php-ext-install -j$(nproc) gd \
20+
&& docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath
21+
22+
# 验证 GD 和 FreeType 是否正确安装
23+
RUN php -r 'var_dump(gd_info());'
24+
25+
# 安装 Composer
26+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
27+
28+
# 设置工作目录
29+
WORKDIR /var/www/html
30+
31+
# 复制项目文件
32+
COPY . /var/www/html
33+
34+
# 设置权限
35+
RUN chown -R www-data:www-data /var/www/html \
36+
&& find /var/www/html/storage -type d -exec chmod 775 {} \; \
37+
&& find /var/www/html/storage -type f -exec chmod 664 {} \; \
38+
&& chmod -R ug+rwx /var/www/html/storage \
39+
&& chmod -R ug+rwx /var/www/html/bootstrap/cache
40+
41+
# 创建一个启动脚本
42+
COPY docker-entrypoint.sh /usr/local/bin/
43+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
44+
45+
ENTRYPOINT ["docker-entrypoint.sh"]
46+
CMD ["php-fpm"]
47+
48+
# 设置 PHP 配置
49+
RUN echo "upload_max_filesize=100M" >> /usr/local/etc/php/conf.d/docker-php-ext-upload.ini \
50+
&& echo "post_max_size=100M" >> /usr/local/etc/php/conf.d/docker-php-ext-upload.ini \
51+
&& echo "memory_limit=512M" >> /usr/local/etc/php/conf.d/docker-php-ext-upload.ini \
52+
&& echo "max_execution_time=600" >> /usr/local/etc/php/conf.d/docker-php-ext-upload.ini \
53+
&& echo "max_input_time=600" >> /usr/local/etc/php/conf.d/docker-php-ext-upload.ini
54+
55+
# 设置时区
56+
RUN echo "date.timezone=Asia/Shanghai" >> /usr/local/etc/php/conf.d/docker-php-ext-timezone.ini
57+
58+
# 设置用户
59+
USER www-data

docker/php/docker-entrypoint.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# 确保storage和bootstrap/cache目录存在
5+
mkdir -p /var/www/html/storage
6+
mkdir -p /var/www/html/bootstrap/cache
7+
8+
# 设置目录权限
9+
chown -R www-data:www-data /var/www/html
10+
find /var/www/html/storage -type d -exec chmod 775 {} \;
11+
find /var/www/html/storage -type f -exec chmod 664 {} \;
12+
chmod -R ug+rwx /var/www/html/storage
13+
chmod -R ug+rwx /var/www/html/bootstrap/cache
14+
15+
# 执行传入的命令(通常是php-fpm)
16+
exec "$@"

module/Blog/Model/BlogCategory.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,31 @@ public function parent()
2424
{
2525
return $this->belongsTo(BlogCategory::class, 'pid', 'id');
2626
}
27+
28+
/**
29+
* 获取树形结构的父级ID字段名
30+
* @return string
31+
*/
32+
public function getTreeParentIdField()
33+
{
34+
return 'pid';
35+
}
36+
37+
/**
38+
* 获取树形结构的排序字段名
39+
* @return string
40+
*/
41+
public function getTreeSortField()
42+
{
43+
return 'sort';
44+
}
45+
46+
/**
47+
* 获取树形结构的标题字段名
48+
* @return string
49+
*/
50+
public function getTreeTitleField()
51+
{
52+
return 'title';
53+
}
2754
}

nginx.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
server {
2+
listen 80;
3+
server_name localhost;
4+
root /var/www/html/public;
5+
index index.php index.html index.htm;
6+
7+
location / {
8+
try_files $uri $uri/ /index.php?$query_string;
9+
}
10+
11+
# PHP-FPM Configuration
12+
location ~ \.php$ {
13+
try_files $uri =404;
14+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
15+
fastcgi_pass php:9000;
16+
fastcgi_index index.php;
17+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
18+
include fastcgi_params;
19+
fastcgi_param PATH_INFO $fastcgi_path_info;
20+
}
21+
22+
# Deny access to .htaccess files
23+
location ~ /\.ht {
24+
deny all;
25+
}
26+
27+
# Cache static files
28+
location ~* \.(jpg|jpeg|png|gif|ico|css|js|eot|ttf|woff|woff2)$ {
29+
expires max;
30+
add_header Cache-Control public;
31+
access_log off;
32+
}
33+
34+
# Security headers
35+
add_header X-Frame-Options "SAMEORIGIN";
36+
add_header X-XSS-Protection "1; mode=block";
37+
add_header X-Content-Type-Options "nosniff";
38+
}

public/images/new-user.png

Lines changed: 1 addition & 0 deletions
Loading

storage/app/.gitignore

100644100755
File mode changed.

0 commit comments

Comments
 (0)