Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 12, 2024 03:43PM

Hello

Before I start with my problem, first of all:

Thanks for Wampserver and thanks to everyone who maintains the project. :-) I have been using it for several years as a local test and development platform for my phpBB extensions (freeware).

My question:

From now on I need this entry in the php.ini, which basically works as it should:

curl.cainfo = "g:\program files\wamp\bin\certificats\cacert.pem"

However, I use virtual hosts because I need different PHP versions for different phpBB versions. I also have a wide range of PHP versions installed, as I often have to test with older versions and this is exactly where the problem lies:

I need the specified PHP variable globally in all PHP versions, but having to make this entry in more than a dozen php.ini's is 1) very cumbersome and 2) would not be future-proof, as I also have to update the PHP versions regularly. Is there a way to set this globally so that it is used by all PHP versions? have already researched this problem, but have not found anything that helps me. One approach was to make an entry with php_value in the httpd-vhosts.conf, in my case:

php_value curl.cainfo "g:\programs\wamp\bin\certificats\cacert.pem"

However, this has no effect for me. Am I missing something, or is it not possible at all?

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 12, 2024 05:31PM

Hi,

Create an Apache variable in httpd.conf (there are already several), for example:
 Define CURLCAINFO G:/programs/wamp/bin/certificats/cacert.pem
This variable can then be accessed via ${CURLCAINFO} in other Apache files such as httpd-vhosts.conf via:
php_value curl.cainfo ${CURLCAINFO}

For your information, all Apache Define are in the file wamp64\bin\apache\apache2.4.62.1\wampdefineapache.conf

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 12, 2024 07:10PM

Good evening Dominique.

Interesting, that's a feature that I'm sure I'll still need, thanks for the information. :-) But the problem is that the php_value instruction doesn't work at all in httpd-vhosts.conf. This is what the relevant section looks like at the moment, which I tried to use:


<VirtualHost *:80>
	ServerName phpbb33
	DocumentRoot "g:/programme/wamp/www/forum33"
	<Directory  "g:/programme/wamp/www/forum33/">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		#Require local
		Require all granted
	</Directory>
	<IfModule fcgid_module>
		Define FCGIPHPVERSION "8.3.9"
		FcgidInitialEnv PHPRC ${PHPROOT}${FCGIPHPVERSION}
		<Files ~ "\.php$">
			Options +Indexes +Includes +FollowSymLinks +MultiViews +ExecCGI
			AddHandler fcgid-script .php
			FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
		</Files>
	</IfModule>
	php_value curl.cainfo "g:\programme\wamp\bin\certificats\cacert.pem"
</VirtualHost>

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 12, 2024 07:50PM

Hi,

In this case, php_value will modify the configuration of the PHP version used as an Apache module and not the configuration of PHP version 8.3.9 used in FCGI mode.

This may be possible in other ways, perhaps via user.ini files. See the PHP documentation :
user.ini files
Where a configuration setting may be set
How to change configuration settings

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 12, 2024 08:43PM

Quote

In this case, php_value will modify the configuration of the PHP version used as an Apache module and not the configuration of PHP version 8.3.9 used in FCGI mode.

Ah, okay.

I've just tried it with httpd.conf and .user.ini: no effect. In php.ini is currently the only method that works for me.

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 13, 2024 09:57AM

Hi,

I asked the question at Apache Lounge.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 13, 2024 02:04PM

Thank you, I'm excited to see if you find out anything.

In the meantime, I've also done some more research and when I look at this page and the explanation of INI_SYSTEM, only php.ini or httpd.conf come into question:

[www.php.net]

php.ini works perfectly, but httpd.conf doesn't work. However, I don't know exactly what the entry in httpd.conf would have to look like for it to work.

I'm also an application programmer, not a server specialist. My knowledge of Apache is only rudimentary, which is why I use Wampserver.

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 13, 2024 02:13PM

Hi,

> php.ini works perfectly, but httpd.conf doesn't work

Yes, it works, but only if you're using PHP as an Apache module, i.e. without having <IfModule fcgid_module>...</IfModule> in the VirtualHost, i.e. without using PHP as an FCGID module.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 13, 2024 02:44PM

Hello

Okay, but as far as I understand, I need FCGID if I want to use multiple web applications with different PHP versions in parallel? Because that is definitely a must for me.


edit: For setup I used add_vhost.php



Edited 1 time(s). Last edit at 09/13/2024 02:47PM by LukeWCS.

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 13, 2024 04:04PM

There's an answer from Apache Lounge :

It is possible to add a define parameter to the CGI interpreter.

