Home > Development, Linux, RedHat > Finding dependencies for PHP applications

Finding dependencies for PHP applications

Blame and lies, contradictions arise
Blame and lies, contradictions arise
Nobody will change my way
Life betrays, but I keep on going
(Sepultura – Inner Self)

I’m a big fan of packaging systems and I pretty much tend to hate deploying unpackaged software. So, I tend to build native OS pacakges as often as I can. Packaging PHP applicatoins (like WordPress for example) is pretty much straightforward job. Only problem one may encounter is listing all software dependencies correctly. Here comes pci to the rescue!

So what is a ‘pci‘ – it’s part of the phpcompatinfo PHP module. The purpose of the module, and of ‘pci’ executable is to find out version and the extensions required for a piece of (PHP) code to run. Yeah, it’s that simple! So, lets try it, on CentOS 6 + EPEL offcourse:

# yum -y install php-pear-PHP-CompatInfo
# mkdir /tmp/pcitest
# echo "<?php phpinfo(); ?>" >> /tmp/pcitest/phpinfo.ph
# pci -d /tmp/pcitest
+-----------------------------+---------+---+------------+--------------------+
| Files                       | Version | C | Extensions | Constants/Tokens   |
+-----------------------------+---------+---+------------+--------------------+
| /tmp/pcitest/*              | 4.0.0   | 0 |            |                    |
+-----------------------------+---------+---+------------+--------------------+

As you can see, phpinfo() requires at least versoin 4.0.0 of PHP and doesn’t require any extension. Let’s run it now on some real project, like TeamPass:

# pci -d teampass > pci.log
# cat pci.log | cut -d'|' -f 5 | grep -v ^+ | sort | uniq | \
    sed 's/^ /Requires: php-/g'
Requires: php-           
Requires: php-bcmath     
Requires: php-ctype      
Requires: php-date       
Requires: php-Extensions 
Requires: php-filter     
Requires: php-gd         
Requires: php-hash       
Requires: php-json       
Requires: php-mbstring   
Requires: php-mysql      
Requires: php-mysqli     
Requires: php-openssl    
Requires: php-pcre       
Requires: php-pgsql      
Requires: php-session    
Requires: php-SimpleXML  
Requires: php-SPL        
Requires: php-xml

With two simple commands we can get output that can easily be copy/pasted and used used in rpm spec file. Enjoy building packages! INNER SELF!

Advertisements
  1. UX-admin
    October 2, 2015 at 7:49 am

    pci -d teampass | awk -F’|’ ‘$5 !~ /^+/ {sub(/^ /, “Requires: php-“, $5); print $5;}’ | sort -u

    -F’|’ sets the delimiter to a pipe…
    …5th will be acted upon only it if does not match ^+ regular expression ($5 ~! /^+/)…
    …and then the beginning space in the 5th field will be replaced with the “Requires: php-” string, and then printed to stdout…
    …which is then passed to the sort command, with -u removing any duplicates.

    So instead of redirecting to a temporary file, then spawning no less than seven different processes, all the work is performed by AWK and sort(1).

    “And look ma! No temporary files!”

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: