Configure php version in httpd-vhosts.conf (Virtual Host)
hi, is there any way to configure laragon so that by configuring virtual hosts; can run more than one version of php at the same time, for example:
ignoring the option that can be changed with a click. I need to see the same development with two versions of php running at the same time since; In 5.6.1 I have an api and in 7.2 and 7.4 a development that consumes it and I am migrating these last two to 8.0
I have seen file settings httpd-vhosts.conf:
but I can't get it to work ... mainly this I can't find:
SetEnv PHPRC "\path\to\xampp\php"
I have already solved it, as follows:
Following this post from the site in English to XAMPP:
And My Spanish POST:
With some changes to make it work on Laragon.
The PHP NTS (non thread safe) versions are NOT compatible with Laragon.
Step 1: Download PHP
Download the versions of PHP that we are going to use, and unzip them and take them to the php directory in Laragon:
C:\laragon\bin\phpewhere we place them, we must place ourselves a friendly name such as:
\php74\whatever the scenario; Very important we must verify that each version has the file
php-cgi.exesince some old versions of php did not incorporate it; and this is a requirement.
Step 2: Configure
In each version of php that we will use we must go to the file
C:\laragon\bin\php\php##\php.ini(where ## is the version of php) in a code or text editor. If the file does not exist, copy
php.iniand open it. Then we will find and uncomment the following line:
extension_dir = "ext"
and we will modify it:
extension_dir = "C:/laragon/bin/php/php72/ext"
with this we will make sure that php points to the correct directory of its extensions.
Step 3: Configure apache
go directly to the apache configuration directory:
C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\conf(it may vary depending on the version of apache used) and open with a code or text editor the file
httpd.conffor each version of php that we want to use we must create an http alias and execute the corresponding php-cgi, this must be placed at the end of the file:
# Example for php 7.2: ScriptAlias /php72 "C:/laragon/bin/php/php72" Action application/x-httpd-php72-cgi /php72/php-cgi.exe <Directory "C:/laragon/bin/php/php72"> AllowOverride None Options None Require all denied <Files "php-cgi.exe"> Require all granted </Files> </Directory> # Example for php 7.4: ScriptAlias /php74 "C:/laragon/bin/php/php74" Action application/x-httpd-php74-cgi /php74/php-cgi.exe <Directory "C:/laragon/bin/php/php74"> AllowOverride None Options None Require all denied <Files "php-cgi.exe"> Require all granted </Files> </Directory>
Note: You can add more versions of PHP to your Paragon installation by following steps 1-3 if you wish.
Step 4: Configure Virtual Host
We must go to the directory:
C:\laragon\etc\apache2\sites-enabledwhich is the place where Laragon has the Virtual Host configuration files; Depending on which projects we have, we must open each configuration file with a code or text editor:
<VirtualHost *:80> DocumentRoot "C:/laragon/www/prueba/" ServerName prueba.me ServerAlias *.prueba.me <Directory "C:/laragon/www/prueba/"> AllowOverride All Require all granted </Directory> </VirtualHost>
<VirtualHost *:80> DocumentRoot "C:/laragon/www/prueba/" ServerName prueba.me ServerAlias *.prueba.me <Directory "C:/laragon/www/prueba/"> AllowOverride All Require all granted </Directory> <FilesMatch "\.php$"> SetHandler application/x-httpd-php72-cgi #SetHandler application/x-httpd-php74-cgi </FilesMatch> </VirtualHost>
where the defined
SetHandlerwill refer to the Alias to use.
and We finish by restarting the web services or the computer.
I did not find or get the error:
Update for Error: malformed header from script 'php-cgi.exe': Bad
no need to define, modify or use the runtime environment variable:
SetEnv PHPRC "\\ruta\\a\\php\\"
Thanks @arcanisgk! 🍻