[TOC]
# 部署
## Apache 配置
```
// Apache 默認已存在文件 public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
```
## Nginx配置
```
server {
listen 80;
server_name example.com;
root /example.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
```
## 自動加載器改進
```
$ composer install --optimize-autoloader --no-dev
```
>[success] 注意:除了優化自動加載器,你還應該確保在你的項目代碼倉庫中包含了 composer.lock 這個文件。當你的項目代碼中有 composer.lock 這個文件時,便可以更快的安裝項目中需要的依賴項。
## 生成配置緩存
```
$ php artisan config:cache
$ php artisan config:clear // 刪除緩存
```
>[success] 注意:如果在部署過程中執行 config:cache 命令,那你應該確保只從配置文件內部調用 env 函數。一旦配置被緩存,.env 文件將不再被加載,所有對 env 函數的調用都將返回 null。
## 生成路由緩存
```
$ php artisan route:cache
$ php artisan route:clear // 刪除緩存
```
>[success] 注意:由于此功能使用 PHP 序列化,你僅能緩存專門使用基于控制器路由的應用程序路由。PHP 不能序列化閉包路由。
## 維護模式
```
php artisan down
// message 顯示或記錄自定義消息
// retry 設置 HTTP 請求頭中 Retry-After 的值
php artisan down --message="Upgrading Database" --retry=60
// allow 選項允許特定的 IP 地址或網絡訪問應用程序
php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16
// 關閉維護模式
php artisan up
```
- 入門指南
- 安裝
- 部署
- 基礎功能
- 路由
- 中間件
- CSRF 保護
- 控制器
- 請求
- 響應
- 視圖
- URL
- Session
- 表單驗證
- 錯誤
- 日志
- 前端開發
- Blade 模板
- 本地化
- 腳手架
- 編譯資源 Mix
- 安全相關
- 用戶認證
- API 認證
- 綜合話題
- 命令行
- 廣播
- 緩存
- 集合
- 事件
- 文件存儲
- 輔助函數
- 郵件發送
- 消息通知
- 擴展包開發
- 隊列
- 任務調度
- 數據庫
- 快速入門
- 查詢構造器
- 分頁
- 數據庫遷移
- 數據填充
- Redis
- Eloquent ORM
- 快速入門
- 速查表
- Artisan
- Auth
- Blade
- Cache
- Collection
- Composer
- Config
- Container
- Cookie
- DB
- Environment
- Event
- File
- Helper
- Input
- Lang
- Log
- Model
- Pagination
- Queue
- Redirect
- Request
- Response
- Route
- SSH
- Schema
- Security
- Session
- Storage
- String
- URL
- UnitTest
- Validation
- View