drupal and open shift (and php)

26
DRUPAL AND OPENSHIFT (AND PHP) DRUPAL AND OPENSHIFT (AND PHP)

Upload: phase2

Post on 10-May-2015

7.894 views

Category:

Technology


0 download

DESCRIPTION

Steven presents with Openshift at DrupalCon Prague

TRANSCRIPT

Page 1: Drupal and Open shift (and php)

DRUPAL AND OPENSHIFT (AND PHP)DRUPAL AND OPENSHIFT (AND PHP)

Page 2: Drupal and Open shift (and php)

DOBRÉ ODPOLEDNE!DOBRÉ ODPOLEDNE!GUTEN TAG!GUTEN TAG!

Page 3: Drupal and Open shift (and php)

STEVEN MERRILLSTEVEN MERRILLDIRECTOR OF ENGINEERING, PHASE2DIRECTOR OF ENGINEERING, PHASE2

Page 4: Drupal and Open shift (and php)

DRUPAL 8 QUICKSTARTDRUPAL 8 QUICKSTART

OPENSHIFT ONLINEOPENSHIFT ONLINE

Page 5: Drupal and Open shift (and php)

BUT FIRST,BUT FIRST,

Page 6: Drupal and Open shift (and php)

DRUPAL 8DRUPAL 8Needs PHP 5.3.5OpenShift Online runs RHEL 6.4RHEL 6.4 has PHP 5.3.3

Page 7: Drupal and Open shift (and php)

BUILDING A CARTRIDGEBUILDING A CARTRIDGEIf it runs on RHEL or Fedora, it will run on OpenShiftIUS provides PHP 5.3 and PHP 5.4 cartridges for RHELLet's make a cartridge from those RPMS

Page 8: Drupal and Open shift (and php)

RPMS TO CARTRIDGERPMS TO CARTRIDGEDownload themUse rpm2cpio to grab the binaries and files

is my script todo this from IUS reposAdd in the appropriate manifest and hooksHere are some examples of scripts from the PHP 5.4cartridge

https://github.com/smerrill/php-the-ripper

Page 9: Drupal and Open shift (and php)

RUNNING A VENDORED PHPRUNNING A VENDORED PHPThe toughest part: the path will change every timephp and php-fpm must be in $PATHPoint to php.ini with $PHPRCPoint to other .ini files with $PHP_INI_SCAN_DIRPHP and HTTP libraries live in $LD_LIBRARY_PATH

Page 10: Drupal and Open shift (and php)

CARTRIDGE SCRIPTSCARTRIDGE SCRIPTSBIN/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.

Page 11: Drupal and Open shift (and php)

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 directoryshopt -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 PHPmkdir -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}

Page 12: Drupal and Open shift (and php)

CARTRIDGE SCRIPTSCARTRIDGE SCRIPTSBIN/INSTALLBIN/INSTALL

The install script is responsible for creating

and/or configuring the files that were copied

from the cartridge repository into the gear’s

directory. install will only be called on the

initial install of a cartridge.

Page 13: Drupal and Open shift (and php)

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/modulesln -s /etc/httpd/conf/magic $OPENSHIFT_PHP_DIR/conf/magic

Page 14: Drupal and Open shift (and php)

bin/install, continued# PEAR setuprm -f $OPENSHIFT_HOMEDIR/.pearrcpear config-create "$OPENSHIFT_PHP_DIR"/phplib/pear/ \ "$OPENSHIFT_HOMEDIR"/.pearrcpear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set php_ini \ "$OPENSHIFT_PHP_DIR"/configuration/etc/php.inipear -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/phppear -c "$OPENSHIFT_HOMEDIR"/.pearrc config-set bin_dir \"$OPENSHIFT_PHP_DIR"/usr/php/5.4.16-1/usr/binpear -c "$OPENSHIFT_HOMEDIR"/.pearrc upgrade --force pear

Page 15: Drupal and Open shift (and php)

SETTING ENVIRONMENTAL VARIABLESSETTING ENVIRONMENTAL VARIABLESCartridges can set environmental variables$OPENSHIFT_$CARTRIDGE_PATH_ELEMENT adds items to $PATHFor PHP, this will be $OPENSHIFT_PHP_PATH_ELEMENTProcessed as .erb templates

Page 16: Drupal and Open shift (and php)

env/OPENSHIFT_PHP_PATH_ELEMENT.erb

<%= ENV['OPENSHIFT_PHP_DIR'] %>usr/php/5.4.16-1/usr/bin

Page 17: Drupal and Open shift (and php)

env/LD_LIBRARY_PATH.erb

<%= ENV['OPENSHIFT_PHP_DIR'] %>usr/php/5.4.16-1/usr/lib64

Page 18: Drupal and Open shift (and php)

WEB CARTRIDGESWEB CARTRIDGESCartridges that accepts HTTP requestsEvery application has one and only one web cartridgeBind to the application to a specified port and hostIn our PHP 5.4 cartridge, PHP-FPM starts and Apache binds

Page 19: Drupal and Open shift (and php)

CARTRIDGE SCRIPTSCARTRIDGE SCRIPTSBIN/CONTROLBIN/CONTROL

update-configuration, pre-build, build, deploypost-deploy, start, stop, statusreload, restart, threaddump,

tidy, pre-snapshot, post-snapshotpre-restore, post-restore

The control script allows OpenShift or user to

control the state of the cartridge.

Page 20: Drupal and Open shift (and php)

bin/control

case "$1" in start) apache start && fpm start ;; stop) stop ;; restart) apache restart && fpm restart ;; reload|graceful) apache graceful "Restarting gracefully" ;; status) status ;; configtest) configtest ;; tidy) tidy ;; build) build ;; deploy) exit 0 ;; # Nothing to deploy on template PHP cartridge *) exit 0esac

exit $?

Page 21: Drupal and Open shift (and php)

bin/control, continuedfunction apache() { client_message "$2 Apache server" [ "$1" != "stop" ] && update_httpd_passenv $HTTPD_CFG_FILE /usr/sbin/httpd -C "Include $HTTPD_CFG_DIR/*.conf" -f $HTTPD_CFG_FILE -k $1 return $?}

Page 22: Drupal and Open shift (and php)

bin/control, continuedfunction 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 $? ;;

Page 23: Drupal and Open shift (and php)

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}

Page 24: Drupal and Open shift (and php)

RUNNING YOURRUNNING YOURCARTRIDGES ON OPENSHIFTCARTRIDGES ON OPENSHIFT

The OpenShift CDK (Catridge Development Kit)

Example: The cartridge reflector"Reflects" a cartridge from GitHub and adds the downloadlink to the GitHub zipballcartreflect-claytondev.rhcloud.com/reflect?github=Example:

https://github.com/smarterclayton/openshift-cdk-carthttp://rediscart-claytondev.rhcloud.com/

https://cartreflect-claytondev.rhcloud.com/reflect?github=phase2/openshift-php-fpm

Page 25: Drupal and Open shift (and php)

LINKSLINKShttps://github.com/phase2/openshift-php-fpmhttps://github.com/phase2/drupal-quickstarthttps://www.openshift.com/quickstarts/drupal-8-quickstarthttp://openshift.github.io/documentation/oo_deployment_guide_puppet.htmlhttp://openshift.github.io/documentation/oo_cartridge_developers_guide.html

Page 26: Drupal and Open shift (and php)

DĚKUJI VÁM!DĚKUJI VÁM!VIELEN DANK!VIELEN DANK!

@stevenmerrillsmerrill on freenodehttps://github.com/smerrillhttps://phase2technology.com