Configure php version in httpd-vhosts.conf (Virtual Host)


  • | 3469 points

    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:

    vhost1.me == 5.6.1
    vhost2.me == 7.2
    vhost3.me == 7.4
    vhost4.me == 8.2

    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:

    <Directory "C:\laragon\my_old_project1">
    <FilesMatch ".php$">
    SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
    </Directory>

    <Directory "C:\laragon\my_old_project2">
    <FilesMatch ".php$">
    SetHandler application/x-httpd-php56-cgi
    </FilesMatch>
    </Directory>

    but I can't get it to work ... mainly this I can't find:

    SetEnv PHPRC "\path\to\xampp\php"


  • | 3469 points

    I have already solved it, as follows:

    Following this post from the site in English to XAMPP:
    https://stackoverflow.com/a/49586592/4717133

    And My Spanish POST:
    https://es.stackoverflow.com/a/432920/46896

    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\php ewhere we place them, we must place ourselves a friendly name such as: \php70\ o \php72\ o \php74\ whatever the scenario; Very important we must verify that each version has the file php-cgi.exe since some old versions of php did not incorporate it; and this is a requirement.

    Step 2: Configure php.ini

    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.ini-development to php.ini and 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.conf for 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-enabled which 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:

    Original:

    <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>
    

    Modified:

    <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 SetHandler will 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
    header

    no need to define, modify or use the runtime environment variable:

    SetEnv PHPRC "\\ruta\\a\\php\\"
    

    kdsjgkjgf


  • | 5 points

    Thanks @arcanisgk! 🍻


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.