Php.ini production vs development - php

I'm using XAMPP to develop on my localhost. I would like to remove the PHP notices and keep only the warnings. I know this is done through the php.ini file, however I'm having trouble locating it. I followed the path in phpinfo() and it led me to /xampp/php. Inside this folder are two php.ini files: one for production and one for development. I have set them both to the error reporting level I'd like, however I still receive notices which makes me believe that neither of these actually control error reporting. I'm using the latest version of XAMPP. So I guess my question is where is the true php.ini and what are these two other versions?

As of PHP 7 the regular php.ini file was removed and added with php.ini-production and php.ini-devlopment. In PHP's installation text file they state, "We advise you to use php.ini-production, because we optimized the default settings in this file for performance, and security."
So in short use the php.ini-production

First, make sure you're editing php.ini, not php-development.ini or php-production.ini or anything BUT php.ini. After that, ensure you restart your Apache server or your changes won't take effect.
Also, check out ini_set for setting ini values at runtime.

I had this confusion, in my computer, the php.ini file didn't appear with the .ini extension name visible - it was just php , and in the type column, it has the value 'configuration settings'

I downloaded php-8.1.0 from official website. php.ini or configuration settings file is not present in it. Instead it has been replaced by two files i.e. php.ini-development and php.ini-production.
My requirement was to edit the php.ini file in order to enable pgsql extension. Alas! there were not one but two .ini files. Being new to php, I made changes to both the files but it didn't worked.
After doing some research, I came to know that in the recent versions of php (not sure from which), user is provided with two .ini files. As name suggests, php.ini-development contains settings suitable for development environment and php.ini-production contains settings suitable for production environment. As per your requirement, you need take backup of anyone of the file and rename that file to php.ini. In this file you will need make required changes for your php environment.
If you compare the two files using tools such as diff-merge, you will get more in-depth understanding.

php.ini.development and php.ini.production are entirely different from php.ini.
the problem is that in the php folder the required php.ini is not marked along with its extension ( .php). Only php is written.Check the properties of the file 'php' of "*configuration settings*" type.it must be .ini,This is the exact file which manages error reporting.

In XAMPP version 1.8.1 php.ini file located at \xampp\php\php.ini modify line 922 upload_max_filesize = 2M
Note: 2M means 2MB, so change to 10M for 10MB file upload. Also note that php.ini-development and php.ini-production are different files from php.ini.

My issue is that I was editing the php.ini-production and overlooked the standard php.ini file.
I edited the php.ini file by adding extension=php_odbc.dll and it fixed the error.

PHP 5.3.0 has significantly improved performance and parsing of INI files, and adds several new syntax features.
The standard php.ini files have been re-organized and renamed. php.ini-development contains settings recommended for use in development environments. php.ini-production contains settings recommended for use in production environments

The PHP.ini file is still there, only it doesn't include the extension .ini, the extension has been removed. You will notice two file name php, one is application file another is configuration setting when you open configuration setting in notepad you will notice that it has ini extension. so the php configuration file is ini file.

Related

How to fix PHP Deprecated Automatically populating $HTTP_RAW_POST_DATA is deprecated issue?

