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:
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).
In both files, look for:
And put in your xtra version:
There are two lines here:
#define PHP_EXTRA_VERSION "" #define PHP_VERSION "5.6.14"
#define PHP_EXTRA_VERSION "-zpm" #define PHP_VERSION "5.6.14-zpm"
This is how it looks like:
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.
Made a small script of it.
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
Use it like
$ php-vers "-abc" Your new (custom) version is: "7.0.1-abc"
» 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.
Updated post: 2012-12-23: added the script.