ReynierPM ReynierPM - 28 days ago 8x
Linux Question

How to overwrite some PHP defaults configuration?

Let's said that I have installed PHP 5.5.x in Ubuntu and it comes with a default configuration. I would like to overwrite a few configurations but I do not want to (this is how I know it's possible):

  • edit the default

  • use a PHP block in each
    file to overwrite them

  • use
    files and directives

I would like to create a file named
with the following lines (as an example):

; 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

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

Is there any place where I can write this file and default PHP values gets overwrited by the ones on


Yeah should be possible. First, create a PHP file somewhere in your document root called info.php and put <?php phpinfo() ?> in it. Then call it from the browser and look for Scan this dir for additional .ini files. On Ubuntu it is probably something like /etc/php5/apache2/conf.d.

In that directory, you can put your own custom ini file (call it something like 99.overrides.php.ini) so it gets parsed last.

In that file, put whatever additional config you want, restart Apache or the web server and the changes will take effect.