啟用後限制檔案系統存取權限(僅能操作擁有者檔案)、禁止執行系統指令、停用 dl() 動態載入擴展等。
; php.ini
safe_mode = On
safe_mode_gid = Off
safe_mode_include_dir = /usr/local/include/php
safe_mode_exec_dir = /usr/local/php-bin
safe_mode_allowed_env_vars = PHP_,TZ
注意:PHP 5.4+ 已移除安全模式,現代專案請改用 open_basedir、disable_functions 等替代方案。
expose_php = Off
; Apache httpd.conf 修改副檔名
AddType application/x-httpd-php .html .htm .phtml
open_basedir = /var/www/html:/tmp
disable_functions = exec,shell_exec,passthru,system,popen,dl
disable_classes =
.env)並排除版控。display_errors = Off(生產環境),改用 log_errors = On。session.cookie_httponly = 1、session.cookie_secure = 1(HTTPS 環境)。