LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   which script determines which php.ini is included when PHPIniDir is unset? //using apache2 (https://www.linuxquestions.org/questions/linux-software-2/which-script-determines-which-php-ini-is-included-when-phpinidir-is-unset-using-apache2-4175598746/)

MrMeeSeeks 02-01-2017 02:35 PM

which script determines which php.ini is included when PHPIniDir is unset? //using apache2
 
So the internet exhaustively tells anyone who's interested, how to include the PHPIniDir-Directive in the apache-conf to change which php.ini is included on startup.
But I failed trying to just figure out where the ini is set/included in the first place, because that definitely shouldn't be said http.conf, since there is only a general include-php directive there as it stands and my ini is included all right.

Sorry for the stupid question, by the way.

Habitual 02-01-2017 03:38 PM

Have a look at section titled 3 Custom php.ini For Each Web Site and let us know!

Have a read of /etc/apache2/mods-enabled/php5.conf
Don't change a damn thing in it. :D

sundialsvcs 02-01-2017 04:56 PM

I actually came up with a very reliable strategy for doing this sort of thing, in my "straight CGI" legacy application, which I shamelessly "borrowed" from http://www.askapache.com/php/custom-...ps-and-tricks/.

The voodoo actually requires three Apache directives to cause a custom-script to be invoked:
Code:

# First, specify a custom action for php files.  (Individual "<VirtualHost>" entries can override this.)
AddHandler my-webapp-php  .php

# Direct each handler to the corresponding custom executable.  Must use the "Alias" here ...
Action  my-webapp-php  /frobozz-cgi/my-webapp-php.cgi    virtual

# This is the alias that must be used with the Action.  Equate it to a physical directory.
ScriptAlias /frobozz-cgi/ /my_script_directory/

Now, my-webapp-php.cgi must be an executable script that sets up the call like this:
Code:

#!/bin/sh

export BLAH=BLAHBLAH
export BLAHHUMBUG=SCROOGE

exec /usr/bin/php-cgi --php-ini /my_webapp/php.ini $PATH_TRANSLATED

So, as you can see, Apache first invokes my script, instead of PHP itself. This script sets up the environment and, via exec, replaces itself with an instance of PHP having the proper command-line parameter to select a php.ini file of my own choosing.

In this way, and no matter what the environment otherwise would have stated, the launch sequence of every PHP script in the application is placed under my control, including specification of the ini-file that is to be used.

MrMeeSeeks 02-01-2017 05:08 PM

Well the site you linked is about the same thing, isn't it? It describes the PHPIniDir-Directive, just in the context of Virtual Hosts. What I meant is: I never set this directive and there is none set by default in the httpd.conf, but Apache still knew which php.ini to include and that kind of bothers me.

I have php7 installed by the way, which seems to have kept out of /etc entirely. I've skimmed through anything that would resemble such a config file (find would find no php7.conf though), but found nothing enlightening.

Guess I'll have to live with the mystery for now.

MrMeeSeeks 02-01-2017 05:13 PM

Quote:

Originally Posted by sundialsvcs (Post 5663639)
I actually came up with a very reliable strategy for doing this sort of thing, in my "straight CGI" legacy application, which I shamelessly "borrowed" from http://www.askapache.com/php/custom-...ps-and-tricks/.

The voodoo actually requires three Apache directives to cause a custom-script to be invoked:
Code:

# First, specify a custom action for php files.  (Individual "<VirtualHost>" entries can override this.)
AddHandler my-webapp-php  .php

# Direct each handler to the corresponding custom executable.  Must use the "Alias" here ...
Action  my-webapp-php  /frobozz-cgi/my-webapp-php.cgi    virtual

# This is the alias that must be used with the Action.  Equate it to a physical directory.
ScriptAlias /frobozz-cgi/ /my_script_directory/

Now, my-webapp-php.cgi must be an executable script that sets up the call like this:
Code:

#!/bin/sh

export BLAH=BLAHBLAH
export BLAHHUMBUG=SCROOGE

exec /usr/bin/php-cgi --php-ini /my_webapp/php.ini $PATH_TRANSLATED

So, as you can see, Apache first invokes my script, instead of PHP itself. This script sets up the environment and, via exec, replaces itself with an instance of PHP having the proper command-line parameter to select a php.ini file of my own choosing.

In this way, and no matter what the environment otherwise would have stated, the launch sequence of every PHP script in the application is placed under my control, including specification of the ini-file that is to be used.

Well, that seems like a neat solution to a problem I currently don't have, but thanks a lot for sharing, I'll keep it for future reference.
I was actually asking out of sheer interest - the standard .ini is working just fine for my current needs, I just wondered how apache knows where to find it since it is not included via the directive in httpd.conf. So Apache must know through something that happened by default while either it or php was configured I guess, and now stores the information in some mystical place not for me to see.

norobro 02-01-2017 06:05 PM

As Habitual said, have a look in /etc/apache2/mods-enabled.

From my Debian box:
Code:

/etc/apache2$ ls -l mods-enabled/php*
lrwxrwxrwx 1 root root 29 Aug  1  2016 mods-enabled/php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Aug  1  2016 mods-enabled/php7.0.load -> ../mods-available/php7.0.load

/etc/apache2$ cat mods-available/php7.0.load
# Conflicts: php5
# Depends: mpm_prefork
LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so


Habitual 02-01-2017 06:06 PM

Quote:

Originally Posted by MrMeeSeeks (Post 5663651)
I just wondered how apache knows where to find it since it is not included via the directive in httpd.conf. So Apache must know through something that happened by default while either it or php was configured I guess, and now stores the information in some mystical place not for me to see.

/etc/php5/apache2/php.ini says right on the box:
Code:

; See the PHP docs for more specific information.
; http://php.net/configuration.file

More Specific information is what I'd call authoritative. :)

http://php.net/configuration.file

Distro specific docs in /usr/share/doc/php5-common/


All times are GMT -5. The time now is 07:55 AM.