This document discusses how to create an OpenShift cartridge for Drupal 8 using PHP 5.4. It describes building a cartridge from RPM packages, setting up required files and environment variables, and scripts for common cartridge operations like installing, setting up, and starting and stopping services. Examples are provided of scripts for tasks like installing PEAR libraries. Links are included for references on the OpenShift documentation, cartridge development, and the specific PHP cartridge project discussed.
8. RPMSTOCARTRIDGERPMSTOCARTRIDGE
Download them
Use rpm2cpio to grab the binaries and files
is my script to
do this from IUS repos
Add in the appropriate manifest and hooks
Here are some examples of scripts from the PHP 5.4
cartridge
https://github.com/smerrill/php-the-ripper
9. RUNNINGAVENDOREDPHPRUNNINGAVENDOREDPHP
The toughest part: the path will change every time
php and php-fpm must be in $PATH
Point to php.ini with $PHPRC
Point to other .ini files with $PHP_INI_SCAN_DIR
PHP and HTTP libraries live in $LD_LIBRARY_PATH
10. CARTRIDGESCRIPTSCARTRIDGESCRIPTS
BIN/SETUPBIN/SETUP
The setup script is responsible for creating
and/or configuring the files that were copied
from the cartridge repository into the gear’s
directory. Setup must also be reentrant and will
be called on every incompatible upgrade. Any
logic you want to occur only once should be
added to install.
11. bin/setup
#!/bin/bash -eu
case "$1" in
-v|--version)
version="$2"
esac
# Set the version if it is unset.
[ -z "$version" ] && version=5.4.16
# Copy the version specific files up to php directory
shopt -s dotglob
mkdir -p $OPENSHIFT_PHP_DIR/configuration/etc/
cp -Hr $OPENSHIFT_PHP_DIR/versions/shared/configuration/etc/*
$OPENSHIFT_PHP_DIR/configuration/etc/
# Create additional directories required by PHP
mkdir -p $OPENSHIFT_PHP_DIR/phplib/pear/{docs,ext,php,cache,cfg,data,download,temp,tests,www}
mkdir -p $OPENSHIFT_PHP_DIR/{logs,run,tmp,sessions}
13. bin/install
#!/bin/bash -eu
case "$1" in
-v|--version)
version="$2"
esac
# Set the version if it is unset.
[ -z "$version" ] && version=5.4.16
echo "$version" > "$OPENSHIFT_PHP_DIR/env/OPENSHIFT_PHP_VERSION"
ln -s /usr/lib64/httpd/modules $OPENSHIFT_PHP_DIR/modules
ln -s /etc/httpd/conf/magic $OPENSHIFT_PHP_DIR/conf/magic
14. bin/install, continued
# PEAR setup
rm -f $OPENSHIFT_HOMEDIR/.pearrc
pear config-create "$OPENSHIFT_PHP_DIR"/phplib/pear/
"$OPENSHIFT_HOMEDIR"/.pearrc
pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set php_ini
"$OPENSHIFT_PHP_DIR"/configuration/etc/php.ini
pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set auto_discover 1
# @TODO: Make the version a variable?
pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set php_bin
"$OPENSHIFT_PHP_DIR"/usr/php/5.4.16-1/usr/bin/php
pear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set bin_dir
"$OPENSHIFT_PHP_DIR"/usr/php/5.4.16-1/usr/bin
pear -c "$OPENSHIFT_HOMEDIR"/.pearrc upgrade --force pear
18. WEBCARTRIDGESWEBCARTRIDGES
Cartridges that accepts HTTP requests
Every application has one and only one web cartridge
Bind to the application to a specified port and host
In our PHP 5.4 cartridge, PHP-FPM starts and Apache binds
22. bin/control, continued
function fpm() {
case "$1" in
start)
client_message "Starting PHP-FPM"
if [ -f "$FPM_PID_FILE" ]; then
client_message "PHP-FPM is already running."
return 0
fi
LD_LIBRARY_PATH=$OPENSHIFT_PHP_DIR/usr/php/5.4.16-1/usr/lib64
PHP_INI_SCAN_DIR=$OPENSHIFT_PHP_DIR/usr/php/5.4.16-1/etc/php.d
PHPRC=$OPENSHIFT_PHP_DIR/configuration/etc/php.ini
$OPENSHIFT_PHP_DIR/usr/php/5.4.16-1/usr/sbin/php-fpm
--fpm-config $OPENSHIFT_PHP_DIR/configuration/etc/php-fpm.conf
--pid $FPM_PID_FILE
return $?
;;
23. bin/control, continued
stop)
client_message "Stopping PHP-FPM"
if [ -f "$FPM_PID_FILE" ]; then
fpm_pid=`cat "$FPM_PID_FILE" 2> /dev/null`
kill $fpm_pid
return_status=$?
rm -f $FPM_PID_FILE
return $return_status
fi
;;
restart)
fpm stop && fpm start ;;
esac
}
24. RUNNINGYOURRUNNINGYOUR
CARTRIDGESONOPENSHIFTCARTRIDGESONOPENSHIFT
The OpenShift CDK (Catridge Development Kit)
Example:
The cartridge reflector
"Reflects" a cartridge from GitHub and adds the download
link to the GitHub zipball
cartreflect-claytondev.rhcloud.com/reflect?github=
Example:
https://github.com/smarterclayton/openshift-cdk-cart
http://rediscart-claytondev.rhcloud.com/
https://cartreflect-claytondev.rhcloud.com
/reflect?github=phase2/openshift-php-fpm