12

When I make any changes in php.ini located in /usr/local/lib on centos, the changes don't appear to be applied, for example, when I clear all the content of php.ini and restart Apache everything works fine...

I searched for php.ini and it is in one place in system... what's the problem? How can I fix this?

Bryan
  • 7,538
  • 15
  • 68
  • 92
Fcoder
  • 341
  • 1
  • 4
  • 8

7 Answers7

13

if you're unsure what php.ini is being used, create a new file in your webfolder, name it phpinfo.php for example , with the following content

<?php
phpinfo();
?>

then open the url in your browser (http://www.example.com/phpinfo.php). it will show the path to the php.ini being used.

when you have identified the correct file, make your desired changes, and be sure to remove the leading ; in case there is one to activate the setting.

restart apache and reload the phpinfo page, your changed setting should now show up. if it doesn't, make sure you don't have a .htaccess file in your webroot that overrides php settings.

Gryphius
  • 2,710
  • 1
  • 18
  • 19
10

You may want to read these threads:

hints:

  1. What is "Loaded Configuration File" in php_info output? -> check that you edit the correct ini-file.
  2. check for multiple occurences of your setting in the same file.
  3. Gryphius´s hint is not bad either: Uncomment the setting! (remove the leading ";")
  4. Check permissions on the ini file. The web server and php-cgi/php-fpm need read access.
  5. php 5 and later: Do not only restart the web server, but also the php-fpm service before testing.
Titus
  • 261
  • 3
  • 7
  • I just switched to fast-cgi and restarting fpm did the trick, thanks. – Dave May 16 '19 at 07:16
  • 5
    Yes point 5 is the unusual step. Thanks. – Tibor Nagy Nov 10 '19 at 21:22
  • Point 5 was the solution for me as well ! I tried everything else on my own, and noticed that changes only take effect after a full reboot. Just wasn't sure which service needs to be restarted to take effect! Thank you – konung Dec 29 '20 at 18:32
  • On Amazon linux, restarted both `httpd` (apache) and `php-fpm` and still no effect. `php_info` says `/etc/php.ini` is the loaded config file. I've changed it, deleted it, no effect. Finally, I used "grep -lr 'display_errors'" to see if the directive was contained anywhere else. Found it in `/etc/php-fpm.d/www.conf`. As such: `php_flag[display_errors] = on`. Commented that line, restarted php-fpm (no need to restart apache, apparently), and finally my errors are not being shown to the world. – Buttle Butkus Jan 19 '21 at 01:55
2

I found a very blatant error in my php.ini file which caused this very symptom, eg. some php.ini settings did not take effect..

As of php7.0, the # character is not a valid comment starter. Only ; is accepted. But still many editors, for example vim, show characters after "#" as comments so you may not recognise that a certain part of the php.ini file is not an ignorable comment.

In my case, the php.ini filed contained this:

# ""
max_input_vars = 3000

The max_input_vars = 3000 did not take effect because the previous line is not a comment. It has some side-effect which causes my next line to be ignored.

Changing it to

; ""
max_input_vars = 3000

solved the problem.

1

If you are using apache you should know there are 2 ini files:

/etc/php/7.4/apache2/php.ini

and

/etc/php/7.4/cli/php.ini

You should change the one in /etc/php/7.4/apache2/php.ini

replace 7.4 with your php version

Ali Seyfi
  • 111
  • 3
1

Follow this:

Create a file inside your webroot naming it whatever you want. I usually prefer x.php

 # vim x.php

The contents of the file should be this:

<?php
phpinfo();
?>

Now open this file in your browser like this:

http://server_ip/x.php

This will show you the location of the php.ini your apache is using. Edit that php.ini and it will work.

Napster_X
  • 3,333
  • 16
  • 20
  • i do this an this is output: Configuration File (php.ini) Path /usr/local/lib Loaded Configuration File /usr/local/lib/php.ini – Fcoder Jan 13 '13 at 14:29
  • That means you are using this file only. Any changes to this file will be reflected in Apache. You can test the same with the same URL. Make some change in some variable in this php.ini, and that will be reflected in x.php file in browser. – Napster_X Jan 13 '13 at 14:42
0

you might have php.ini file in your webroot.

jahil
  • 121
  • 1
0

cannot comment here yet, but: Does it work if you keep the changes and restart Apache?

If so, the reason is probably that PHP runs as an Apache module.
If you want changes to have effect without restarting the web server, use php-cgi instead.

This page explains installation and configuration; search the page for "as an Apache Module" or for "PHP 5 as a CGI Binary".

Titus
  • 261
  • 3
  • 7