iEFdev

Code, Computers & Random Junk

Custom Version Numbers in PHP

Sometimes it can be good to change the version number in PHP, for various reasons. This is a small “howto” on how to do that.

Now and then you see PHP version numbers in the head of phpinfo() pages like:

  • PHP Version 5.6.14-foo.bar3-etc.

Most likely it is because it’s another distribution, often like when coming from a certain Linux dist, or someone made a pre-made/modified version.

Now… It’s not really necessary, nor useful, when setting up your local environment else than it could be “cool”(ish), &/or you learn something, or in my case - I run 2 PHP versions side-by-side. So in a way to separate them (exept the version number) I’ve added a suffix to each version. What’s in the code is the: PHP_EXTRA_VERSION.

I (still) use PHP 5.4 to keep old work and files running. That one is set up as an Apache module: mod_php. And then I have PHP 5.6 as my main PHP version. Since both can’t run on the same server (as a module) - my 5.6 version is setup with FPM/FastCGI. Works great. The xtra versions I’ve added are: -mod (as in module) for 5.4, and -zpm1 for 5.6, and have had that since my first dual PHP setup.

Anyway… Here’s how I change it.

Files to change

There are 3 files to edit before you compile the source. (Line numbers and version are from 5.6.14).

php-x.x.xx/

  • configure (~ L3676)
  • configure.in (~ L123)

In both files, look for:

PHP_EXTRA_VERSION=""

And put in your xtra version:

PHP_EXTRA_VERSION="-zpm"
  • main/php_version.h

There are two lines here:

#define PHP_EXTRA_VERSION ""
#define PHP_VERSION "5.6.14"

Change into:

#define PHP_EXTRA_VERSION "-zpm"
#define PHP_VERSION "5.6.14-zpm"

That’s all! +1

This is how it looks like:

Terminal

Instead of editing the files, you could use sed to do the job. It would be something like this:

$ sed -i '/^PHP_EXTRA_VERSION/s/"$/-zpm"/' configure
$ sed -i '/^PHP_EXTRA_VERSION/s/"$/-zpm"/' configure.in
$ sed -i '/PHP_EXTRA_VERSION/s/""/"-zpm"/' main/php_version.h
$ sed -i '/PHP_VERSION "/s/"$/-zpm"/' main/php_version.h

First time(s)… Verify the changes to make sure it went fine.

Script

Made a small script of it.

php-vers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
#
# /usr/local/xbin
#
# Description: Setting PHP_EXTRA_VERSION
#

# check input of $1
_base=$(basename $0);
if [ $# != 1 ] || [[ -z $1 ]]; then
  cat <<INFO
 :: Usage:  $_base <string>
            $_base "-foo"
INFO
  exit 1;
fi

_append="$1";

sed -i "/^PHP_EXTRA_VERSION/s/\"$/${_append}\"/" configure;
sed -i "/^PHP_EXTRA_VERSION/s/\"$/${_append}\"/" configure.in;
sed -i "/PHP_EXTRA_VERSION/s/\"\"/\"${_append}\"/" main/php_version.h;
sed -i "/PHP_VERSION \"/s/\"$/${_append}\"/" main/php_version.h;

_vers=$(cat main/php_version.h | grep 'PHP_VERSION ' | sed '/PHP_VERSION /s/#define PHP_VERSION //');

echo "Your new (custom) version is: ${_vers}";

exit;

Use it like

$ php-vers "-abc"
Your new (custom) version is: "7.0.1-abc"

speech_balloon » Now, I don’t like to see everyone adding xtra version numbers to see (&/or maybe to “show off”) just about everywhere. That was not the point. If you do it: Do it for your self, keep it in your local environment, and have a (somewhat good) reason for it. You know, PHP will run just fine without it. ok_hand

Updated post: 2012-12-23: added the script.


  1. “ZPM” (Zero point module), as seen in the TV show “Stargate Atlantis” »». I love that show. And the description fits quite well in on FPM/FastCGI, since it doesn’t point to anywhere (eg to Apache), like mod_php does.”

Comments