hello i'm getting this error in my error log:
"PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0"
My wordpress version is 4.8.1 and the php version is 5.6.30.
I tried fixing the issue by creating a php ini file and setting always_populate_raw_post_data value to -1. But i still get the error.
If it cannot be fixed, how can i prevent it prints on the error log?
I'm using a shared hosting.
how can i prevent it prints on the error log?
Your problem here is not that you cannot access php.ini and it is not that error shows.
Your problem, in fact, is that you use deprecated variable
instead, you could try using
file_get_contents('php://input');
php.ini is located somewhere in the php files on the server, which I assume you have no access to on shared hosting.
The php.ini file you created needs to be located where PHP expects to find its config files. You can see the configs which PHP is already loading using the phpinfo() function:
Upload a file named info.php with the following contents to your web server root:
<?php
// delete this file or comment out the below function when not in use
phpinfo();
?>
Then use a browser to navigate to http://yourwebsite.com/info.php. A page should load which tells you all about your php configuration. Look for the part near the top which shows information about the loaded configuration files. In particular, look for these entries:
"Loaded Configuration File" and "Scan this dir for additional .ini files".
If you have access to the .ini file listed as the Loaded Configuration File simply modify the value for always_populate_raw_post_data there. Otherwise, upload the .ini file you already created to the directory that is scanned for additional configuration files. Of course, you'll need to reload or restart php in order to reparse the configuration files.
If you don't have access to any of the locations listed from the above steps, it's possible your hosting provider may give you access to your php.ini file through cPanel or a similar means. Otherwise, your best bet is to contact them directly.
Finally, if you don't care about the actual configuration value as much as just suppressing the warning message, you could use the ini_set() function to set your error reporting to a different value, eliminating any deprecation warnings. The variable you want to set is "error_reporting" and a list of possible values can be found here.
In addition, since you are running WordPress there are some debug and error reporting options you can set in the wp-config.php file.
If your Account (on the shared hosting) using (or Configured) PHP-FPM, you can't do it via php.ini (if you create php.ini in your root, it will have no effect)
you can try: add this code
<IfModule mod_php5.c>
php_value always_populate_raw_post_data -1
</IfModule>
in your .htaccess file in your root directory, if not helps then ask the server admin (support) to change that in core php.ini globally for the given host.
You cant create a PHP.ini just like that. This is a core config file that is part of the PHP install. http://php.net/manual/en/configuration.file.php Read over this documentation to get a better idea of what the ini does.
The ini file could be located in multiple places depending on the OS and who installed it. If you do not have access to it, talk to your hosting provider

Installing PHP on Linux and php.ini file

