Appearance
配置说明
MineShop 的配置文件位于 config/autoload/ 目录,支持环境变量覆盖。
🎯 配置结构
config/
├── autoload/
│ ├── databases.php # 数据库配置
│ ├── redis.php # Redis 配置
│ ├── server.php # 服务器配置
│ ├── async_queue.php # 异步队列配置
│ ├── cache.php # 缓存配置
│ └── ...
└── config.php # 主配置文件📦 核心配置
数据库配置
php
// config/autoload/databases.php
return [
'default' => [
'driver' => env('DB_DRIVER', 'mysql'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'mineshop'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
'connect_timeout' => 10.0,
'wait_timeout' => 3.0,
'max_idle_time' => 60.0,
],
],
];Redis 配置
php
// config/autoload/redis.php
return [
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'port' => (int) env('REDIS_PORT', 6379),
'auth' => env('REDIS_AUTH', null),
'db' => (int) env('REDIS_DB', 0),
'pool' => [
'min_connections' => 1,
'max_connections' => 10,
],
],
];服务器配置
php
// config/autoload/server.php
return [
'mode' => SWOOLE_PROCESS,
'servers' => [
[
'name' => 'http',
'type' => Server::SERVER_HTTP,
'host' => '0.0.0.0',
'port' => 9501,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
],
],
],
'settings' => [
'enable_coroutine' => true,
'worker_num' => swoole_cpu_num(),
'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
'open_tcp_nodelay' => true,
'max_coroutine' => 100000,
'socket_buffer_size' => 2 * 1024 * 1024,
],
];异步队列配置
php
// config/autoload/async_queue.php
return [
'default' => [
'driver' => Hyperf\AsyncQueue\Driver\RedisDriver::class,
'redis' => [
'pool' => 'default',
],
'channel' => '{queue}',
'timeout' => 2,
'retry_seconds' => 5,
'handle_timeout' => 10,
'processes' => 1,
'concurrent' => [
'limit' => 5,
],
],
];🔧 环境变量
.env 文件示例
env
# 应用配置
APP_NAME=MineShop
APP_ENV=production
# 数据库配置
DB_DRIVER=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mineshop
DB_USERNAME=root
DB_PASSWORD=your_password
# Redis 配置
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_AUTH=
REDIS_DB=0
# JWT 配置
JWT_SECRET=your_jwt_secret
JWT_TTL=7200📋 配置优先级
环境变量 > .env 文件 > 配置文件默认值⚠️ 注意事项
- 敏感信息: 密码等敏感信息使用环境变量
- 生产环境: 生产环境禁用调试模式
- 连接池: 根据服务器配置调整连接池大小
- 缓存配置: 生产环境启用配置缓存