How does Virtualmin detect PHP versions?

15 posts / 0 new
Last post
#1 Sun, 07/27/2014 - 13:24
ReArmedHalo

How does Virtualmin detect PHP versions?

Hello,

Background:

  • Virtualmin Pro on CentOS 6.5 x64
  • I compile Apache and PHP on my systems
  • Using the following commands I also install PHP 5.4:
  • yum install centos-release-SCL yum install php54 php54-php-cli php54-php-mysql php54-php-gd

  • PHP is compiled with the following command:
  • LDFLAGS=-L/usr/include/mysql ./configure --with-config-file-path=/etc --sysconfdir=/etc --with-zlib --with-bz2 --enable-zip --with-openssl=/usr/local/ssl --with-mcrypt --with-mhash --with-curl --with-ldap --with-gd --with-jpeg-dir --with-png-dir --enable-ftp --enable-exif --with-freetype-dir --enable-calendar --enable-soap --enable-mbstring --with-libxml-dir=/usr/lib --enable-cgi --with-mm --with-pdo-mysql --with-mysqli --with-mysql --with-pear --enable-intl --with-gettext --enable-gd-native-ttf --with-gmp --with-iconv --enable-sockets --with-pspell --enable-fpm --with-kerberos --libdir=/usr/lib64 make && make install && cp /usr/local/bin/* /usr/bin/ -R -f

    I've tried installing PHP 5.4 by compiling it to a different directory in /etc (/etc/php54 I think it was) but Virtualmin is unable to detect my compiled version of 5.4. However, the SCL PHP 5.4 is detected.

    My question is does anyone know, or can provide some insight or even code sample of how Virtualmin finds and detects the PHP versions that are installed? Mainly I am curious as I am attempting to build a administration panel to help manage all my servers (DigitalOcean Droplets) and automate a bunch of tasks. (Like creating a new droplet, building and compiling php, apache etc) with the click of a form submit. I think it would be kind of cool if I could also make it tell me which droplets (virtual machines) have what in terms of PHP versions available and things like that.

    Thanks! :)

    Sun, 07/27/2014 - 19:43
    lp86

    Virtualmin looks for alternate PHPs under /opt/rh like "/opt/rh/php54/root/usr/bin/php"

    Mon, 07/28/2014 - 10:25 (Reply to #2)
    ReArmedHalo

    Ah, okay thank you for that.

    Mon, 09/08/2014 - 12:20
    ReArmedHalo

    Used the following to build php 5.6.0 on a DigitalOcean droplet running CentOS 7:
    [code]
    LDFLAGS=-L/usr/include/mysql ./configure --prefix=/opt/rh/php-5.6 --with-config-file-path=/opt/rh/php-5.6/root/etc --sysconfdir=/etc --with-zlib --with-bz2 --enable-zip --with-openssl=/usr/local/ssl --with-mcrypt --with-mhash --with-curl --with-gd --with-jpeg-dir --with-png-dir --enable-ftp --enable-exif --with-freetype-dir --enable-calendar --enable-soap --enable-mbstring --with-libxml-dir=/usr/lib --enable-cgi --with-mm --with-pdo-mysql --with-mysqli --with-mysql --with-pear --enable-intl --with-gettext --enable-gd-native-ttf --with-gmp --with-iconv --enable-sockets --with-pspell --enable-fpm --with-kerberos
    [/code]

    Copied the php.ini-development file from the source tar to /opt/rh/php-5.6/root/etc/php.ini (seemed during previous testing that the php.ini file had to be there for Virtualmin to use it, by use it I mean for it to be copied to the users home directory instead of defaulting to /etc/php.ini) and re-checked configuration in Virtualmin:
    [code]
    The following PHP versions are available : 5.4.16 (/bin/php-cgi)
    [/code]

    So it did not properly detect the version. Not exactly sure why yet. If anyone has any ideas, I'd love to hear them please. In the meantime, I'll keep working on this to see if I can narrow down the issue.

    [UPDATES]
    1) So I thought perhaps it was either the dash or periods in the path name, so I compiled php-5.5.16 to /opt/rh/php5516, it made no difference.

    2) I think I found out what the problem is. I can't be so specific with my --prefix. There is an all_possible_php_versions variable in the code that detects PHP versions. That variable is defined as the following:
    ./webmin/virtual-server/virtual-server-lib.pl:196:@all_possible_php_versions = (4, 5, 5.2, 5.3, 5.4, 5.5);
    Then their is a function called list_available_php_versions that takes each item in that variable, forms the paths /opt/rh/php$php_version/ ($php_version being one item, without the dots between the version numbers, from that array) and then checks around inside that folder for the appropriate php binaries. I moved my /opt/rh/php5516 to /opt/rh/php55 and re-checked the configuration again, and it was successfully detected! This works for me really. I had no need to really be that specific as I don't plan on having two of the same PHP 5.x.y versions installed, only one version for like php 5.5, 5.4 and 5.6. Speaking of 5.6, Due to this, it would seem that I am not able to use it until Virtualmin updates to support it. Little sad about that but that's okay I guess.

    I guess I should also mention why I am doing this the way I am. For a long time now, I've been compiling httpd and php and overwriting the system installed (via yum in my case) version with my compiled version. Adding httpd* and php* to the yum.conf exclude list to prevent updates. I have always felt like this was a sloppy "hack" if you will. So doing things to separate directories allows me to not need to mess with yum and can simply allow it to update the system packages as it pleases, hopefully without disrupting anything I have done with my compiled binaries.

    Fri, 07/31/2015 - 14:33
    colech

    ReArmedHalo above wrote... Speaking of 5.6, Due to this, it would seem that I am not able to use it until Virtualmin updates to support it. Little sad about that but that's okay I guess. Can anyone tell me if it is even possible to run PHP 5.6 in Virtualmin now?

    Fri, 07/31/2015 - 14:42 (Reply to #5)
    ReArmedHalo

    Yes it is. Once installed virtualmin should detect it no problem now.

    Fri, 07/31/2015 - 15:02
    colech

    ### THE PROBLEM

    I'm using CentOS 7. I installed rh-php56 from the rhscl repo and was having trouble getting it to be recognized but I read more carefully your that you wrote ReArmedHalo... I moved my /opt/rh/php5516 to /opt/rh/php55 and re-checked the configuration again, and it was successfully detected! ### FIX #1 (this now lets Virtualmin see php56)

    I looked and saw that my PHP 5.6 was installed as /opt/rh/rh-php56 so I created a link php56 that pointed to rh-php56.

    ### FIX #2 (is this one necessary?)

    When I tried to run scl enable php56 bash it failed so in the directory /etc/scl/conf I also create another link php56 that pointed to rh-php56 and was then able to run scl enable php56 bash in addition to the one I already added scl enable rh-php56 bash.

    Fri, 07/31/2015 - 15:18 (Reply to #7)
    ReArmedHalo

    I'm not sure about using the SCL command. To be honest I don't even know what it does. I'm assuming you don't need to use it as I haven't and things have been working.

    Also just to clarify, are you still requiring assistance or did you sort out the issue? I wasn't too sure. :)

    Fri, 07/31/2015 - 18:09
    colech

    Hello again ReArmedHalo. Yes my questions are all answered but not until after you wrote the last reply.

    I now at least mostly know what scl enable php55 does. After running it, which php responds /opt/rh/php55/root/usr/bin/php instead of the default /usr/bin/php. So it appears that changes command line php to use a specific version by default if there's more than one version installed. However when I log back into the bash again later it doesn't save that setting. After searching a bit I found that it needs to be included in ~/.bashrc so it gets updated each time a new bash instance is initiated.

    Here's a simple little script thing that I used and entered at the end of my ~/.bashrc file that I found here (https://plus.google.com/115875830338788300419/posts/5bTJMBoXsai). I also found a very similar thing on the Red Hat developer blog (http://developerblog.redhat.com/2014/03/19/permanently-enable-a-software-collection/.

    # ------------------------------------------------------------------
    # Define functions to enable SCLs for current session.
    # ------------------------------------------------------------------
    scl_enable() {
        if [[ $X_SCLS != *$1* ]]; then
            . /opt/rh/$1/enable
            export X_SCLS="$1 $X_SCLS"
        fi
    }

    scl_show_enabled() {
        echo "Using Software Collections:"
        echo -e "  ${X_SCLS// /\n  }"
    }

    # -----------------------------------------------------------------
    # Enable SCLs, display list for user.
    # -----------------------------------------------------------------
    scl_enable php55
    Fri, 09/25/2015 - 02:25
    nibb

    I can confirm that indeed Virtualmin does not detect PHP 5.6 which gets installed under:

    /opt/rh/rh-php56

    It does detect 5.5 fine under: /opt/rh/php55

    This maybe should be addressed in a feature release.

    Fri, 09/25/2015 - 09:47 (Reply to #10)
    andreychek

    Howdy,

    Try making a symlink at "/opt/rh/php56", which points to your "/opt/rh/rh-php56" directory, and see if that gets detected at that point.

    -Eric

    Fri, 10/16/2015 - 16:54 (Reply to #11)
    nibb

    I know how to make it work. I'm saying this is a bug in Virtualmin as it should detect 5.6 like it does with previous versions.

    Fri, 10/16/2015 - 20:01
    andreychek

    I'll review that as I write up this documentation -- it's likely that we can use a symlink as temporary workaround, which we'll include in the write up. I have a suspicion that the path used by the newer PHP version is slightly different than where Virtualmin is looking.

    -Eric

    Tue, 02/16/2016 - 08:49
    08solsticegxp

    Virtualmin 5.0.gpl is working without the need for making a symlink. I used the following guide to use Software Collections (SCL): https://www.softwarecollections.org/en/scls/rhscl/rh-php56/

    You can see all the software collections that are available here: https://www.softwarecollections.org/en/scls/?page=1

    Fri, 12/15/2017 - 08:51
    isbagsdotru

    more detail: https://github.com/virtualmin/virtualmin-gpl/blob/master/php-lib.pl 936 ----- 954

    if ($nodotv ne $v) {
    # For a version like 5.4, check for binaries like php54 and
    # /opt/rh/php54/root/usr/bin/php
    $phpn ||= &has_command("php$nodotv-cgi") ||
      &has_command("php-cgi$nodotv") ||
      &has_command("/opt/rh/php$nodotv/root/usr/bin/php-cgi") ||
      &has_command("/opt/rh/rh-php$nodotv/root/usr/bin/php-cgi") ||
      &has_command("/opt/atomic/atomic-php$nodotv/root/usr/bin/php-cgi") ||
      &has_command("/opt/atomic/atomic-php$nodotv/root/usr/bin/php") ||
      &has_command("/opt/rh/php$nodotv/bin/php-cgi") ||
      &has_command("/opt/remi/php$nodotv/root/usr/bin/php-cgi") ||
      &has_command("php$nodotv") ||
      &has_command("/opt/rh/php$nodotv/root/usr/bin/php");
      &has_command("/opt/rh/rh-php$nodotv/root/usr/bin/php");
      &has_command("/opt/rh/php$nodotv/bin/php") ||
      &has_command(glob("/opt/phpfarm/inst/bin/php-cgi-$v.*"));
    }
    $php_command_for_version_cache{$v} = $phpn;
    }

    just

    ln -sv /usr/local/php56/bin/ /opt/rh/php56/bin

    +++++++++++++++++++++++

    /opt/rh/php56/bin' ->/usr/local/php56/bin/'

    now PHP versions 5.6.32, 7.0.10

    isbags.ru