PHP 分這四種模式,及它可以設定的地方

  • PHP_INI_USER – 只能在 php 的 ini_set() 、與 檔案 .user.ini  (php 5.3 後support)
  • PHP_INI_PERDIR – 只在 /etc/php.ini、.htaccess、httpd.conf、 .user.ini (php 5.3 後 support)
  • PHP_INI_SYSTEM – 只在 php.ini 與 httpd.conf
  • PHP_INI_ALL – 能在任何地方

如果 PHP 是跑 apache module (mod_php) 時可以強制在 virtualhost 裡使用 php_admin_flag or value 讓 .htaccess 裡面 php_flag or value 的值無效,連同 ini_set() 也是

不過 .user.ini 在 PHP 5.3 版本後出現了,它也只用於 CGI/fastCGI 環境

現在 PHP 用 CGI 或 fastCGI 跑是很常見的,我竟現在才發現 .user.ini 這東東,它可以放在網站目錄底下設定想要的 PHP 參數,而且 它是不受 Loaded Configuration File 限制 (PHPINFO看得到),這是多麼危險啊,fastCGI/CGI 是連讓 ini_set() 也沒限到

意思是說我設置某個 virtualhost 的 memory_limit = 128M
(我會針對每個 virtualhost 設置自已的 php.ini)

但底下這樣子就可以改變我的限制

# xx.php
ini_set('memory_limit','1024M');
# /var/www/html/ssorc.tw/.user.ini
memory_limit = 2048M

怎麼防止使用 .user.ini,就在個別的 php.ini 裡設置如下,空值

user_ini.filename = ""

但 ini_set() 呢,只能用 disable_function = ‘ini_set’ 嗎,像用 apache module (mod_php) 時,我可以用 php_admin_flag or value 限制我想限制的,就不會讓 ini_set() 不能用

我列出 .user.ini 可被成功設定生效的參數 (我常用的),有(# ————-)符號就是

sendmail_path = "/usr/sbin/sendmail -t -i -f apache@ssorc.tw"
sendmail_from = “apache@ssorc.tw" # -------------
open_basedir = "/var/www/html/ssorc.tw:/tmp/ssorc.tw"	 	 
upload_tmp_dir = "/tmp/ssorc.tw"	 	 
session.save_path = "/tmp/ssorc.tw"	 	 
safe_mode = "Off"	 	 
disable_functions = "exec,passthru,proc_open,shell_exec,system,popen,dl"	 	 
memory_limit = "123M" # -------------	 	 
post_max_size = "123M" # -------------	 	 
upload_max_filesize = "123M" # -------------	 	 
allow_url_fopen = "Off"	 	 
file_uploads = "On"	 	 
max_execution_time = "30" # -------------	 	 
max_file_uploads = "20" # -------------	 	 
register_globals = "Off"	 	 
output_buffering = "4096"	 	 
error_reporting = "6143"	 	 
expose_php = "Off"	 	 
log_errors = "On" # -------------	 	 
display_errors = "Off" # -------------	 	 
magic_quotes_gpc = "Off"	 	 
max_input_time = "60" # -------------	 	 
register_argc_argv = "Off" # -------------	 	 
register_long_arrays = "Off"	 	 
allow_call_time_pass_reference = "Off"	 	 
include_path = ".:" # -------------

其它相關文章

Apache 使用 mod_php 讓 VH 有獨立的 php.ini 檔
php_flag + php_value + Apache 在不更改 php.ini 的情況下更改預設值
Apache + 可以限制 .htaccess 只能使用某些參數嗎

Related posts 相關文章
WordPress 6.3 以後可能不支援 PHP 5,最低需求為 PHP 7.4
More...
你的 WordPress 升級到 PHP 8 了嗎
More...
你看 WordPress 也建議至少 PHP 7.4+ 了
More...
PHP 7 最後一版,今年也要退場了
More...

作者

留言

作者

php+ user.ini + fastcgi 不能用 ?? .user.ini 限制 fastcgi 不能用 ?? 在 domain/php.ini 裡新增 user_ini.filename = “” 但 ini_set() 只能 disable_function 嗎 ?? http://forum.sp.parallels.com/threads/php-5-3-run-as-fastcgi-application.327644/

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。