Giter Site home page Giter Site logo

laravel-practise's Introduction

second-hand-books backend - Laravel 環境初始化

先來確認以下事情

安裝套件

# 包含開發環境所需的套件
composer install
# 僅安裝正式環境所需的套件,而不包含開發環境所需的套件
composer install --no-dev

.env 設定

.env 檔並不會預設就存在,因為這是整個專案的環境變數

# 將 .env.example 複製成 .env
cp .env.example .env

預設情況下,不會有 APP key

透過artisan產生一組網站專屬密鑰用來確保session、password等加密資料安全性

# 網頁上會有這些警告
No application encryption key has been specified.
Your app key is missing
Generate your application encryption key using `php artisan key:generate`.
php artisan key:generate

就會在 .env 產生

# 這是範例,請勿複製
# 會在 .env 中出現這段環境變數
APP_KEY=base64:dR4haQ8vN2TERj2M/tvUdSyC1cAZv4WbIDBCgDEzdzk=

以下為在 Linux 的環境需要做的事情

storage 權限不足

# 會有底下類似說明的錯誤,Permission denied
The stream or file "/home/web/public/core/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/home/web/public/core/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied......................

本機是開發環境可以調整檔案權限

將檔案權限全開啟(不安全)

chmod -R 0777 storage

開發站、測試站、正式站皆比照正式環境辦理

正式環境上應該遵循「最小權限原則」

chown -R www-data:www-data storage

正式環境下務必

APP_NAME=Laravel-SHD-Backend
APP_ENV=local #環境變數,正式改為 production
APP_KEY=base64:dR4haQ8vN2TERj2M/tvUdSyC1cAZv4WbIDBCgDEzdzk=
APP_DEBUG=true #Debug用途,正式改為 false
APP_URL=http://localhost # 主機 URL
APP_NAME
config/app.php
預設為 Laravel-SHD-Backend
此服務名稱
注意同一個 Domain Name 下每一個服務的 APP_NAME 都必須不同,避免瀏覽器混淆不同網站的 Cookie Name,可能會導致 419 expired 的問題。

APP_ENV
config/app.php
預設為 production
開發環境,用於加載不同環境時的配置

通常為
開發環境: local
自動測試: testing
產品環境: production

APP_DEBUG
config/app.php
預設為 false
開啟時一旦發生錯誤會跳在網頁上,有可能會將重要資訊或程式碼洩漏

APP_URL
config/app.php
預設為 http://localhost
為此服務預設的網頁根目錄

產生 JWT 令牌加密

#產生後要自行修改進 .env的 JWT_SECRET,他不會替換
php artisan jwt:secret

開發時幫助檢查腳本

執行腳本(開發時使用)

composer dev
# git 設定使用我們所寫的 hooks
# 詳情指令可以看 composer.json 中的 "scripts" 的 dev

開發者幫助工具

產生套件提示

php artisan ide-helper:generate

產生Model 資料庫操作提示

php artisan ide-helper:models
# 要選 no ,_ide_helper_models.php 他會產生提示
# 選 yes,會注入註解到 model,不需要麼做

產生 swagger 文檔

僅非 production 會產生

先將設定改置網頁目錄

L5_SWAGGER_CONST_HOST=http://{domain or ip}/{path}/public/

生 swagger 文檔

php artisan l5-swagger:generate

打開網頁

http://{domain or ip}/{path}/public/api/documentation
# 路徑是 config\l5-swagger.php 設定的

laravel-practise's People

Contributors

uinnnnnn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.