For each VirtualHost, replace :
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe" .php
by
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe -d curl.cainfo=g:/programme/wamp/bin/certificats/cacert.pem" .php
 

Warning: no space around the equal sign and .php relegated to the end of the line and slash / not antislash \

If this doesn't work, I have a script that allows you to modify the php.ini files of all installed PHP versions.
But I'd prefer you to use the parameters on the wrapper rather than a hack.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons



Edited 1 time(s). Last edit at 09/13/2024 04:06PM by Otomatic.

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 13, 2024 04:34PM

Just tried it and... works perfectly! smiling smiley

For me, this is a good and practical solution and future-proof, without me having to constantly adjust lots of php.ini's.

I also thought about a PHP script for automatically adjusting all php.ini's, but I really only wanted to use that if there was no other option.

Thank you Dominique for your time and work!

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 13, 2024 04:47PM

Thanks to James Blond from Apache Lounge!
This is not really explained in the FCGID module documentation.
For FcgidWrapper, it is written:

Options for the command can be included using quotation marks surrounding the command and options.

You should already know that -d says it's an option that follows!

There may be several options, each introduced by -d
FcgidWrapper "${PHPROOT}${FCGIPHPVERSION}/php-cgi.exe -d option1 -d option2" .php

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 13, 2024 05:03PM

Quote

Thanks to James Blond from Apache Lounge!

Thank you James Blond. smiling smiley

Quote

There may be several options, each introduced by -d

hehe that's exactly what I tried next, to see if I could specify more than one parameter. grinning smiley

Very nice feature that I can certainly use with other PHP values.



Edited 1 time(s). Last edit at 09/13/2024 05:04PM by LukeWCS.

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 14, 2024 03:04PM

Hi,

Here's a little undocumented Wampserver trick for developers!

In the wampmanager.conf file, replace
LocalTest = "off"
by
LocalTest = "on"
then Right-click -> Refresh

At the bottom of the Left-Click menu, there's a new item: For local test only

This item launches the wamp64\scripts\test.php script, which you can create and modify as you see fit.

Here's the test.php script I wanted to propose if -d options didn't work:
<?php

require 'config.inc.php';
require 'wampserver.lib.php';

$search = ';curl.cainfo =';
$replace = 'curl.cainfo = "g:/programme/wamp/bin/certificats/cacert.pem"';

//Retrieve all installed PHP version numbers in an array
$list = listDir($c_phpVersionDir,'checkPhpConf','php',false);
//Creating absolute paths array for php.ini files
array_walk($list,function(&$value,$key)use($c_phpVersionDir){$value = $c_phpVersionDir.'/'.$value.'/php.ini';});
//Replacements in each php.ini file
foreach($list as $value) {
  $ini_file_contents = file_get_contents($value);
  $ini_file_contents = str_replace($search,$replace,$ini_file_contents,$count);
  if($count > 0) {
    file_put_contents($value,$ini_file_contents);
  }
}

?>

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 14, 2024 08:25PM

Good evening

Ah, thanks for this tip about the additional menu item. I already have it active and I'm sure I'll be using the feature pretty quickly. grinning smiley When updating Wampserver and/or PHP versions, there are recurring tasks that I can automate and link to this menu item.

And thank you for the script that you created specially, that would have been very convenient in combination with the additional menu item. smiling smiley

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: Otomatic (Moderator)
Date: September 15, 2024 10:18AM

Hi,

It's paradoxical that you and I haven't thought of the ABCs of searching for possible arguments to an executable simply by typing, in a command line, php-cgi.exe /? or php-cgi.exe -h winking smiley

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual hosts and global php_value
Posted by: LukeWCS (---.um25.pools.vodafone-ip.de)
Date: September 15, 2024 01:02PM

Hi

Hahaha that's true! grinning smiley

The problem with systems as complex as Wampserver is that you sometimes have very rare/exotic wishes or requirements that perhaps very few or even no one has had before. And then you may use terms in a search engine that don't really get you to your goal. That's exactly what happened to me. In recent years I've almost always been able to find a solution on Wampserver through research, but here I haven't found a solution even after several evenings. My approach in the initial post here was the best I had. I always try to find a solution myself first, but that's not always possible.

The ironic thing is that it was only after I spoke to you and you gave me James Blond's solution that I had the idea to look at the help for the CLI parameters and that's exactly where it's mentioned, including an example for max_execution_time.

[www.php.net]

I was far too focused on *.ini/*.conf, I didn't even think about CLI parameters, although I do use php.exe in the shell from time to time. winking smiley

Options: ReplyQuote


Sorry, only registered users may post in this forum.