安裝
伺服器要求
- Golang >= 1.23
安裝
使用 Goravel 安裝器
根據文檔初始化安裝器,然後使用以下命令初始化一個新的 Goravel 項目:
// Install the latest version of the goravel installer
go install github.com/goravel/installer/goravel@latest
// Enter the directory where you want to install the project
goravel new blog手動安裝
// 下載框架
git clone --depth=1 https://github.com/goravel/goravel.git && rm -rf goravel/.git*
// 安裝依賴
cd goravel && go mod tidy
// 創建 .env 環境配置文件
cp .env.example .env
// 生成應用密鑰
go run . artisan key:generate如果您遇到下載依賴緩慢的情況,請確認您的網絡。
啟動 HTTP 服務
根據根目錄中的 .env 文件啟動服務
go run .指定 .env 文件啟動服務
go run . --env=./.env使用環境變量啟動服務
APP_ENV=production APP_DEBUG=true go run .即時重新加載
安裝 air-verse/air,Goravel 具備可以直接使用的內建配置文件:
air🧰 After Installing Air
Once you have successfully installed Air, you need to make sure it can be executed properly within your environment.
Depending on your setup, Air might not be automatically available as a command.
Here are two simple ways to ensure it runs correctly:
🪄 Option 1: Using a Helper Script (air.sh)
If Air is installed but not recognized as a terminal command, you can create a small helper script that locates and runs it automatically.
- Create a new file in your project root:
touch air.sh
chmod +x air.sh- Add the following content inside air.sh:
#!/bin/bash
GO_PATH=$(go env GOPATH)
GO_BIN=$GO_PATH/bin/air
if [ ! -f $GO_BIN ]; then
echo "❌ Air not found. Please install it first:"
echo " go install github.com/air-verse/air@latest"
exit 1
fi
echo "🚀 Starting Air..."
$GO_BIN- Run your project using:
./air.shThis ensures Air runs even if your $PATH does not include Go binaries.
💡 Option 2: Add Go Bin To PATH (Mac/Linux)
If you prefer to run Air directly without a script, you can add Go bin directory to your PATH.
For Zsh users:
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.zshrc
source ~/.zshrcAfter this setup, you can start your project simply by running:
air✅ Tip
To verify that Air is installed and accessible, run:
which airIf it doesn't return a valid path (for example /Users/yourname/go/bin/air), it means the helper script or the path hasn't been configured yet.
配置
配置文件
Goravel 框架的所有配置文件被放置在 config 目錄中。 所有配置項都有註解,您可以根據需要進行調整。
生成應用密鑰
在本地安裝 Goravel 後,您需要生成應用密鑰。 運行以下命令後,會在 .env 文件的 APP_KEY 鍵上生成 32 位字符串。 此密鑰主要用於數據加解密。
go run . artisan key:generate生成JWT Token
如果您使用到 身份驗證 功能,則需要生成 JWT Token。
go run . artisan jwt:secret加解密 env 文件
您可能希望將生產環境的 env 文件添加到版本控制中,但不想暴露敏感信息,您可以使用 env:encrypt 命令加密 env 文件:
go run . artisan env:encrypt
// 指定文件名與密鑰
go run . artisan env:encrypt --name .env.safe --key BgcELROHL8sAV568T7Fiki7krjLHOkUc然後在生產環境中使用 env:decrypt 命令來解密 env 文件:
GORAVEL_ENV_ENCRYPTION_KEY=BgcELROHL8sAV568T7Fiki7krjLHOkUc go run . artisan env:decrypt
// or
go run . artisan env:decrypt --name .env.safe --key BgcELROHL8sAV568T7Fiki7krjLHOkUc