3

I am writing a script that requires me to get all php configuration. But I stumble an issue and inconsistencies when I run the ini_get_all() in the browser and using php5-cli. Here is my code snippet:

$confiq = ini_get_all();
echo $config['memory_limit']['local_value'];

It return 128M when I run using browsers, but it return -1 when I run using php5-cli from the command line

EDIT: It turned out they are using two different php.ini files. I checked the cli .ini with php --ini command. Now I need to figure out how to change the location for .ini file for cli

EDIT: For the easy hack, I created symbolic links to the apache2 php.ini to make sure both using the same php.ini.

7
  • 1
    check if both are using same ini file Commented Dec 21, 2015 at 7:27
  • 1
    easiest. just remove (backup) the cli ini and put a symbolic link to the ini you require. Commented Dec 21, 2015 at 7:34
  • @bansi: Yeah. I believe it will work that way. Not sure best practice or not though. Not really familiar with php. Commented Dec 21, 2015 at 7:37
  • not sure why you want this. you can use also CURL to get output of the real PHP url in your script. by that way you can altogether avoid cli Commented Dec 21, 2015 at 7:43
  • 1
    then you can CURL to the local server also instead of cli, I would suggest that because it is what the exact config your web server will be using. Commented Dec 21, 2015 at 8:10

1 Answer 1

2

There are two different php.ini files.

/etc/php5/apache2/php.ini for web and /etc/php5/cli/php.ini for command line.

You need to edit corresponding ini file according to the context. If you need the same ini value in both cli and web, obviously you need to edit both. Also don't forget to restart apache (service apache2 restart) after editing ini files to see the changes.

Sign up to request clarification or add additional context in comments.

1 Comment

i think Systemd has taken over SysVinit +1 for solving tha actual problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.