How to Add PHP Extensions to a Pod

Learn how to add non-standard PHP extensions to your pod.  Most extensions can be installed without additional configurations.  However, some extensions (e.g., oci8) require additional libraries be installed and configured. 

Operating System: Any

Applies To: Faculty or Staff using CaaS  

Last Updated: October 29, 2024

What is an Extension?

An extension is a piece of code written in C or C++ which will be included into the PHP core when PHP starts. Normally, you have some more native functions available after including an extension.  PHP extensions are slightly more difficult to install than PHP libraries.  Examples of PHP extensions include:

  • oci8
  • zip
  • mongodb
  • LDAP
  • curl

Prerequisites

Instructions

1. Add the following files to your code repository in the locations specified.  Replace "<extension_name>" with the name of the extension you would like to install.

.s2i/environment

  1. PHP_INI_SCAN_DIR=/etc/opt/rh/rh-php70/php.d:/opt/app-root/php.d
  2. ### Add any additional variables required by the extension below this line ###

.s2i/bin/assemble

  1. ### Add any prerequisite steps above this line ###
  2. echo "Installing extension"
  3. mkdir /opt/app-root/php.d
  4. cd /opt/app-root/
  5. pecl bundle <extension_name>
  6. cd <extension_name>
  7. phpize
  8. ./configure -q
  9. make
  10. echo "extension=/opt/app-root/<extension_name>/modules/<extension_name>.so" >> /opt/app-root/php.d/<extension_name>.ini
  11. ### Repeat lines 4 - 10 for any additional extensions ###
  12. ### Do not remove the line below unless you are sure you know what you are doing ###
  13. echo "Running assemble script"
  14. cd /opt/app-root/src/
  15. /usr/libexec/s2i/assemble

2. Follow the steps for How to create a new pod (aka container)

  • Select the php-devel image (or shib-php if you plan to use Shibboleth)

Example Repositories

The repositories listed below are complete examples of how to install the extension specified.  You can simply clone the repository and add your own code if you plan to use the extension in the example.

See also

Still need help?

Contact the UBIT Help Center.