[Tutorial] How to auto change Apache version after changing PHP version

  • administrators
    | 131258 points

    Create this file trigger-php.bat in usr\bin:


    php trigger.php %PHP_VERSION% %APACHE_VERSION%

    You can access PHP_VERSION and APACHE_VERSION through $argv in trigger.php in usr\bin:


        # YOUR CODE HERE

    In you code, you can download correspond Apache version from http://www.apachelounge.com/download/ and extract it to bin\apache

  • | 3254 points

    @leokhoa This may be an obvious question, but how do I change the Apache version inside of trigger.php? I understand that $argv will look something like this...

    array(2) {
      [0]=> "trigger.php"
      [1]=> "php-7.2.8-Win32-VC15-x64" // %PHP_VERSION%
      [2]=> "httpd-2.4.27-win64-VC14" // %APACHE_VERSION%

    ...but how can I use that to tell Laragon to change the active Apache version (if applicable). I'm fine parsing the strings to get VC15 and VC14 out of them, but how would I tell Larago to change to, say, Apache httpd-2.4.34-win64-VC15? I'm only asking about the Laragon command. I'm good with the surrounding code needed.

    Thanks again!

  • administrators
    | 131258 points

    @pfaciana : You can change it in usr\laragon.ini.

  • | 997 points

    I don't quite understand this setup.

    I get that /usr/bin/trigger-php.bat when run will call a new PHP process of /usr/bin/trigger.php and will have the current PHP & Apache versions available.

    But like @pfaciana I don't see how we use this to change the active version of Apache based on the selected version of PHP.

    Based on the title of this page I would have thought when I install multiple PHP versions and change from one to another that also required a change in Apache version it would auto install and tell Laragon to switch then restart Apache.

    Currently, we have to stop Apache, change PHP version which gives warning, then change apache version to match, then restart apache. I thought this would have fixed that so we could just change PHP versions and Laragon would switch to the correct Apache version.

    Or are we supposed to use the trigger.php file to browse up one directory and fopen frwite the laragon.ini file directly?

    Could you provide us a complete sample of how you are envisioning it being used, or at least a complete conceptual map so we can write the rest ourselves?

  • | 3254 points

    Yes, that is how I read it. I'm still working on trying to integrate Laragon into my existing setup, but with how busy I am, it's just not a top priority at the moment, so I have not had a chance to try it out it. But I was thinking of just having a lookup table in the trigger.php which used the VC of the PHP version to find the full string of the matching Apache version, then fopen laragon.ini , parse it and replace the [apache] Version. However, this instance would be on a Windows machine and I have not looked into permissions. I guess I could look into having trigger-php.bat do it as well, just I haven't had time to look into it at the moment.

  • | 289 points


    I've written this (you may have to change the apacheVersion variable according to yours):

    # Get PHP VC version
    preg_match('/VC[0-9]{2}/', $argv[1], $matches);
    $apacheVersion = '';
    switch ($matches[0]) {
        case 'VC14':
            $apacheVersion = 'httpd-2.4.27-win64-VC14';
        case 'VC15':
            $apacheVersion = 'httpd-2.4.35-win64-VC15';
        case 'VC11':
            $apacheVersion = 'httpd-2.4.35-win64-VC11';
            throw new Exception("UNSUPPORTED VC VERSION {$matches[0]}");
    # Get apache line and replace it
    $laragonIniPath = '../laragon.ini';
    $laragonIni = file_get_contents($laragonIniPath);
    file_put_contents($laragonIniPath, preg_replace('/(Version=)httpd-(.*)[0-9]{2}/i', '$1'.$apacheVersion, $laragonIni));
    $laragonExe = realpath('../../laragon.exe');
    exec($laragonExe . " reload apache");

    It properly writes into laragon.ini file the correct version, but it does not change it on Laragon...
    There is online one command available in cli to reload apache or nginx, but not to really switch an Apache version.
    Any help would be useful, thanks.

Log in to reply

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