55c79512242fd281202cd57ca18defac696440f5kess#!/bin/bash
55c79512242fd281202cd57ca18defac696440f5kess#
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd# CDDL HEADER START
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd#
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd# The contents of this file are subject to the terms of the
55c79512242fd281202cd57ca18defac696440f5kess# Common Development and Distribution License (the "License").
55c79512242fd281202cd57ca18defac696440f5kess# You may not use this file except in compliance with the License.
55c79512242fd281202cd57ca18defac696440f5kess#
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc# or http://www.opensolaris.org/os/licensing.
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd# See the License for the specific language governing permissions
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd# and limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen#
2e545ce2450a9953665f701bb05350f0d3f26275nd# When distributing Covered Code, include this CDDL HEADER in each
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen# If applicable, add the following below this CDDL HEADER, with the
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd# fields enclosed by brackets "[]" replaced with your own identifying
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd# information: Portions Copyright [yyyy] [name of copyright owner]
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen#
3f08db06526d6901aa08c110b5bc7dde6bc39905nd# CDDL HEADER END
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd#
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd#
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd# Helper functions
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7ndfunction usage {
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd echo ""
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd echo "Usage: This script will update a given Web Server 7 instance's configuration"
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen echo " files to be able to execute PHP scripts."
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd echo ""
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end echo "This script recognizes following arguments:"
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen echo " --installroot : Top level Sun Web Server 7 installation location. "
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen echo ""
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd echo " --instancename : Name of Web Server instance (https-php) which should"
726b11c595edf0b0b71d0d39a2bc9d912c0ee4b5nd echo " be configured to execute PHP scripts. "
55c79512242fd281202cd57ca18defac696440f5kess echo ""
ec1d455940a366b63e1cce2f442a445347394a90nd echo " --sapi : How should PHP runtime be loaded within Web Server 7"
ec1d455940a366b63e1cce2f442a445347394a90nd echo " fastcgi (Default) or NSAPI (Optional). "
ec1d455940a366b63e1cce2f442a445347394a90nd echo ""
ec1d455940a366b63e1cce2f442a445347394a90nd exit 1
ec1d455940a366b63e1cce2f442a445347394a90nd}
55c79512242fd281202cd57ca18defac696440f5kess
1ce7f356a70d1d9961ec315c212e2f83a1452456ndfunction parse_arguments
8f057347a12e831fdf567da83de2fa581580298dnd{
5b10fd3977e6dfff19afe770e612e276962f7950nd until [ $# -eq 0 ]
5b10fd3977e6dfff19afe770e612e276962f7950nd do
8f057347a12e831fdf567da83de2fa581580298dnd cur_arg=$1
8f057347a12e831fdf567da83de2fa581580298dnd case $cur_arg in
8f057347a12e831fdf567da83de2fa581580298dnd --installroot=*)
8f057347a12e831fdf567da83de2fa581580298dnd install_root="`echo $cur_arg | cut -d= -f2-`"
8f057347a12e831fdf567da83de2fa581580298dnd ;;
8f057347a12e831fdf567da83de2fa581580298dnd --instancename=*)
1ce7f356a70d1d9961ec315c212e2f83a1452456nd instance_name="`echo $cur_arg | cut -d= -f2-`"
5b10fd3977e6dfff19afe770e612e276962f7950nd ;;
5b10fd3977e6dfff19afe770e612e276962f7950nd --sapi=*)
1ce7f356a70d1d9961ec315c212e2f83a1452456nd sapi="`echo $cur_arg | cut -d= -f2-`"
2fc082b48b1bfb1182d6b93f5837e74b0c0af3eckess ;;
2fc082b48b1bfb1182d6b93f5837e74b0c0af3eckess *)
74086452b5093fa1a58446034c6ddfd67dab5651kess usage
74086452b5093fa1a58446034c6ddfd67dab5651kess ;;
80eed96ee3d8cfa0b66d9fb1cfe63fd83254d38bnilgun esac
80eed96ee3d8cfa0b66d9fb1cfe63fd83254d38bnilgun shift;
55c79512242fd281202cd57ca18defac696440f5kess done
55c79512242fd281202cd57ca18defac696440f5kess}
316f02e3836836c82e19019ff23f90a7ebc65289nilgun
62664c6703ed9e8d8f4f8e4c5f5e893559ecefecndfunction try_interactive
62664c6703ed9e8d8f4f8e4c5f5e893559ecefecnd{
cf60fc8ad0f3a8f4b08351a2a3e346e0662af010nd # Get user response on Web Server 7 installation location and instance name.
eac1d56b0c6d54ddf717d035f808bdfa61e8bd14nd echo -n "Enter your Web Server installation location : "
b8670d4ea3a3efcd12c3e1eddf68ef6fabef49fend read input
b8670d4ea3a3efcd12c3e1eddf68ef6fabef49fend if [ -n "$input" ]; then
1ce7f356a70d1d9961ec315c212e2f83a1452456nd install_root="$input"
1ce7f356a70d1d9961ec315c212e2f83a1452456nd fi
1ce7f356a70d1d9961ec315c212e2f83a1452456nd
6c4ef4a72d9897e53365b94103f4bd819fd0d3acnd echo -n "Enter your Web Server instance name to configure with PHP runtime: "
22d5d84393d960a2027f472036f3fee15d7dbce9nd read input
22d5d84393d960a2027f472036f3fee15d7dbce9nd if [ -n "$input" ]; then
22d5d84393d960a2027f472036f3fee15d7dbce9nd instance_name="$input"
5a98f1b67de38575f3903a03fc5120062b814371kess fi
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kess while [ 0 ]; do
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf echo -n "How you would like Sun Web Server 7 to load PHP engine (fastcgi|nsapi) [fastcgi]: "
50c04f297d76a57ead2fa6b73845f7563b1fc788sf read input
55c79512242fd281202cd57ca18defac696440f5kess if [ -z "$input" ]; then
55c79512242fd281202cd57ca18defac696440f5kess sapi="fastcgi"
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen else
55c79512242fd281202cd57ca18defac696440f5kess sapi=$input
635e08c1d8332adc365b1c20bbe3577d59ebcd78kess fi
623eebe956d9c2d6d073ed3eae855b56030b40e9noodl if [ -n "$sapi" ] && [ $sapi = "fastcgi" -o $sapi = "nsapi" ]; then
55c79512242fd281202cd57ca18defac696440f5kess break
55c79512242fd281202cd57ca18defac696440f5kess fi
ffb88a4885747797937e30a5ac8b1606da3cb4adnd done
909ce17e2bd0faef7b1c294f2307f009793fd493nd return 1;
55c79512242fd281202cd57ca18defac696440f5kess}
55c79512242fd281202cd57ca18defac696440f5kess
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowefunction validate_arguments
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
65a611af7093423efb91e5794b8887a527d4cf63trawick if [ ! -d "$install_root" ] || [ ! -x "$install_root/lib/webservd" ]; then
65a611af7093423efb91e5794b8887a527d4cf63trawick echo ""
42af92a661a06b3cebc88d585aad75064a309d51nd echo "Warning: Unable to find valid Web Server installation under $install_root"
42af92a661a06b3cebc88d585aad75064a309d51nd echo "Please try again by providing a valid Web Server 7 installation location."
ffb88a4885747797937e30a5ac8b1606da3cb4adnd usage
6fe26506780e73be2a412d758af77fafdf03291and fi
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kess if [ ! -d "$install_root" ] || [ ! -x "$install_root/lib/webservd" ]; then
55c79512242fd281202cd57ca18defac696440f5kess echo ""
55c79512242fd281202cd57ca18defac696440f5kess echo "Warning: Unable to find valid Web Server installation under $install_root"
0203b896e484dfb877111aceffb812401d0f216and echo "Please try again by providing a valid Web Server 7 installation location."
312d4192f2e32167a1e750034664f1e3c2105c65nd usage
55c79512242fd281202cd57ca18defac696440f5kess fi
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kess if [ -n "$sapi" ] && [ $sapi != "fastcgi" -a $sapi != "nsapi" ]; then
08cf4a15275e4cb65a424b3a1db5410bfb51085cjim echo ""
f6066dc0a6ad0432b74774e290c04c3cc4aa2dafrbowen echo "Error: Invalid SAPI option is provided.Valid SAPI argument is either 'fastcgi' or 'nsapi'"
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin echo "Please try again by providing a valid SAPI as argument."
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen usage
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen fi
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kess return 1;
55c79512242fd281202cd57ca18defac696440f5kess}
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kessfunction generate_tempfile
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin{
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin template="tmp.XXXXXXXXXX";
55c79512242fd281202cd57ca18defac696440f5kess if [ -x "/bin/mktemp" ]; then
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen temp_file="`/bin/mktemp`"
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen elif [ -x "/usr/bin/mktemp" ]; then
e8b603fa9ccf7b17b11b42df6d8916fd97c2331dnd temp_file="`/usr/bin/mktemp`"
55c79512242fd281202cd57ca18defac696440f5kess fi
55c79512242fd281202cd57ca18defac696440f5kess if [ ! -f $temp_file ]; then
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier temp_file="/tmp/ws7_php_configure.$$"
55c79512242fd281202cd57ca18defac696440f5kess touch $temp_file
55c79512242fd281202cd57ca18defac696440f5kess chmod 600 $temp_file
611049e38bfbaeb173d2d7fab2e44a48753436a1nd fi
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf
55c79512242fd281202cd57ca18defac696440f5kess return 1;
55c79512242fd281202cd57ca18defac696440f5kess}
55c79512242fd281202cd57ca18defac696440f5kess
2eb7a8afc318286c210a1fbb2ff2ba904471956frjungfunction generate_configure
d8b761beec42bbe2847bb14e3b706642c6eed47cnd{
d8b761beec42bbe2847bb14e3b706642c6eed47cnd if [ "$OSNAME" = "SunOS" ]; then
d8b761beec42bbe2847bb14e3b706642c6eed47cnd tail +${perl_start_line} $PROGRAM_NAME > $temp_file
55c79512242fd281202cd57ca18defac696440f5kess elif [ "$OSNAME" = "Linux" ]; then
55c79512242fd281202cd57ca18defac696440f5kess start_line=${perl_start_line}
1ce7f356a70d1d9961ec315c212e2f83a1452456nd total_line=`wc -l $PROGRAM_NAME | awk '{print $1}' 2>/dev/null`
03a4ff9ac4c9b8009249010e7c53bb86ff05915and few_lines=$(($total_line - $start_line))
5effc8b39fae5cd169d17f342bfc265705840014rbowen tail -${few_lines} $PROGRAM_NAME > $temp_file
1ce7f356a70d1d9961ec315c212e2f83a1452456nd fi
55c79512242fd281202cd57ca18defac696440f5kess chmod 500 $temp_file
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen}
864d6d55a72bdb982ebabbc95cf8f051c43fa6ddrbowen
0203b896e484dfb877111aceffb812401d0f216andfunction invoke_configure
6329991d5f023c1c4ae02cfbbda636c66e6392aand{
55c79512242fd281202cd57ca18defac696440f5kess # Setup environment
55c79512242fd281202cd57ca18defac696440f5kess if [ -f "$install_root/lib/wsenv" ]; then
55c79512242fd281202cd57ca18defac696440f5kess source $install_root/lib/wsenv
55c79512242fd281202cd57ca18defac696440f5kess if [ ! -d "${WS_INSTANCEROOT}/${instance_name}" ]; then
6c4ef4a72d9897e53365b94103f4bd819fd0d3acnd echo "Warning: Unable to find instance:'$instance_name' under $WS_INSTANCEROOT"
2704de98885368683621b01c8f8f4e4b01557611takashi echo " Please try again by providing a valid instance name."
2704de98885368683621b01c8f8f4e4b01557611takashi exit 1;
2704de98885368683621b01c8f8f4e4b01557611takashi fi
b43f840409794ed298e8634f6284741f193b6c4ftakashi fi
2704de98885368683621b01c8f8f4e4b01557611takashi
55c79512242fd281202cd57ca18defac696440f5kess # Special case, if it is NSAPI
55c79512242fd281202cd57ca18defac696440f5kess if [ "$sapi" = "nsapi" ]; then
c819c19c2f1ffbf3a3f12a4070cc6c3f4ea2a6f2sf mkdir -p "$install_root/plugins/webstack-php"
d2b809e5d72658bff23819d8b77f20e4939af541nd ln -sf "<<INSTALL_DIR>>/nsapi/libphp5.so" "$install_root/plugins/webstack-php/libphp5.so"
55c79512242fd281202cd57ca18defac696440f5kess fi
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier # Invoke script to configure PHP runtime.
e60187855fd0488f48f37e88acde742754308d39rbowen if [ "$sapi" = "nsapi" ]; then
04bab87733a0e93a926e82311c85cd8ac06a032fnd PHPROOT="<<INSTALL_DIR>>"
55c79512242fd281202cd57ca18defac696440f5kess PHPCONFROOT="<<NSAPI_CONF_DIR>>"
55c79512242fd281202cd57ca18defac696440f5kess PHPCONFROOT_SCANDIR="<<ZTS_MODULES_CONF_DIR>>"
55c79512242fd281202cd57ca18defac696440f5kess else
55c79512242fd281202cd57ca18defac696440f5kess PHPROOT="<<INSTALL_DIR>>"
55c79512242fd281202cd57ca18defac696440f5kess PHPCONFROOT="<<CONF_DIR>>"
1ce7f356a70d1d9961ec315c212e2f83a1452456nd PHPCONFROOT_SCANDIR="<<MODULES_CONF_DIR>>"
c023f60e35022146373e40249f0c8c8d623b6fcfnd fi
5effc8b39fae5cd169d17f342bfc265705840014rbowen
5effc8b39fae5cd169d17f342bfc265705840014rbowen ${WS_PERL}/perl -I ${WS_PERL} -I ${WS_PERL}/lib -I ${WS_PERL}/lib/site_perl $temp_file \
27d778df0b517e1578f907d2e51eb961cd8ee5fbjim -installroot=${WS_INSTALLROOT} -instanceroot=${WS_INSTANCEROOT} -instancename=$instance_name \
a610901168de82df5fc5d99b8759fd80e0f70aeasf -sapi=$sapi -phproot="${PHPROOT}" \
a43bfa789f4e52dde53ae8e53fa0427b5c1cf977nd -phpconfroot="${PHPCONFROOT}" -phpmodulesconfroot="${PHPCONFROOT_SCANDIR}"
a43bfa789f4e52dde53ae8e53fa0427b5c1cf977nd
28c9d384aa958b321280b4ac886941dcad25396bnd status=$?
240e1b440b19476ecaa4aa9ff8d79afef74cb14and if [ $status -eq 0 ]; then
240e1b440b19476ecaa4aa9ff8d79afef74cb14and if [ -f $temp_file ]; then
438b4817913a5ff55d9cad4c7ddf133330b4466ejim rm -f $temp_file
438b4817913a5ff55d9cad4c7ddf133330b4466ejim fi
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi elif [ $status -ne 0 ]; then
e5ce3ac0e9b720c0fa23782e29168a0810697fdetakashi echo "Unable to successfully setup PHP within Web Server 7"
604c89126c27104f659d7a51b0113e3bd435faf8fielding exit 1
50cb7e2b30597f481fee57bac945190f06ebcc58jorton fi
240e1b440b19476ecaa4aa9ff8d79afef74cb14and}
240e1b440b19476ecaa4aa9ff8d79afef74cb14and
4126704c4950bfd46d32ad54e3b106ac6d868a73sf#-------------------------------------------------------------------------------
4126704c4950bfd46d32ad54e3b106ac6d868a73sf#####
240e1b440b19476ecaa4aa9ff8d79afef74cb14and# Main
240e1b440b19476ecaa4aa9ff8d79afef74cb14and#####
0a69d9bb491d9810892a9949c01403a1de3c7ac2ndPATH=/bin:/usr/bin:/usr/gnu/bin:/usr/sfw/bin
2544c1693130c0a3106f2ff2c0ef7e3cf0a228e0jimexport PATH
245eb3a84b8bc2b350c3a39ba2599444d443b50ajim
4ed26c413f67a5aae20b95909828f30bb5dc2286poirier# Global variables.
4ed26c413f67a5aae20b95909828f30bb5dc2286poirierOSNAME="`uname -s`"
5effc8b39fae5cd169d17f342bfc265705840014rbowenPHPROOT="<<INSTALL_DIR>>"
5effc8b39fae5cd169d17f342bfc265705840014rbowenPHPCONFROOT="<<CONF_DIR>>"
9652bc3a93433d52f80579062986ead2afe0d11fsfPHPCONFROOT_SCANDIR="<<MODULES_CONF_DIR>>"
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowePROGRAM_NAME="$0"
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilguninstall_root=""
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilguninstance_name=""
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowesapi="fastcgi"
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashitemp_file=""
55c79512242fd281202cd57ca18defac696440f5kess
50cb7e2b30597f481fee57bac945190f06ebcc58jorton# This below line need to point to the start of embedded perl script.
79b024b81f6bb3c44dce77a7552191daf8b522d2jimperl_start_line=245
f772e8f448c223e5ea306f1bf92d97d968f972d5jim
f772e8f448c223e5ea306f1bf92d97d968f972d5jimecho "This script will update a given Web Server 7 instance's configuration"
fac8c35bfb158112226ab43ddf84d59daca5dc30ndecho "files to be able to execute PHP scripts."
f772e8f448c223e5ea306f1bf92d97d968f972d5jimecho ""
55c79512242fd281202cd57ca18defac696440f5kess
1de1266f0ea387d6373be8415745dfd2ab876341jim# Verify if the program is called with necessary arguments.
1de1266f0ea387d6373be8415745dfd2ab876341jimif [ -n "$1" ]; then
55c79512242fd281202cd57ca18defac696440f5kess parse_arguments $@;
55c79512242fd281202cd57ca18defac696440f5kesselse
5effc8b39fae5cd169d17f342bfc265705840014rbowen # Invoked with no arguments. Try interactive.
5effc8b39fae5cd169d17f342bfc265705840014rbowen try_interactive
5effc8b39fae5cd169d17f342bfc265705840014rbowenfi
5effc8b39fae5cd169d17f342bfc265705840014rbowen
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sfvalidate_arguments
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sfgenerate_tempfile
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kessgenerate_configure
0237f43ab925775250e266e479d0a337ff374a4btakashi
0237f43ab925775250e266e479d0a337ff374a4btakashiinvoke_configure
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kessexit 0
898711b68797304101de0882fa576c8908acfae6nd
55c79512242fd281202cd57ca18defac696440f5kess#---------------------EOF-------------------------------------------------------
55c79512242fd281202cd57ca18defac696440f5kess
4044e4b6cb07cf7fa8e90676fafffe543c1d439bjim# Helper Script to configure PHP runtime environment within Web Server 7
a8855705fee1545ac35b482d58d03b2e4064b3aend
1ce7f356a70d1d9961ec315c212e2f83a1452456nduse XML::Simple;
55c79512242fd281202cd57ca18defac696440f5kessuse File::Basename;
50cb7e2b30597f481fee57bac945190f06ebcc58jortonuse English;
55c79512242fd281202cd57ca18defac696440f5kessuse strict;
55c79512242fd281202cd57ca18defac696440f5kess
55c79512242fd281202cd57ca18defac696440f5kessour $INSTANCE_ROOT = undef;
55c79512242fd281202cd57ca18defac696440f5kessour $INSTALL_ROOT = undef;
03c25fb6f628ac81f2ecb637d1e7502dcee783f3ndour $INSTANCE_NAME = undef;
03c25fb6f628ac81f2ecb637d1e7502dcee783f3ndour $PHP_ROOT = "";
55c79512242fd281202cd57ca18defac696440f5kessour $PHP_CONF_ROOT = "";
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coarour $PHP_MODULES_CONF_ROOT = "";
b43f840409794ed298e8634f6284741f193b6c4ftakashiour $SAPI = undef;
4126704c4950bfd46d32ad54e3b106ac6d868a73sfour $MIME_TYPES_FILES = [];
4126704c4950bfd46d32ad54e3b106ac6d868a73sfour $OBJ_CONF_FILES = [];
8f057347a12e831fdf567da83de2fa581580298dndour $SERVER_64BIT_MODE = undef;
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7ndmy $phpSoName;
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7ndif (isWindows()) {
b05ab3ff5ab54aa22610b13d56eaba6ddfc3db60nd $phpSoName = "php5nsapi.dll";
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen} else {
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd $phpSoName = "libphp5.so";
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end}
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen
d474d8ef01ec5c2a09341cd148851ed383c3287crbowenmy $fastCGISoName;
3b3b7fc78d1f5bfc2769903375050048ff41ff26ndif (isWindows()) {
205f749042ed530040a4f0080dbcb47ceae8a374rjung $fastCGISoName = "fastcgi.dll";
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen} else {
0d0ba3a410038e179b695446bb149cce6264e0abnd $fastCGISoName = "libfastcgi.so";
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd}
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
7fec19672a491661b2fe4b29f685bc7f4efa64d4ndmain();
1ce7f356a70d1d9961ec315c212e2f83a1452456nd
sub main {
getCommandOptions();
processServerXml();
checkFilesWritable();
processMagnusConf();
processObjConf();
processMimeTypes();
printResult();
}
# -----------------------------------------------------------------------------
# getCommandOptions
# Process the command line options
# -----------------------------------------------------------------------------
sub getCommandOptions {
for (my $counter=0; $#ARGV >= $counter; $counter++) {
my $argument = $ARGV[$counter];
if ($argument =~ /^-installroot=/i) {
$INSTALL_ROOT = substr($argument, length("-installroot="));
}
if ($argument =~ /^-instanceroot=/i) {
$INSTANCE_ROOT = substr($argument, length("-instanceroot="));
}
if ($argument =~ /^-phproot=/i) {
$PHP_ROOT = substr($argument, length("-phproot="));
}
if ($argument =~ /^-phpconfroot=/i) {
$PHP_CONF_ROOT = substr($argument, length("-phpconfroot="));
}
if ($argument =~ /^-phpmodulesconfroot=/i) {
$PHP_MODULES_CONF_ROOT = substr($argument, length("-phpmodulesconfroot="));
}
if ($argument =~ /^-instancename=/i) {
$INSTANCE_NAME = substr($argument, length("-instancename="));
}
if ($argument =~ /^-sapi=/i) {
$SAPI = substr($argument, length("-sapi="));
}
}
if ((!defined $PHP_CONF_ROOT) || ($PHP_CONF_ROOT eq "")) {
$PHP_CONF_ROOT = $PHP_ROOT;
}
if ((not defined $INSTANCE_NAME) or ($INSTANCE_NAME !~ m/\S+/)) {
printUsage();
}
exit 1 unless defined isValidFile("$INSTANCE_ROOT/$INSTANCE_NAME/config");
}
# -----------------------------------------------------------------------------
# migrateObjConf
# Migrate obj.conf file to php 1.1
# -----------------------------------------------------------------------------
sub migrateObjConf {
my $objConfFile = shift;
my $pContents = shift;
my $tmpObjConfStatus = 1;
return undef unless ($objConfFile);
if ((not -f $objConfFile or ref($pContents) != "ARRAY")) {
return undef;
}
my $tmpObjConfFile = "$objConfFile"."tmp";
my $update_reqd = undef;
local *TMPOBJ;
my $newLibPath = "$PHP_ROOT/lib";
my $newLibPath64 = "$PHP_ROOT/lib/64";
for (my $i = 0; $i < $#{@{$pContents}}; $i++) {
my $pLine = \$pContents->[$i];
next if ($$pLine =~ /^\#/); #ignore comments;
next if (isWindows());
if ($$pLine =~ m@(.*\s+app-path=['"])(\S+)\s*(['"].*)@) {
my ($tmp, $tmp1, $tmp2, $tmp3);
$tmp1 = $1; $tmp2 = $2; $tmp3 = $3;
$tmp2 =~ s@$PHP_ROOT/bin/php@$PHP_ROOT/bin/php-cgi@;
$tmp = $tmp1.$tmp2.$tmp3."\n";
$pContents->[$i] = $tmp;
$update_reqd = 1;
}
elsif ($$pLine =~ m@(.*\s+app-env=['"])(\S+)(=)(\S+)(['"].*)@) {
my ($tmp, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5);
$tmp1 = $1; $tmp2 = $2; $tmp3 = $3; $tmp4 = $4; $tmp5 = $5;
if (($tmp2 =~ m@LD_LIBRARY_PATH@) or ($tmp2 =~ m@LD_LIBRARY_PATH_64@)) {
if ($tmp4 =~ m@$PHP_ROOT/64@) {
$tmp4 =~ s@$PHP_ROOT/64@$newLibPath64@g;
}
elsif ($tmp4 =~ m@$PHP_ROOT/64([:].*)@) {
$tmp4 =~ s@$PHP_ROOT/64(:.*)@$newLibPath64$1@g;
}
elsif ($tmp4 =~ m@$PHP_ROOT([:].*)@) {
$tmp4 =~ s@$PHP_ROOT(:.*)@$newLibPath$1@g;
}
elsif ($tmp4 =~ m@$PHP_ROOT@) {
$tmp4 =~ s@$PHP_ROOT@$newLibPath@g;
}
}
elsif ($tmp2 =~ m@PHP_FCGI_MAX_REQUEST@) {
$tmp2 =~ s@PHP_FCGI_MAX_REQUEST@PHP_FCGI_MAX_REQUESTS@g;
$tmp4 =~ s@200@2000@;
}
$tmp = $tmp1.$tmp2.$tmp3.$tmp4.$tmp5."\n";
$pContents->[$i] = $tmp;
$update_reqd = 1;
}
}
if ($update_reqd) {
open(TMPOBJ,">$tmpObjConfFile") or $tmpObjConfStatus = undef;
if (defined $tmpObjConfStatus) {
for (my $i = 0; $i < $#{@{$pContents}}; $i++) {
my $line = $pContents->[$i];
print TMPOBJ $line;
}
print "UPDATED: $objConfFile \n";
close(TMPOBJ);
unlink("$objConfFile");
rename("$tmpObjConfFile", "$objConfFile");
chmod(0600, "$objConfFile");
return 2;
}
}
return 1;
}
# -----------------------------------------------------------------------------
# processServerXml
# Parse the server.xml and get all the mime files and object files
# -----------------------------------------------------------------------------
sub processServerXml {
my $file = undef;
my $serverXml = "$INSTANCE_ROOT/$INSTANCE_NAME/config/server.xml";
my $config = eval{XMLin("$serverXml", forcearray=>1, keyattr=>[])};
if ($@) {
print("\nERROR: Problem parsing the $serverXml. Not a valid xml file. \n\n");
exit 1;
}
#get the server level mime file
$file = $config->{"mime-file"}->[0];
if (defined $file) {
$file = getValidAbsoluteFilePath($file);
if (defined $file) {
push (@$MIME_TYPES_FILES, $file);
}
}
# get the server platform mode
my $mode = $config->{"platform"}->[0];
if (defined $mode) {
if ($mode == "64") {
$SERVER_64BIT_MODE = "64";
}
}
for (my $vsCounter = 0; ${config}->{"virtual-server"}->[$vsCounter]; $vsCounter++) {
my $virutalServerElement = ${config}->{"virtual-server"}->[$vsCounter];
#get the virtual server level mime files
for (my $mimeTypescounter = 0; ${virutalServerElement}->{"mime-file"}->[$mimeTypescounter]; $mimeTypescounter++) {
$file = ${virutalServerElement}->{"mime-file"}->[$mimeTypescounter];
$file = getValidAbsoluteFilePath($file);
if (defined $file) {
push (@$MIME_TYPES_FILES, $file);
}
}
#get the virtual server level object files
for (my $objectFilecounter = 0; ${virutalServerElement}->{"object-file"}->[$objectFilecounter]; $objectFilecounter++) {
$file = ${virutalServerElement}->{"object-file"}->[$objectFilecounter];
$file = getValidAbsoluteFilePath($file);
if (defined $file) {
push (@$OBJ_CONF_FILES, $file);
}
}
}
#Default is mime.types
if (@$MIME_TYPES_FILES < 1) {
push (@$MIME_TYPES_FILES, "$INSTANCE_ROOT/$INSTANCE_NAME/config/mime.types");
}
#Default is obj.conf
if (@$OBJ_CONF_FILES < 1) {
push (@$OBJ_CONF_FILES, "$INSTANCE_ROOT/$INSTANCE_NAME/config/obj.conf");
}
}
# -----------------------------------------------------------------------------
# processMagnusConf
# Append the MAGNUS_CONF_APPEND_STRING value at the end of magnus.conf file.
# -----------------------------------------------------------------------------
sub processMagnusConf {
my $magnusConfFile = "$INSTANCE_ROOT/$INSTANCE_NAME/config/magnus.conf";
my $magnusConfStatus = 1;
if (defined isValidFile($magnusConfFile))
{
# Get the current File Stat.
my @statInfo = stat $magnusConfFile;
# Verify if the changes already exist.
if (open(MAGNUS_R,"<$magnusConfFile")) {
my @contents = <MAGNUS_R>;
foreach (@contents) {
next if (/^\#/); #ignore comments;
if ((isNSAPI()) and (/shlib(.*)$phpSoName(.*)/g)) {
close(MAGNUS_R);
return 1;
} elsif ((not isNSAPI()) and (/shlib(.*)$fastCGISoName(.*)/g)) {
close(MAGNUS_R);
return 1;
}
}
close(MAGNUS_R);
}
open(MAGNUS,">>$magnusConfFile") or $magnusConfStatus = 0;
if ($magnusConfStatus == 1) {
addToMagnusConf(\*MAGNUS);
print "\n\nUPDATED: $magnusConfFile \n";
} else {
print "\nERROR: Unable to write $magnusConfFile. \n\n";
close(MAGNUS);
exit 1;
}
close(MAGNUS);
chown $statInfo[4], $statInfo[5], $magnusConfFile;
}
}
# -----------------------------------------------------------------------------
# processObjConf
# Append the OBJ_CONF_APPEND_STRING value after the <object name="default"
# directive in all object files.
# -----------------------------------------------------------------------------
sub processObjConf {
while(scalar(@$OBJ_CONF_FILES) > 0) {
my $objConfFile = pop(@$OBJ_CONF_FILES);
my $objConfStatus = 1;
my $tmpObjConfStatus = 1;
if (defined isValidFile($objConfFile))
{
# Get the current File Stat.
my @statInfo = stat $objConfFile;
# Verify if the changes already exist.
open(OBJ,"<$objConfFile") or $objConfStatus = undef;
if (defined $objConfStatus) {
my @lines = <OBJ>;
my $escape_path = $PHP_ROOT;
$escape_path =~ s/\/(\w)/\\\/$1/g;
$escape_path =~ s/\\(\w)/\/$1/g;
my $contents = join("",@lines);
my $already_configured = undef;
if ((isNSAPI()) and ($contents =~ m/
\s*Service\s+type="magnus-internal\/php"\s+fn="php5_execute"
/mx)) {
close(OBJ);
$already_configured = 1;
}
if ((not isNSAPI()) and (($contents =~ m/
\s*Service\s+type=[\"]magnus-internal\/php[\"]
[\r\n]+
\s*fn=[\"]responder-fastcgi[\"]
[\r\n]+
\s*app-path=[\"](.*)[\"]
[\r\n]+
/mx) and ($1 =~ m@$escape_path@))) {
close(OBJ);
$already_configured = 1;
# migrate existing obj.conf configurations.
&migrateObjConf($objConfFile, \@lines);
}
next if ($already_configured);
# Create a new obj.conf
my $tmpObjConfFile = "$objConfFile"."tmp";
open(TMPOBJ,">$tmpObjConfFile") or $tmpObjConfStatus = undef;
if (defined $tmpObjConfStatus) {
if (@lines) {
foreach my $line (@lines) {
if (($line =~ /^<Object/i) &&
(($line =~ /name=default>/i) ||
($line =~ /name=default\s/i) ||
($line =~ /name="default"/i))) {
print TMPOBJ $line;
addToObjConf(\*TMPOBJ);
print "UPDATED: $objConfFile \n";
} elsif ($line =~ /PathCheck\s+fn\s*=\s*(\S+)\s+(\S+)\s*=\s*(\S+)$/) {
my $funcName = $1;
my $valueName = $2;
my $values = $3;
if (($funcName =~ /find-index/) and ($valueName =~ /index-names/)) {
$values =~ s/[\"](\S+)[\"]/$1/;
$values = "$1".",index.php";
my $newLine = <<__UP_TO_THIS_POINT_;
PathCheck fn=$funcName $valueName=\"$values\"
__UP_TO_THIS_POINT_
print TMPOBJ $newLine;
}
else {
print TMPOBJ $line;
}
} else {
print TMPOBJ $line;
}
}
}
} else {
print "\nERROR: Unable to write $objConfFile \n\n";
close(TMPOBJ);
close(OBJ);
unlink("$tmpObjConfFile");
exit 1;
}
close(TMPOBJ);
close(OBJ);
unlink("$objConfFile");
rename("$tmpObjConfFile", "$objConfFile");
chmod(0600, "$objConfFile");
chown $statInfo[4], $statInfo[5], $objConfFile;
}
}
}
}
# -----------------------------------------------------------------------------
# processMimeTypes
# Append the MIME_TYPES_APPEND_STRING value at the end of
# all the mime types file.
# -----------------------------------------------------------------------------
sub processMimeTypes {
while(scalar(@$MIME_TYPES_FILES) > 0) {
my $mimeTypesFile = pop(@$MIME_TYPES_FILES);
my $mimeTypesStatus = 1;
if (defined isValidFile($mimeTypesFile)) {
# Get the current File Stat.
my @statInfo = stat $mimeTypesFile;
# Verify if the changes already exist.
if (open(MIME_R,"<$mimeTypesFile")) {
my @contents = <MIME_R>;
for (my $i = $#contents; $i > 0; $i--) {
if ($contents[$i] =~ /magnus-internal\/php/g) {
close(MIME_R);
return 1;
}
}
close(MIME_R);
}
open(MIME,">>$mimeTypesFile") or $mimeTypesStatus = undef;
if (defined $mimeTypesStatus) {
addToMimeTypes(\*MIME);
print "UPDATED: $mimeTypesFile \n";
} else {
print "\nERROR: Unable to write $mimeTypesFile. \n\n";
close(MIME);
exit 1;
}
close(MIME);
chown $statInfo[4], $statInfo[5], $mimeTypesFile;
}
}
}
# -----------------------------------------------------------------------------
# addMagnusConfEntry
# Add the required magnus conf entry
# -----------------------------------------------------------------------------
sub addToMagnusConf {
my $entry;
my $FILENAME = shift;
my $phpNsapi = $phpSoName;
if (isNSAPI()) {
$entry = <<__UP_TO_THIS_POINT_;
Init fn="load-modules" shlib="$phpNsapi" shlib_flags="global|now"
funcs="php5_init,php5_close,php5_execute,php5_auth_trans"
Init fn="php5_init"
php_ini="$PHP_CONF_ROOT"
php_ini_scandir="$PHP_MODULES_CONF_ROOT"
errorString="PHP failed to initialize."
__UP_TO_THIS_POINT_
} else { # fastcgi
$entry = <<__UP_TO_THIS_POINT_;
Init fn="load-modules" shlib="$fastCGISoName"
__UP_TO_THIS_POINT_
}
print $FILENAME $entry;
}
# -----------------------------------------------------------------------------
# addMimeTypesEntry
# Add the required mime types entry
# -----------------------------------------------------------------------------
sub addToMimeTypes {
my $FILENAME = shift;
my $entry = <<__UP_TO_THIS_POINT_;
type=magnus-internal/php exts=php,php3,php4,php5
__UP_TO_THIS_POINT_
print $FILENAME $entry;
}
# -----------------------------------------------------------------------------
# addObjConfEntry
# Add the required obj conf entry
# -----------------------------------------------------------------------------
sub addToObjConf {
# setup
my $FILENAME = shift;
# On windows, replace \ with / in paths
my $l_php_root = $PHP_ROOT;
if (isWindows()) {
$l_php_root =~ s/\\/\//g;
}
my $newLibPath = "$l_php_root/lib";
my $newLibPath64 = "$l_php_root/lib/64";
my $childs = &detectDefaultChildren();
my $unixFastCGIEntry = <<__UNIX_FASTCGI_ENTRY_
<If -f \$path>
Service type="magnus-internal/php"
fn="responder-fastcgi"
app-path="$l_php_root/bin/php-cgi"
bind-path="localhost:3101"
app-env="PHPRC=$PHP_CONF_ROOT"
app-env="PHP_INI_SCANDIR=$PHP_MODULES_CONF_ROOT"
app-env="PHP_FCGI_CHILDREN=$childs"
app-env="PHP_FCGI_MAX_REQUESTS=2000"
app-env="FCGI_WEB_SERVER_ADDRS=127.0.0.1"
bucket="php-bucket"
</If>
<Else>
Service type="magnus-internal/php" fn="set-variable" error="404"
</Else>
__UNIX_FASTCGI_ENTRY_
;
my $windowsFastCGIEntry = <<__WINDOWS_FASTCGI_ENTRY_
Service type="magnus-internal/php"
fn="responder-fastcgi"
app-path="$l_php_root/php-cgi.exe"
bind-path="$INSTANCE_NAME--php_cgi"
app-env="PHPRC=$l_php_root"
app-env="PHP_FCGI_CHILDREN=$childs"
app-env="PHP_FCGI_MAX_REQUESTS=2000"
bucket="php-bucket"
__WINDOWS_FASTCGI_ENTRY_
;
my $nsapiEntry = <<__NSAPI_ENTRY_
Service type="magnus-internal/php" fn="php5_execute"
__NSAPI_ENTRY_
;
my $entry;
if (isNSAPI()) {
$entry = $nsapiEntry;
} else {
if (isWindows()) {
$entry = $windowsFastCGIEntry;
} else {
$entry = $unixFastCGIEntry;
}
}
print $FILENAME $entry;
}
# -----------------------------------------------------------------------------
# isNSAPI
# Check if SAPI is nsapi
# -----------------------------------------------------------------------------
sub isNSAPI() {
if ($SAPI =~ m/nsapi/i) {
return 1;
}
return 0;
}
# -----------------------------------------------------------------------------
# isWindows
# Check platform
# -----------------------------------------------------------------------------
sub isWindows() {
if ($OSNAME =~ m/WIN/i) {
return 1;
}
return 0;
}
# -----------------------------------------------------------------------------
# checkFilesWritable
# Check all the necessary files writable before adding the entries
# -----------------------------------------------------------------------------
sub checkFilesWritable {
exit 1 unless defined isValidFile("$INSTANCE_ROOT/$INSTANCE_NAME/config/magnus.conf");
my @TMP_OBJ_CONF_FILES = @$OBJ_CONF_FILES;
my @TMP_MIME_TYPES_FILES = @$MIME_TYPES_FILES;
while(scalar(@TMP_OBJ_CONF_FILES) > 0) {
my $objConfFile = pop(@TMP_OBJ_CONF_FILES);
exit 1 unless defined isValidFile("$objConfFile");
}
while(scalar(@TMP_MIME_TYPES_FILES) > 0) {
my $mimeTypesFile = pop(@TMP_MIME_TYPES_FILES);
exit 1 unless defined isValidFile("$mimeTypesFile");
}
}
# -----------------------------------------------------------------------------
# getValidAbsoluteFilePath
# To get the valid absolute file path
# -----------------------------------------------------------------------------
sub getValidAbsoluteFilePath {
my ($file) = @_;
if (defined $file) {
my ($fileName,$filePath,$fileNameSuffix) = fileparse("$file");
if ($fileName eq $file) {
$file = "$INSTANCE_ROOT/$INSTANCE_NAME/config/$fileName";
}
$file = undef unless defined isValidFile($file);
}
return $file;
}
# -----------------------------------------------------------------------------
# getValidAbsoluteFilePath
# Valid file check
# -----------------------------------------------------------------------------
sub isValidFile {
my ($file) = @_;
my $status = undef;
if (-e "$file") {
if (-w "$file") {
$status = 1;
} else {
print "\nERROR: $file is not writable. \n\n";
exit 1;
}
} else {
print "\nERROR: $file not found, $! \n\n";
exit 1;
}
return $status;
}
# -----------------------------------------------------------------------------
# detectDefaultChildren
# detect current architecture and come up with default values.
# set default value to a higher value on Niagara based servers.
# -----------------------------------------------------------------------------
sub detectDefaultChildren {
my $default = 2;
if ($OSNAME =~ /SOLARIS/i) {
if (-x "/bin/uname") {
my $type = qx(/bin/uname -m);
chomp($type);
$default *= 3 if ($type =~ /sun4u/i);
$default *= 6 if ($type =~ /sun4v/);
}
}
return $default;
}
# -----------------------------------------------------------------------------
# printUsage
# print the usage command
# -----------------------------------------------------------------------------
sub printUsage {
print "This script will configure a web server instance to run PHP scripts\n" .
"either as FastCGI or NSAPI \n".
"usage : \n" .
" setupPHP -instancename=<instance name> [-sapi=fastcgi|nsapi]\n" .
"Examples:\n" .
"\n".
"This below example configures Web Server to run PHP in FastCGI mode (Default)\n".
" setupPHP -instancename=https-php\n" .
"\n".
"This below example configures Web Server to run PHP in NSAPI mode\n".
" setupPHP -instancename=https-php -sapi=nsapi\n";
exit 1;
}
# -----------------------------------------------------------------------------
# printResult
# print the post setup steps
# -----------------------------------------------------------------------------
sub printResult {
#remove "https-" from the instance name and use it as the config name
my $configName = undef;
$configName = $INSTANCE_NAME;
$configName = substr($INSTANCE_NAME, 6) if ($INSTANCE_NAME =~ /^https/);
my $result = <<__UP_TO_THIS_POINT_;
Setup was sucessful.
--------------------
The following steps are necessary to make the changes to all the nodes.
(1) Start the admin server
$INSTALL_ROOT/admin-server/bin/startserv
(2) Connect to the admin server using wadm command
$INSTALL_ROOT/bin/wadm [--user=admin-user] [--password-file=admin-pswd-file] [--host=admin-host] [--port=admin-port]
(3) Pull the modified config from the node to config store
using the following command in wadm console:
pull-config --config=$configName nodehost
For Example: If the host name for the node is xyz.com then enter the command like,
pull-config --config=$configName xyz.com
(4) Deploy the new changes to all nodes using
the following command in wadm console:
deploy-config $configName
__UP_TO_THIS_POINT_
print $result;
}