php.ini not reflecting changes ever after server restart - php

I needed to change few values in php.ini file and after running phpinfo() within my application, found my php.ini file in below location
Configuration File (php.ini) Path /opt/php-5.6.30/lib
Loaded Configuration File /opt/php-5.6.30/lib/php.ini
Changed the values in above php.ini file followed by apache2 restart but they didn't reflect.
I ran php --ini command to see any other php.ini files and got following folders:
/etc/php/7.0/cli
/etc/php/7.0/apache2
/etc/php/7/0/fpm
so changed values in all of those php.ini files followed by apache2 and php7.0-fpm restart but to no effect.
I'm puzzled as my application's "loaded configuration file" is using php 5.6.30 which is in /opt/php-5.6.30 folder without any apache2 folder within and php-fpm points at /etc/php/7.0 folder.
None of those ini files followed by apache & php-fpm service restarts is actually reflecting my changes.
Any suggestions/pointers would be much appreciated.

I think the problem is that you are using different php versions for php-fpm (web), and cli. You should create test.php file, and run there phpinfo(). And check where loaded php.ini of web version is located. You should access test.php from web, like https://example.com/test.php

If you've made changes to your php.ini file and the changes are not being reflected, even after restarting your server, there are a few things you can try:
Check that you are editing the correct php.ini file: Make sure you are editing the correct php.ini file that your server is using. You can check which file your server is using by creating a PHP file with the following content:
<?php
phpinfo();
?>
Save the file to your server and open it in your browser. Look for the "Loaded Configuration File" directive in the output to determine the location of the php.ini file.
Check that you have permission to edit the php.ini file: Make sure that you have permission to edit the php.ini file. If you are not the owner of the file, you may need to use sudo to edit it.
Check for syntax errors: Make sure that there are no syntax errors in your php.ini file. You can check for syntax errors by running the following command:
php -c /path/to/php.ini -l
Replace /path/to/php.ini with the actual path to your php.ini file. If there are syntax errors, you will need to correct them before the changes can take effect.
Clear any opcode caches: If you have an opcode cache, such as APC or OPcache, you may need to clear it before the changes to the php.ini file take effect. You can usually clear the opcode cache by restarting your web server or by using the cache's built-in function.
Check that your changes are in the correct section: Make sure that your changes are in the correct section of the php.ini file. For example, if you are trying to change the max_execution_time directive, make sure that it is in the [PHP] section of the file.
Restart your web server: Finally, make sure to restart your web server after making changes to the php.ini file. Depending on your server configuration, you may need to restart both the web server and the PHP FPM process.

Related

Mac Localhost Not Reading php.ini or .user.ini files for PHP configuration

I would like to place a php.ini file in a localhost (MacOS Big Sur) site directory administrator/ to create a configuration:
auto_prepend_file="/Users/USER/Sites/SITE/administrator/library/script/function.php"
When I look at my phpinfo();, my php.ini file is not loaded and the function.php file is not prepended (looking at Additional .ini files parsed section). I also tried using my .user.ini file as well with no success. Lastly, if I used the Loaded Configuration File php.ini with the new configuration, it works fine. But this is not what I want. I would like to create multiple php.ini files and place them in the folder I need them in.
Every time I add a php.ini file or update it, I always restart apache. This is not the issue because I have change the Loaded Configuration File and restarted apache with success.
sudo apachectl start
sudo apachectl stop
Here are some screenshots of my configuration:
How do I enable php.ini to be parsed in any directory for that specific directory?

php.ini does not change values

I have a virtual machine with openSUSE Leap 42.3 and a LAMP stack.
Now I want to set up a CMS called TYPO3. The install tool tells me, that I should change following settings:
Low PHP script execution time
PHP max_input_vars is very low
I opened my /etc/php7/cli/php.ini and changed the values. But after restarting the Apache web server, and executing phpinfo();, nothing changes.
This is what phpinfo() tells me:
Configuration File (php.ini) Path /etc/php7/apache2 Loaded
Configuration File /etc/php7/apache2/php.ini Scan this directory for
additional .ini files /etc/php7/conf.d
Are my changes overridden? A system restart did not help.
The php.ini file in the /cli directory is for the command line interface (CLI). Those changes will not affect if the PHP interpreter is "called by Apache" (or other web servers) in PHP's default configuration. You have to adjust the apache2/php.ini file. This is also what your phpinfo() states ;)
Restart PHP and/or Apache (depending on the system you are using) and it should be done.

Why isn't Php not loading values from php.ini? [duplicate]

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

Opcache does not get enabled

I've installed Apache 2.4.x webserver on Ubuntu and also PHP5.5.x from sources. I go to php installation folder and do find . -name "opcache.so". Then, to php.ini (same as in phpinfo()), I add zend_extension=/php5/lib/php/extensions/no-debug-zts-x/opcache.so, and opcache.enable=On (or 1) and restart Apache with apachectl restart. Then I check phpinfo() but opcache does not get enabled! Please help.
I think a wrong php.ini file might be used, but in phpinfo() it shows the path to file which I do edit. When I change maximum upload filesize from 2M to 4M in the php.ini, and restart Apache, it does not get changed in phpinfo()
Turns out, after compilation PHP would look for the ini file in /usr/local/lib rather than where I installed it despite
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
To check it, you can run php --ini to see if the file has been read fine.
But now I'm seeing white screen when trying to load php files :)
Hope it helps.

Changes to upload_max_filesize in Ubuntu php.ini will not take effect

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

Categories