Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite some PHP configuration defaults with a custom .ini file?

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 php.ini file
  • use a PHP block in each .php file to overwrite them
  • use .htaccess files and directives

I would like to create a file named custom-php.ini 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
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"

Is there any place where I can write this file and default PHP values gets overwrited by the ones on custom-php.ini?

like image 325
ReynierPM Avatar asked Sep 23 '16 20:09

ReynierPM


People also ask

How do I use a different PHP ini file?

For example, you can set the environment variable PHPRC , or you can put a different php. ini file in each current working directory, assuming each virtual host has a distinct cwd. Note that when using Apache and mod_php, or other module embedding PHP in the web server (e.g. FastCGI), the php.

What is PHP ini configuration file?

The php. ini file is the default configuration file for running applications that require PHP. It is used to control variables such as upload sizes, file timeouts, and resource limits. php. ini file is the configuration file.


1 Answers

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.

like image 107
drew010 Avatar answered Oct 24 '22 00:10

drew010