Custom php.ini when executing php as shell script

I am running php as a shell script.

(Not sure if the "shell script" is correct. The file starts with #!/usr/bin/php)

This works great. But the MongoDB class does not load, since the correct php.ini (having extension=mongo.so) is not used.

How can i use php.ini?

Already tried #!/usr/bin/php -c /usr/local/lib/php.ini

But I still get the same error - Fatal error: Class 'Mongo' not found

What can be done?

+3
source share
5 answers

In this particular situation. I'd

php.ini - CLI. php.ini script XYZ ( )?

+3

php.ini , php. , .

, strace, , .

$ strace -o strace.log php --version
$ grep php.ini strace.log

Strace (), , -o

grep php.ini . , , , .

open("/usr/bin/php.ini", O_RDONLY)      = -1 ENOENT (No such file or directory)
open("/etc/php.ini", O_RDONLY)          = 3
lstat("/etc/php.ini", {st_mode=S_IFREG|0644, st_size=69105, ...}) = 0
+3

, . , php.ini.
, Apache,

/etc/php5/apache2/php.ini

, MongoDB = mongo.so

cron ini. ,

grep php.ini strace.log

@tomwrong

, "= 3", - php.ini, , ini "extension = mongo.so".

+2
source

Change the .bashrc located in your home directory and add the following line:

alias php='php -c /path-to-custom/php.ini'
+2
source

another option is to use a small sh shell, something like this below in myapp.sh, don't forget chmod + x on the script to run it

#!/usr/bin/env sh

SOMEVAR='Yea Baby!'

export SOMEVAR

php -c /path/to/my/custom/php.ini /path/to/my/old_script.php

with added bonus to the ability to set or override env vars pre-run

+1
source

Source: https://habr.com/ru/post/1783105/


All Articles