andrei_1234567890 andrei_1234567890 - 4 months ago 27
PHP Question

Set php second configuration ( php.ini file )

I want to set my own (php2.ini) file, with just a few lines that must overwrite the first php.ini settings - only for those lines.

So I start looking on google and seems like what I need is the parse_ini_file function.

Ok. Now, in index.php I have:


But those settings from php2.ini are not loaded....

Trying to see if the file php2.ini is read-it and it is, beacause if i set parse_ini_file("php2-not-exist.ini") tells me that the file cannot be found. So the file php2.ini is read, but the settings are not overwrited.

The php2.ini file has inside the next lines:

error_log = "errors.log"
display_errors = "0"
max_execution_time = "300"
upload_max_filesize = "60M"
post_max_size = "60M"
date.timezone = "Europe/Bucharest"
default_charset = "UTF-8"
mbstring.internal_encoding = "UTF-8"
mbstring.http_output = "UTF-8"
mbstring.encoding_translation = "On"
mbstring.func_overload = "6"

Trying to let this file with just one line like post_max_size = "60M", but still not overwriting the general php.ini settings.

There is one thing that I don't understand....

I know that some settings can be setted only and only using the php.ini file configuration. So setting a second file with parse_ini_file witch is a function from php.... something is not correct, because some servers doesn't allow you to edit the general php.ini file. So how can the php let you set a second php ini file if you don't have access to the general one ? I don't know if that has something to do with my problem. I'm just saying that maybe here is the problem.

Right now I'm using wamp with php 5.5.12. I just want when i upload my website up, to be all done. I know that some hosting servers lets you to have a second php.ini file that must be uploaded in public_html or whatever folder it is. This is why I want to set my php2.ini file. To have the website clean when I'll upload to hosting.

I'm waiting an answer please.

Thank you.


The php parse_ini_file() function reads an ini file into an associative array. It does not set them up as settings like the php.ini file.

There is not a convenience function to override the server settings like this. What you may want here are .user.ini (the leading dot is important) files:

Since PHP 5.3.0, PHP includes support for configuration INI files on a per-directory basis.


In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.

For full documentation on that feature, take a look at

Note that only a subset of settings can be changed here:

Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.