編譯 Apache 時啟用 --enable-so,PHP 配置 --with-apxs。升級 PHP 僅需 make clean && ./configure ... && make && make install 並重啟 Apache,無需重編 Apache。
; php.ini
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0 ; 生產環境關閉檢查,部署後需重啟 php-fpm 或發送 SIGUSR2
opcache.jit=1255 ; PHP 8+ JIT 編譯
消除手動 require,統一規範,支援版本鎖定、腳本鉤子、插件生態。
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
$stmt->execute([$email]);
$user = $stmt->fetch();
display_errors=On,生產 display_errors=Off, log_errors=On。AppException、ValidationException、NotFoundException。set_exception_handler() 統一返回 JSON/友好頁面。echo htmlspecialchars($str, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
// 模板引擎自動轉義 (Blade {{ }}, Twig {{ }})
$hash = password_hash($pwd, PASSWORD_BCRYPT, ['cost' => 12]);
if (password_verify($input, $hash)) { /* 登錄成功 */ }
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1); // 僅 HTTPS
ini_set('session.use_strict_mode', 1);
ini_set('session.gc_maxlifetime', 1800);
<link href="/assets/app.css?v== filemtime(__DIR__.'/public/assets/app.css') ?>" rel="stylesheet">