Building a portable executable on Linux
As a DBA who prefers Linux/Unix, you might guess that I script most everything I do. Bash was my scripting language of choice, but honestly it has its limitations. Interacting with a database via a Bash script can be flimsy to say the least.
When I am not DBA’ing I am developing. Over the last couple of years I have come to know and love PHP. Most people think of PHP as a language used for building web applications/sites, and it is, but PHP also has a command line interface known as php-cli. Several weeks ago I thought to myself, “Why am I writing all this extra bash code when I could do this simply (and cleanly) with PHP?” So from this point forward I am abandoning Bash for PHP for command line scripting.
One positive for Bash on Linux, is that it already exists on the system. PHP may or may not. Even if PHP is there, it doesn’t have the necessary Oracle extension for connecting to an Oracle database. My system administrators would be offended if they knew this, but I turn to them as a last resort. I hate asking for their help. They are busy too and I prefer not to wait in them. With all that said, I choose to install PHP as myself and not as root. So on each system I:
Build PHP with Oracle:
- install oracle instant client
- unzip instant client
- unzip instant client sdk
- ln -s libclntsh.so.11.1 libclntsh.so
- build php
- unzip php
- ./configure –disable-all –without-sqlite3 –without-sqlite –without-pdo-sqlite –prefix=/opt/oracle/php/php –enable-mbstring –enable-cli –with-oci8=instantclient,/opt/oracle/php/instantclient_11_2 –enable-libxml –enable-simplexml
- make
- make install
I have lost count of the number of systems I script on, and I prefer to not go through the above process on all of them. So why not build a portable PHP executable?
After doing some digging, there are two players that have utilities to build portable executables on Linux/Unix. They are Statifier and Ermine. Being cheap, I thought I would give Statifier a shot. I won’t go into all the details, but part of building the executable with Statifier involved setting the randomize_va_space kernel parameter to 0. This is NOT an option on our systems. You might be thinking just set it to 0, build the executable, and set it back. That is not an option since it has to be 0 to even execute the statified executable.
So this leaves Ermine as the best option for me. Installation could not have been simpler.
Install Ermine
- Download the free trial from http://www.magicermine.com/trial.html
- chmod +x PROGRAM
Now the even easier part. If we want to verify that the php binary is currently static, cd to php/bin directory and type: ldd php. This will produce a list of dependent libraries for the php executable.
Build portable PHP executable
- From the directory that you extracted Ermine to
- ./ErminePro.i386 /path/to/php/bin/php –output php-static
Now run ldd on the php-static executable. It will return “not a dynamic executable”. I now have an executable that I can drop on all my Linux systems.
This is only a brief overview of the features of Ermine. For more information I would suggesting looking at the “Ermine Packagers Guide” at http://www.magicermine.com/docs/. There are more details for packaging PHP at that link.