Guest User

Untitled

a guest
Nov 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. # Howto build a PHP builtin extension without having to rebuild full PHP distribution
  2.  
  3. Sometime, we need to dig into PHP extension code to make some adjustements. For
  4. instance that is currently our case with the PHP openssl extension as provided
  5. by older PHP versions (5.3, 5.4, 5.5) which is not compatible with openssl > 1.1...
  6. We need patch the code to add openssl 1.1 support...
  7.  
  8. To do so, it would be tedious for us to have to recompile full PHP distribution
  9. each time we want try a build of the openssl extension with our changes. A build
  10. of the openssl extension take ~3 seconds while a build of the full PHP distribution
  11. is far far longer...
  12.  
  13. So how to process exactly? Easy...
  14.  
  15. ## Preparing PHP build environment
  16.  
  17. First, we need prepare our environment by installing the PHP build environment. This
  18. should be simple as installing the PHP development package: apt-get phpX.Y-dev but...
  19. there is always a but... the `phpX.Y-dev` package for our older PHP version (here 5.3)
  20. depends on the `libssl1.0-dev` package while for the purpose of our backporting session,
  21. we need the openssl 1.1 development libraries.
  22.  
  23. If we try to install the `phpX.Y-dev` package, this will also install the `libssl1.0-dev`
  24. package on which it depend and if we try to install the `libssl-dev` package, this will
  25. of course lead to it removal... Ouch... So what now? Should we rebuild the `phpX.Y-dev`
  26. package to change dependencies for allowing installation of the `libssl-dev` package for
  27. our backporting session? Of course yes, but a rebuild of the `phpX.Y-dev` in standard way
  28. (think of dpkg-buildpackage invocation) would involve a build of a full PHP distribution
  29. for various PHP SAPIs and we want avoid that (this would be too much time consuming).
  30.  
  31. Another solution, the one we choosen, is to unpack the `phpX.Y-dev` package manually to
  32. edit the `DEBIAN/control` file and then repack it once done. This can be done quickly as
  33. follows:
  34. ```
  35. root@jenkins:/usr/local/src/SCM/# mkdir tmp
  36. 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
  37. root@jenkins:/usr/local/src/SCM/# cd tmp
  38. 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
  39. root@jenkins:/usr/local/src/SCM/tmp# vi php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64/DEBIAN/control
  40. 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
  41. dpkg-deb: building package 'php5.3-dev' in 'php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb'.
  42. ```
  43. Then we can install the `libssl-dev` package and our new `phpX.Y-dev` package:
  44. ```
  45. root@jenkins:/usr/local/src/SCM/tmp# apt-get install libssl-dev
  46. Reading package lists... Done
  47. Building dependency tree
  48. Reading state information... Done
  49. Recommended packages:
  50. libssl-doc
  51. The following NEW packages will be installed:
  52. libssl-dev
  53. 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
  54. Need to get 0 B/1575 kB of archives.
  55. After this operation, 7051 kB of additional disk space will be used.
  56. Selecting previously unselected package libssl-dev:amd64.
  57. (Reading database ... 36677 files and directories currently installed.)
  58. Preparing to unpack .../libssl-dev_1.1.0f-3+deb9u2_amd64.deb ...
  59. Unpacking libssl-dev:amd64 (1.1.0f-3+deb9u2) ...
  60. Setting up libssl-dev:amd64 (1.1.0f-3+deb9u2) ...
  61. root@jenkins:/usr/local/src/SCM/tmp# dpkg -i php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb
  62. Selecting previously unselected package php5.3-dev.
  63. (Reading database ... 36763 files and directories currently installed.)
  64. Preparing to unpack php5.3-dev_5.3.29-1~1.gbpbf5ab3_amd64.deb ...
  65. Unpacking php5.3-dev (5.3.29-1~1.gbpbf5ab3) ...
  66. Setting up php5.3-dev (5.3.29-1~1.gbpbf5ab3) ...
  67. update-alternatives: using /usr/bin/php-config5.3 to provide /usr/bin/php-config (php-config) in auto mode
  68. update-alternatives: using /usr/bin/phpize5.3 to provide /usr/bin/phpize (phpize) in auto mode
  69. Processing triggers for man-db (2.7.6.1-2) ...
  70. root@jenkins:/usr/local/src/SCM/tmp#
  71. ```
  72.  
  73. ## Build of PHP openssl extension with our changes
  74.  
  75. To build the PHP openssl extension without having to build the full PHP distribution,
  76. we need first prepare it for compilation as would will do with any external extension.
  77. This is done by invoking the `phpize` script inside the extension source directory:
  78. ```
  79. $ cd /usr/local/src/SCM/php/ext/openssl
  80. $ mv config0.m4 config.m4
  81. $ phpize
  82. ```
  83. That's all what we have to do. We can now build the extension as usual:
  84. ```
  85. $ make -j4
  86. ```
  87.  
  88. Happy coding ;)
Add Comment
Please, Sign In to add comment