Edit File: findphpversion
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - findphpversion Copyright 2014 cPanel, Inc. # All rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited use strict; use warnings; use Cpanel::ConfigFiles::Apache (); use Cpanel::HttpUtils::Version (); use Cpanel::SafeRun::Simple (); use Cpanel::SafeFile (); use Cpanel::Logger (); use Getopt::Long (); my $logger = Cpanel::Logger->new(); Getopt::Long::GetOptions( 'force' => \my $force, ); my $apacheconf = Cpanel::ConfigFiles::Apache->new(); my $usebin = 0; my $phpso = ''; my $sl = Cpanel::SafeFile::safeopen( \*APC, $apacheconf->file_conf() ); if ( !$sl ) { $logger->die( 'Could not read from ' . $apacheconf->file_conf() ); } while (<APC>) { next if (/^#/); if (/(libphp\S+)/) { $phpso = $1; last(); } } my $binphp = '/usr/local/bin/php'; # if it ever becomes so it could be other places use a find function Cpanel::SafeFile::safeclose( \*APC, $sl ); if ( $phpso !~ /libphp\d+\.so/ && -e $binphp ) { $usebin = 1; } my $so_dir = Cpanel::HttpUtils::Version::get_current_apache_version_key() eq '1' ? 'libexec' : 'modules'; my ( $phpsosize, $phpsomtime ) = ( stat( $apacheconf->dir_base() . "/$so_dir/$phpso" ) )[ 7, 9 ]; my ( $phpbinsize, $phpbinmtime ) = ( stat $binphp )[ 7, 9 ]; my ( $phpverfilesize, $phpverfilemtime ) = ( stat( $apacheconf->dir_conf() . '/php.version' ) )[ 7, 9 ]; my $now = time(); if ( !$force && defined $phpverfilesize && defined $phpverfilemtime && $phpverfilesize > 0 && $phpverfilemtime > ( $phpbinmtime + 86400 ) && $phpverfilemtime > ( $phpsomtime + 86400 ) && $phpverfilemtime <= $now ) { print "PHP version file is up to date\n"; exit; } my $phpv = ''; if ($usebin) { $phpv = Cpanel::SafeRun::Simple::saferun( $binphp, '-v' ); $phpv =~ /^PHP[\s\t]+(\S+)/; $phpv = $1; } else { if ( open( my $so_bin_fh, '<', $apacheconf->dir_base() . "/$so_dir/$phpso" ) ) { while ( readline($so_bin_fh) ) { if (/X-Powered-By:\s*[HP\/]*([\d+\.]*)/) { $phpv = $1; last; } } close($so_bin_fh); } } if ( open( my $phpv_fh, '>', $apacheconf->dir_conf() . '/php.version' ) ) { print {$phpv_fh} $phpv; close($phpv_fh); } print "PHP version file has been updated to $phpv\n"; # We don't call exec here because build_global_cache returns 141 and maintenance # doesn't like that. system '/usr/local/cpanel/bin/build_global_cache'; exit 0;