The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'cPanel Developers' started by sehh, Aug 27, 2013.

  1. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    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.
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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 
                           },
                       },
                   },
    
     
  3. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    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 :)
     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    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).
     
  5. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    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.
     
  6. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Europe
  7. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,453
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    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.
     
  8. sehh

    sehh Well-Known Member

    Joined:
    Feb 11, 2006
    Messages:
    579
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    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.
     
  9. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,453
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    An update, the Workarounds forum is the best place for that thread, it's been moved. Similar threads will be placed there from now on as well.

    Thanks!
     
Loading...

Share This Page