動工前必須產出:需求文件、功能清單、原型圖、資料庫 ER 圖、API 合約、非功能需求(效能、安全、相容性)。未經確認的需求是專案失敗主因。
.com/.tw/.cn| 類型 | 適用階段 | 優點 | 缺點 |
|---|---|---|---|
| 共享主機 | 個人/極小專案 | 便宜、免維運 | 資源共用、權限低、效能不穩 |
| VPS / 雲伺服器 | 中小型專案 | Root 權限、彈性擴充、成本可控 | 需自行維運、安全加固 |
| 容器/Serverless | 現代化部署 | 自動擴縮、按用量付費 | 冷啟動、Vendor Lock-in |
| 獨立主機 | 大型/高安全 | 專屬資源、合規 | 昂貴、擴充慢 |
**建議**:起步用 VPS(1-2 vCPU, 2-4GB RAM, SSD),採 Ubuntu 22.04 LTS / Debian 12 / Rocky Linux 9。
# /etc/nginx/sites-available/example.com
server {
listen 80; listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 300;
}
# 安全:隱藏版本、禁止敏感檔案存取
location ~ /\.(env|git|htaccess) { deny all; }
}
maxmemory-policy allkeys-lru、持久化 AOF| 框架 | 定位 | 學習曲線 | 生態 |
|---|---|---|---|
| Laravel | 全功能、企業級首選 | 中 | 極豐富 |
| Symfony | 大型、長期、高度客製 | 高 | 企業級 |
| CodeIgniter 4 | 輕量、上手快 | 低 | 中等 |
| ThinkPHP 8 | 國內流行、文檔中文 | 低 | 國內豐富 |
| Hyperf / Swoole | 高效能、長駐、微服務 | 高 | 新興 |
**初始化標準流程 (以 Laravel 為例)**:
composer create-project laravel/laravel my-project cd my-project cp .env.example .env # 編輯 .env: APP_KEY, DB_*, REDIS_*, MAIL_* php artisan key:generate php artisan migrate --seed php artisan storage:link # 設定排程: * * * * * cd /path && php artisan schedule:run >> /dev/null 2>&1 # 設定佇列監聽: supervisor 管理 php artisan queue:work --sleep=3 --tries=3
| 項目 | 做法 |
|---|---|
| URL 結構 | 語意化、靜態化、無參數雜訊、規範化 (canonical) |
| Meta 標籤 | title、description、OG 標籤、JSON-LD 結構化資料 |
| 靜態資源 | Vite/laravel-mix 打包、版本哈希、gzip/brotli、CDN |
| 快取策略 | HTTP 快取標頭、Redis 頁面/片段快取、OPcache 預載入 |
| 資料庫 | 索引優化、慢查詢分析、讀寫分離、分表分庫 |
composer update、安全掃描 composer auditPHP 網站建設非單純「寫代碼」,而是**基礎設施、架構選型、工程規範、部署運維**的系統工程。遵循標準化流程、善用成熟生態、建立可觀測體系,才能交付穩定、可擴展、安全的產品。