2016-09-23 41 views
2

讓我們說,我已經在Ubuntu中安裝了PHP 5.5.x,它帶有一個默認配置。我想覆蓋一些配置,但我不希望(這就是我知道這是可能的):如何覆蓋一些PHP的默認配置?

  • 編輯默認php.ini文件
  • 使用PHP塊中的每個.php文件覆蓋它們
  • 使用.htaccess文件和指令

我想創建一個名爲custom-php.ini有如下的文件(作爲一個例子):

; Basic configuration override 
expose_php = Off 
memory_limit = 512M 
post_max_size = 128M 
upload_max_filesize = 128M 
date.timezone = UTC 
max_execution_time = 120 

; Error reporting 
display_errors = stderr 
display_startup_errors = Off 
error_reporting = E_ALL 

; A bit of performance tuning 
realpath_cache_size = 128k 

; OpCache tuning 
opcache.max_accelerated_files = 32000 
; Temporarily disable using HUGE PAGES by OpCache. 
; This should improve performance, but requires appropriate OS configuration 
; and for now it often results with some weird PHP warning: 
; PHP Warning: Zend OPcache huge_code_pages: madvise(HUGEPAGE) failed: Invalid argument (22) in Unknown on line 0 
opcache.huge_code_pages=0 

; Xdebug 
[Xdebug] 
xdebug.remote_enable = true 
xdebug.remote_host = "192.168.3.1" // this IP should be the host IP 
xdebug.remote_port = "9001" 
xdebug.idekey  = "XDEBUG_PHPSTORM" 

有什麼地方可以寫這個文件,默認的PHP值會被custom-php.ini上的那些文件覆蓋嗎?

+1

我沒有附近的Ubuntu機器來檢查,但沒有像'/ etc/php/conf.d'這樣的東西嗎?你應該能夠在那裏放置一個部分配置,它將覆蓋主配置文件。 – Chris

+0

不需要** ini_set()**,ya? –

+0

@TheOneandOnlyChemistryBlob是的,我不想爲每個文件添加這樣的行;) – ReynierPM

回答

3

呀應該是可能的。首先,在您的文檔根目錄中創建一個名爲info.php的PHP文件,並將其放入<?php phpinfo() ?>。然後從瀏覽器中調用它並查找Scan this dir for additional .ini files。在Ubuntu上它可能類似於/etc/php5/apache2/conf.d

在該目錄中,您可以放置​​自己的自定義ini文件(稱爲99.overrides.php.ini),以便最後解析。

在該文件中,將所需的任何其他配置,重新啓動Apache或Web服務器,更改將生效。

+0

請注意,只有在使用「--with-config-file-scan-dir」參數編譯PHP時,纔會設置'Scan this dir for additional .ini files'值。如果它說的是'(none)',那麼你必須重新編譯PHP並使用更正選項才能使用此功能。 –

0

如果你不使用Apache和你使用CGI/FastCGI的SAPI可以使用.user.ini文件波紋管:

upload_max_filesize  = "300M" 
post_max_size   = "100M" 
+0

從OP中,原始問題:「我不想......使用'.htaccess'文件和指令」。 – Chris

+0

他說他知道這種方法,而不是他不想使用這種方法。我已經設定了我的答案,從上到下列出了我的經驗中常用的方法和最好的方法。 – CIRCLE

+0

我的評論包括來自OP的_direct quote_:「我不想......使用'.htaccess'文件和指令」。我很確定OP不想要這個解決方案。 – Chris