Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Howto build a PHP builtin extension without having to rebuild full PHP distribution
- Sometime, we need to dig into PHP extension code to make some adjustements. For
- instance that is currently our case with the PHP openssl extension as provided
- by older PHP versions (5.3, 5.4, 5.5) which is not compatible with openssl > 1.1...
- We need patch the code to add openssl 1.1 support...
- To do so, it would be tedious for us to have to recompile full PHP distribution
- each time we want try a build of the openssl extension with our changes. A build
- of the openssl extension take ~3 seconds while a build of the full PHP distribution
- is far far longer...
- So how to process exactly? Easy...
- ## Preparing PHP build environment
- First, we need prepare our environment by installing the PHP build environment. This
- should be simple as installing the PHP development package: apt-get phpX.Y-dev but...
- there is always a but... the `phpX.Y-dev` package for our older PHP version (here 5.3)
- depends on the `libssl1.0-dev` package while for the purpose of our backporting session,
- we need the openssl 1.1 development libraries.
- If we try to install the `phpX.Y-dev` package, this will also install the `libssl1.0-dev`
- package on which it depend and if we try to install the `libssl-dev` package, this will
- of course lead to it removal... Ouch... So what now? Should we rebuild the `phpX.Y-dev`
- package to change dependencies for allowing installation of the `libssl-dev` package for
- our backporting session? Of course yes, but a rebuild of the `phpX.Y-dev` in standard way
- (think of dpkg-buildpackage invocation) would involve a build of a full PHP distribution
- for various PHP SAPIs and we want avoid that (this would be too much time consuming).
- Another solution, the one we choosen, is to unpack the `phpX.Y-dev` package manually to
- edit the `DEBIAN/control` file and then repack it once done. This can be done quickly as
- follows:
- ```
- root@jenkins:/usr/local/src/SCM/# mkdir tmp
- root@jenkins:/usr/local/src/SCM/# cp php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64 php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb /tmp
- root@jenkins:/usr/local/src/SCM/# cd tmp
- root@jenkins:/usr/local/src/SCM/tmp# dpkg-deb -R php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64
- root@jenkins:/usr/local/src/SCM/tmp# vi php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64/DEBIAN/control
- root@jenkins:/usr/local/src/SCM/tmp# dpkg-deb -b php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64 php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb
- dpkg-deb: building package 'php5.3-dev' in 'php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb'.
- ```
- Then we can install the `libssl-dev` package and our new `phpX.Y-dev` package:
- ```
- root@jenkins:/usr/local/src/SCM/tmp# apt-get install libssl-dev
- Reading package lists... Done
- Building dependency tree
- Reading state information... Done
- Recommended packages:
- libssl-doc
- The following NEW packages will be installed:
- libssl-dev
- 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
- Need to get 0 B/1575 kB of archives.
- After this operation, 7051 kB of additional disk space will be used.
- Selecting previously unselected package libssl-dev:amd64.
- (Reading database ... 36677 files and directories currently installed.)
- Preparing to unpack .../libssl-dev_1.1.0f-3+deb9u2_amd64.deb ...
- Unpacking libssl-dev:amd64 (1.1.0f-3+deb9u2) ...
- Setting up libssl-dev:amd64 (1.1.0f-3+deb9u2) ...
- root@jenkins:/usr/local/src/SCM/tmp# dpkg -i php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb
- Selecting previously unselected package php5.3-dev.
- (Reading database ... 36763 files and directories currently installed.)
- Preparing to unpack php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb ...
- Unpacking php5.3-dev (5.3.29-1~1.gbpbf5ab3) ...
- Setting up php5.3-dev (5.3.29-1~1.gbpbf5ab3) ...
- update-alternatives: using /usr/bin/php-config5.3 to provide /usr/bin/php-config (php-config) in auto mode
- update-alternatives: using /usr/bin/phpize5.3 to provide /usr/bin/phpize (phpize) in auto mode
- Processing triggers for man-db (2.7.6.1-2) ...
- root@jenkins:/usr/local/src/SCM/tmp#
- ```
- ## Build of PHP openssl extension with our changes
- To build the PHP openssl extension without having to build the full PHP distribution,
- we need first prepare it for compilation as would will do with any external extension.
- This is done by invoking the `phpize` script inside the extension source directory:
- ```
- $ cd /usr/local/src/SCM/php/ext/openssl
- $ mv config0.m4 config.m4
- $ phpize
- ```
- That's all what we have to do. We can now build the extension as usual:
- ```
- $ make -j4
- ```
- Happy coding ;)
Add Comment
Please, Sign In to add comment