How to get PHP version from inside an "opt mod"

sehh

Well-Known Member
Feb 11, 2006
579
6
168
Europe
I'm working on an EasyApache module ("opt mod") and I need to get the PHP version that EasyApache is about to install.

I need this to select the correct patch to install on top of PHP's source code.

Any help would be appreciated.

Thank you.
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
You can find the documentation for executing code during custom opt mod installs here by running:

Code:
/scripts/easyapache --perldoc
I don't believe that the PHP version is passed to the Easy::Apache object (haven't tested) so you'll have to find it via the perl command line (or maybe there's a module on CPAN you want to use for portability: The CPAN Search Site - search.cpan.org) like so:

Code:
'step'      => {
                   '0' => {
                       'name' => 'Frabnogizing Option',
                       'command' => sub {
                           my ($self) =  @_;
						   my @result = ();
						   my $success;
						
						   my $version_string = `php -v`;
						   my $version;
						   if( $version_string =~ /PHP ([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2})/ ){
						         $version = $1;
						   }
							

						   if ( $version ){
							  #apply patch based on version
						      $result[0] = 1;	#got PHP version and it is ok
						   }else{
						      $result[0] = 0;	#failed to get php version, do not continue
						   }
						   return 
                       },
                   },
               },
 

sehh

Well-Known Member
Feb 11, 2006
579
6
168
Europe
Dave,

Thank you for taking the time to reply, much appreciated.

I don't need the version of the existing PHP, but the version of the PHP that is about to be compiled by EasyApache.

I think I could "ls" the src directory and grep the version number from the name of the directory, since this is what I see:

Code:
# ls /home/cpeasyapache/src/ |grep '^php-'
php-5.4.19/
The path /home/cpeasyapache/src/ is where all the compilation happens, under that directory EasyApache uncompresses all the archives it needs, including PHP.

But I was looking for a proper way to do this, instead of a hack :)
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
Dave,

Thank you for taking the time to reply, much appreciated.

I don't need the version of the existing PHP, but the version of the PHP that is about to be compiled by EasyApache.

I think I could "ls" the src directory and grep the version number from the name of the directory, since this is what I see:
Ah, that makes more sense. Sorry for the confusion. You may want to dump out $self and see if it contains any configuration information.

Code:
use Data::Dumper ();
print STDERR Data::Dumper::Dumper($self);
The above will likely dump the contents of self to /usr/local/cpanel/logs/error_log (not tested).
 

sehh

Well-Known Member
Feb 11, 2006
579
6
168
Europe
Thanks for the suggestion, I tried to dump self and it came out to be total chaos. Instead I opted to "grep" the php directory name.

I'm nearly finished with my EasyApache module, once I've finished my tests I'll release it for others to play with.
 

Infopro

Well-Known Member
May 20, 2003
17,075
524
613
Pennsylvania
cPanel Access Level
Root Administrator
Twitter
Greetings, there has been some discussion about posting this sort of thing on the forums in recent months, but no decision has been made yet. In the meantime, I am to redirect all such posts to the AppCat instead:
cPanel App Catalog


At the time that new thread has been placed in moderation. I'd like to see if I can get a ruling on this once and for all today at some point if possible, but I cannot guarantee it will come today.

The issue is, we cannot support things like this on these forums, and you shouldn't be. Adding it to the AppCat, and linking to your own site for support is preferred.


I'll see what I can find out today.
 

sehh

Well-Known Member
Feb 11, 2006
579
6
168
Europe
No problem, I understand.

Although this is not a real application, it is more like a quick hack to fit my needs. It probably doesn't fit anywhere in the App Catalog.