%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /scripts/
Upload File :
Create Path :
Current File : //scripts/findphpversion

#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/findphpversion                  Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package scripts::findphpversion;

use strict;
use warnings;
use Cpanel::ProgLang::Conf ();
use Cpanel::PackMan        ();
use Cpanel::ConfigFiles::Apache 'apache_paths_facade';    # see POD for import specifics
use Cpanel::Services::Installed ();
use Cpanel::ServerTasks         ();

exit( run(@ARGV) // 0 ) unless caller;

sub run {
    if ( !Cpanel::Services::Installed::service_is_installed('httpd') ) {
        print "httpd is not present on this system, exiting …\n";
        return 0;    # exit value not boolean of success/failure
    }

    my $default_php_pkg = Cpanel::ProgLang::Conf->new( type => "php" )->get_system_default_package();
    my $default_php_ver = "";
    my $default_php_hr  = $default_php_pkg ? Cpanel::PackMan->instance->pkg_hr($default_php_pkg) : undef;

    if ( !$default_php_pkg ) {
        warn "You do not have a default PHP set.\n";
    }

    if ($default_php_hr) {
        if ( !$default_php_hr->{version_installed} ) {
            warn "Your default PHP, $default_php_pkg, is not installed.\n";
        }
        else {
            $default_php_ver = $default_php_hr->{version};
        }
    }

    my $php_dot_version_file = apache_paths_facade->dir_conf() . '/php.version';
    if ( open( my $phpv_fh, '>', $php_dot_version_file ) ) {
        print {$phpv_fh} $default_php_ver;
        close($phpv_fh);
    }
    else {
        warn "Could not open “$php_dot_version_file”: $!\n";
        return 1;    # exit value not boolean of success/failure
    }

    $default_php_ver ||= 'nothing';
    print "PHP version file has been updated to $default_php_ver\n";

    # We don't call exec here because build_global_cache returns 141 and maintenance
    # doesn't like that.
    Cpanel::ServerTasks::schedule_task( ['CpDBTasks'], 5, 'build_global_cache' );
    return 0;    # exit value not boolean of success/failure
}

Zerion Mini Shell 1.0