I have installed PHP with Apache 2.2 on my Linux machine and all works fine following guide here
During the installation I had to copy the php.ini-development file into /usr/local/lib/php.ini, the question is why? Why exactly in this directory?
Default locations of the PHP configurations vary greatly by distribution. In any case, phpinfo() will allways tell you where is looks for your configurations.
So, create file with extension ".php" in your webroot and past this into it:
<?php
phpinfo();
Also, the default php.ini files contain plenty od usefull comments. Just read them and change what you need. Differences between dev and prod environments are usually only the verbosity. They show and log different ammounts of errors. Production usually shows no error at all.
(Debian and many other distributions put the PHP config into /etc/php5. This is actually the most reasonable place for configurations, but stick with what your distribution uses.)
The document you link to says this
You may edit your .ini file to set PHP options. [...]
If you instead choose php.ini-production, be certain to read the list of changes within, as they affect how PHP behaves.`
Have you tried something like
vi /usr/local/lib/php.ini
to see what's in it?
Maybe you need to read http://www.php.net/manual/en/configuration.file.php
You copied a default PHP.ini file, php.ini-development, to the standard 'php.ini' file in the location '/usr/local/lib/' the guide http://www.php.net/manual/it/install.unix.apache2.php
expected the php.ini file to be.
The php.ini file is a configuration file used by PHP when it is launched (runtime)

php.ini unable to change upload_max_filesize

I am developing php applications on Ubuntu 13.04 and when i am trying to change the upload_max_filesize setting:
$ sudo gedit /etc/php5/apache2/php.ini
and restart apache the values do not change in my phpinfo() they stay at the default values
This is the path mentioned in the phpinfo:
Loaded Configuration File /etc/php5/apache2/php.ini
Those values can be read from more than one location. You only show one location (and yes there is a phpinfo showing only one location but there are other elements in phpinfo hinting additional ini locations and to tell you the truth: the phpinfo does not show all inis).
So actually this depends on your configuration (which can greatly differ as you've got an open system) and the only thing we can say for sure is that you
a) edited the wrong file -or -
b) made a mistake while editing the right file.
To fix your issue, edit the right file.
To find the right file, learn about your systems PHP configuration.
To learn about your systems PHP configuration, start removing the ini and see what happens.
To learn about how it works in general - not specific to your system - you can easily consult the PHP manual:
Runtime Configuration Docs
Try to check if there is any syntax error in your php.ini, if there is any, it will not take the changes.
also make sure that your php.ini is writable
Or if you are on Linux (same will apply for windows, just different path), check the error log file with the command like this:
$ tail -n 100 /var/log/apache2/error.log
after restarting apache server
This will show you the line of the error and its cause in case of the syntax error in php.ini.
Check also "Scan this dir for additional .ini files" and "Additional .ini files parsed"

what happens if php.ini is missing?

What happens if php.ini is missing? Does PHP load with a default configuration? In phpinfo(), it says the configuration file path is /etc, however it also says Loaded Configuration File (none). I went into /etc, and noticed there is no php.ini, only php.ini.default. PHP is working though, so I'm guessing it must load with default settings. Can anybody confirm this for me?
PHP has what amounts to a php.ini compiled into it. The php.ini file on the system is there merely to override those pre-compiled defaults. If there's no php.ini, the compile-time values are in charge.
It does load default settings, yes.
if php.ini is missing , u can choose one of this files and rename it to php.ini => this will give u the same results
php.ini-development
php.ini-production
I wish this can help ;)

How do I include a php.ini file in another php.ini file?

How do I include a php.ini file in another php.ini file?
I don't think you can "include" .ini files from the main php.ini file.
One possible solution, though, might be to use this option on the configure line, when compiling PHP:
--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files
If this option is used at compile-time, PHP will look for every .ini file in this directory, in addition to the "normal" php.ini file.
I suppose this is what is used by Ubuntu, for instance, which uses a different .ini file for each downloaded extension, instead of modifying php.ini.
The path to the php.ini file is being defined with this option, on the configure line:
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
Still, it probably means you'll have to re-compile PHP -- which is not that hard, btw -- the hardest part being to get the dependencies you need.
And, here is a post on the internals# mailling-list that says the same thing as I do: config files and PHP_CONFIG_FILE_SCAN_DIR
One can also define the path in ~/.bashrc
export PHP_INI_SCAN_DIR=/usr/local/lib/php.d
I installed Memcached for php and wasn't sure how to make sure that its ini was included in my php.ini file, but as it turns out, it automatically is. You can validate what is being loaded by running php --ini.
php --ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File: (none)
Scan for additional .ini files in: /opt/local/var/db/php5
Additional .ini files parsed: /opt/local/var/db/php5/memcached.ini
EDIT: My answer was mistaken. This only works in .conf files, which is not the question asked. Better testing showed that it won't work in php.ini files, where include statement is ignored.
I just tested it on DebianĀ 9 (Stretch) with PHP-FPM. From some .conf file, use this syntax:
include=/path/to/special-php.ini
or even
include=/path/to/special-dir-full-of-conf-files/*.conf
as it is used in
/etc/php/7.0/fpm/php-fpm.conf
include=/etc/php/7.0/fpm/pool.d/*.conf
By the way, this will be most useful if you split your settings by topic, and or if you want a set for development and another one for production. Then you could do it the Debian/Apache style like
/etc/php/conf-available/
/etc/php/conf-enabled/
with symliks from the second to the other and an include to that one.
It seems you cannot include one ini file into another so it gets referenced and loaded. But you can set php up to load several files by telling it which folders to look into.
When using a FastCGI setup (possibly in FPM, too, though I don't know that for sure) you can export environment variables from within the PHP wrapper.
There you could do:
export PHP_INI_SCAN_DIR=/etc/php5/cgi/conf.d:/var/www/mydomain.net/etc
/var/www/mydomain.net/etc is just an example. It's the folder where you put your additional ini files into. It seems this can be a : separated list.
Use a phpinfo.php (file called arbitrarily containing only <?php phpinfo();), open the corresponding URL in your browser and check the list of directories that are parsed and the list of files that get loaded in the top area of it.
/etc/php5/cgi/conf.d should always be included (I guess because it was compiled into the PHP executable) and possibly not really be needed.
You can't. Read online pages:
The configuration file
SUMMARY: The configuration file
(php.ini) is read when PHP starts up.
For the server module versions of PHP,
this happens only once when the web
server is started. For the CGI and CLI
version, it happens on every
invocation.
.user.ini files
SUMMARY: 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']). Only INI
settings with the modes PHP_INI_PERDIR
and PHP_INI_USER will be recognized in
.user.ini-style INI files.
You could try to simulate it making use of the ini_set function. But as the "man page" indicates, not all ini options can be changed using ini_set. It's definitely a useful function, though.

Categories