資源
Laravel7 30天: 目錄
專案連結: github - laravel7 之 30 天分享
前言
上一篇: Day 2. 安裝及資料夾介紹
今天則要來介紹初始化的一些設定,
伺服器設定
檔案資料夾要設定在 專案路徑/public/
nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| server {
listen 80;
listen [::]:80;
# (1) 網址
server_name laravel7-30days.test;
# (2)專案路徑
root /var/www/html/laravel7-30days/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri $uri/ =404;
# (3) php使用
# local
# fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# docker
fastcgi_pass PHP7.3:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# for phpstorm / xdebug
#fastcgi_param PHP_IDE_CONFIG serverName=localhost;
fastcgi_buffers 8 128k;
fastcgi_buffer_size 256k;
# for long running debug sessions
fastcgi_read_timeout 600;
#fastcgi_intercept_errors on;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
|
apache
我本地是使用 nginx
, 沒有使用 apache
這部份是參考網路上的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| <VirtualHost *:80>
# (1) 專案路徑
DocumentRoot "/var/www/html/laravel7-30days/public"
# (2) 網址
ServerName laravel7-30days.test
# (3) LOG的地方
ErrorLog "/var/www/html/laravel7-30days/storage/laravel7-30days_error.log"
CustomLog "/var/www/html/laravel7-30days/storage/laravel7-30days_access.log" combined
DirectoryIndex index.php
# (4) 專案路徑
<Directory "/var/www/html/laravel7-30days/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
|
執行
於專案路徑底下執行
1
2
3
4
5
6
7
8
9
| #複製一個環境檔
cp .env.example .env
# composer
composer install
# npm
npm install
#生成 .env key
php artisan key:generate
|
設定 env 檔
.env
檔是納入 .gitignore
的所以很多個人設定的東西可以直接放在這,如網址、DB連線 等等
基本設定
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| # 網站名稱
APP_NAME=Laravel-30天
# 環境 本地(local) 測試(develop) 正式(production) 也可以依照個人喜好設定
APP_ENV=local
# 網站必須的 key (執行 php artisan key:generate 就會產生)
APP_KEY=
# 是否要顯示錯誤 true|false
APP_DEBUG=true
# 網址
APP_URL=http://laravel7-30days.test
|
Log
Laravel 有自己的 LOG 可以查看,
我都設定 daily
每天都會產生一個 LOG檔
若想設定其他的可以參考文件
DB 設定
1
2
3
4
5
6
| DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
|
Redis 設定
1
2
3
| REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
|
Mail Server
發信用
1
2
3
4
5
6
7
8
| MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
|
其他
以下設定我都是使用預設值,
但還是簡單跟大家介紹一下
- 隊列設定,可以參考
/config/queue.php
設定,預設是 sync
,
如寄信功能就可能需要設定,避免執行過程中畫面卡著。 - Broadcaster 廣播,可以發通知的功能
可以參考 /config/broadcasting.php
(這個我目前沒用過) - 快取設定,可以參考
/config/cache.php
- Seesion 設定,可以參考
/config/session.php
1
2
| SESSION_DRIVER=file
SESSION_LIFETIME=120
|
結語
env 的設定,都是跟 /config/
底下檔案息息相關,
可以理解成 config 是預設值, env是設定值
所以我開發時都會直接用 config()
調用他們。