904N/A# The contents of this file are subject to the terms of the 904N/A# Common Development and Distribution License (the "License"). 904N/A# You may not use this file except in compliance with the License. 904N/A# See the License for the specific language governing permissions 904N/A# and limitations under the License. 904N/A# When distributing Covered Code, include this CDDL HEADER in each 904N/A# If applicable, add the following below this CDDL HEADER, with the 904N/A# fields enclosed by brackets "[]" replaced with your own identifying 904N/A# information: Portions Copyright [yyyy] [name of copyright owner] 904N/A# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 904N/A echo "Usage: This script will update a given Web Server 7 instance's configuration" 904N/A echo " files to be able to execute PHP scripts." 904N/A echo "This script recognizes following arguments:" 904N/A echo " --installroot : Top level Sun Web Server 7 installation location. " 904N/A echo " --instancename : Name of Web Server instance (https-php) which should" 904N/A echo " be configured to execute PHP scripts. " 904N/A echo " --sapi : How should PHP runtime be loaded within Web Server 7" 904N/A echo " fastcgi (Default) or NSAPI (Optional). " 904N/A # Get user response on Web Server 7 installation location and instance name. 904N/A echo -n "Enter your Web Server installation location : " 904N/A echo -n "Enter your Web Server instance name to configure with PHP runtime: " 904N/A echo -n "How you would like Sun Web Server 7 to load PHP engine (fastcgi|nsapi) [fastcgi]: " 904N/A echo "Please try again by providing a valid Web Server 7 installation location." 904N/A echo "Please try again by providing a valid Web Server 7 installation location." 904N/A echo "Error: Invalid SAPI option is provided.Valid SAPI argument is either 'fastcgi' or 'nsapi'" 904N/A echo "Please try again by providing a valid SAPI as argument." 904N/A if [ ! -d "${WS_INSTANCEROOT}/${instance_name}" ]; then 904N/A echo " Please try again by providing a valid instance name." 904N/A # Special case, if it is NSAPI 904N/A # Invoke script to configure PHP runtime. 904N/A echo "Unable to successfully setup PHP within Web Server 7" 904N/A#------------------------------------------------------------------------------- 904N/A# This below line need to point to the start of embedded perl script. 904N/Aecho "This script will update a given Web Server 7 instance's configuration" 904N/Aecho "files to be able to execute PHP scripts." 904N/A# Verify if the program is called with necessary arguments. 904N/A # Invoked with no arguments. Try interactive. 904N/A#---------------------EOF------------------------------------------------------- 904N/A# Helper Script to configure PHP runtime environment within Web Server 7 904N/A# ----------------------------------------------------------------------------- 904N/A# Process the command line options 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A elsif ($$pLine =~ m@(.*\s+app-env=['"])(\S+)(=)(\S+)(['"].*)@) { 904N/A my ($tmp, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5); 904N/A $tmp1 = $1; $tmp2 = $2; $tmp3 = $3; $tmp4 = $4; $tmp5 = $5; 904N/A if (($tmp2 =~ m@LD_LIBRARY_PATH@) or ($tmp2 =~ m@LD_LIBRARY_PATH_64@)) { 904N/A if ($tmp4 =~ m@$PHP_ROOT/64@) { 904N/A $tmp4 =~ s@$PHP_ROOT/64@$newLibPath64@g; 904N/A elsif ($tmp4 =~ m@$PHP_ROOT/64([:].*)@) { 904N/A $tmp4 =~ s@$PHP_ROOT/64(:.*)@$newLibPath64$1@g; 904N/A elsif ($tmp4 =~ m@$PHP_ROOT([:].*)@) { 904N/A $tmp4 =~ s@$PHP_ROOT(:.*)@$newLibPath$1@g; 904N/A elsif ($tmp4 =~ m@$PHP_ROOT@) { 904N/A $tmp4 =~ s@$PHP_ROOT@$newLibPath@g; 904N/A elsif ($tmp2 =~ m@PHP_FCGI_MAX_REQUEST@) { 904N/A $tmp2 =~ s@PHP_FCGI_MAX_REQUEST@PHP_FCGI_MAX_REQUESTS@g; 904N/A $tmp = $tmp1.$tmp2.$tmp3.$tmp4.$tmp5."\n"; 904N/A $pContents->[$i] = $tmp; 904N/A open(TMPOBJ,">$tmpObjConfFile") or $tmpObjConfStatus = undef; 904N/A if (defined $tmpObjConfStatus) { 904N/A for (my $i = 0; $i < $#{@{$pContents}}; $i++) { 904N/A my $line = $pContents->[$i]; 904N/A print "UPDATED: $objConfFile \n"; 904N/A unlink("$objConfFile"); 904N/A rename("$tmpObjConfFile", "$objConfFile"); 904N/A chmod(0600, "$objConfFile"); 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A my $config = eval{XMLin("$serverXml", forcearray=>1, keyattr=>[])}; 904N/A print("\nERROR: Problem parsing the $serverXml. Not a valid xml file. \n\n"); 904N/A #get the server level mime file 904N/A $file = $config->{"mime-file"}->[0]; 904N/A $file = getValidAbsoluteFilePath($file); 904N/A push (@$MIME_TYPES_FILES, $file); 904N/A # get the server platform mode 904N/A my $mode = $config->{"platform"}->[0]; 904N/A $SERVER_64BIT_MODE = "64"; 904N/A for (my $vsCounter = 0; ${config}->{"virtual-server"}->[$vsCounter]; $vsCounter++) { 904N/A my $virutalServerElement = ${config}->{"virtual-server"}->[$vsCounter]; 904N/A #get the virtual server level mime files 904N/A for (my $mimeTypescounter = 0; ${virutalServerElement}->{"mime-file"}->[$mimeTypescounter]; $mimeTypescounter++) { 904N/A $file = ${virutalServerElement}->{"mime-file"}->[$mimeTypescounter]; 904N/A $file = getValidAbsoluteFilePath($file); 904N/A push (@$MIME_TYPES_FILES, $file); 904N/A #get the virtual server level object files 904N/A for (my $objectFilecounter = 0; ${virutalServerElement}->{"object-file"}->[$objectFilecounter]; $objectFilecounter++) { 904N/A $file = ${virutalServerElement}->{"object-file"}->[$objectFilecounter]; 904N/A $file = getValidAbsoluteFilePath($file); 904N/A push (@$OBJ_CONF_FILES, $file); 904N/A if (@$MIME_TYPES_FILES < 1) { 904N/A if (@$OBJ_CONF_FILES < 1) { 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A my $magnusConfStatus = 1; 904N/A if (defined isValidFile($magnusConfFile)) 904N/A # Get the current File Stat. 904N/A my @statInfo = stat $magnusConfFile; 904N/A # Verify if the changes already exist. 904N/A if (open(MAGNUS_R,"<$magnusConfFile")) { 904N/A my @contents = <MAGNUS_R>; 904N/A next if (/^\#/); #ignore comments; 904N/A if ((isNSAPI()) and (/shlib(.*)$phpSoName(.*)/g)) { 904N/A } elsif ((not isNSAPI()) and (/shlib(.*)$fastCGISoName(.*)/g)) { 904N/A open(MAGNUS,">>$magnusConfFile") or $magnusConfStatus = 0; 904N/A if ($magnusConfStatus == 1) { 904N/A addToMagnusConf(\*MAGNUS); 904N/A print "\n\nUPDATED: $magnusConfFile \n"; 904N/A print "\nERROR: Unable to write $magnusConfFile. \n\n"; 904N/A chown $statInfo[4], $statInfo[5], $magnusConfFile; 904N/A# ----------------------------------------------------------------------------- 904N/A# Append the OBJ_CONF_APPEND_STRING value after the <object name="default" 904N/A# directive in all object files. 904N/A# ----------------------------------------------------------------------------- 904N/A while(scalar(@$OBJ_CONF_FILES) > 0) { 904N/A my $objConfFile = pop(@$OBJ_CONF_FILES); 904N/A my $tmpObjConfStatus = 1; 904N/A if (defined isValidFile($objConfFile)) 904N/A # Get the current File Stat. 904N/A my @statInfo = stat $objConfFile; 904N/A # Verify if the changes already exist. 904N/A open(OBJ,"<$objConfFile") or $objConfStatus = undef; 904N/A if (defined $objConfStatus) { 904N/A my $escape_path = $PHP_ROOT; 904N/A $escape_path =~ s/\/(\w)/\\\/$1/g; 904N/A $escape_path =~ s/\\(\w)/\/$1/g; 904N/A my $contents = join("",@lines); 904N/A my $already_configured = undef; 904N/A if ((isNSAPI()) and ($contents =~ m/ 904N/A \s*Service\s+type="magnus-internal\/php"\s+fn="php5_execute" 904N/A $already_configured = 1; 904N/A if ((not isNSAPI()) and (($contents =~ m/ 904N/A \s*Service\s+type=[\"]magnus-internal\/php[\"] 904N/A \s*fn=[\"]responder-fastcgi[\"] 904N/A \s*app-path=[\"](.*)[\"] 904N/A /mx) and ($1 =~ m@$escape_path@))) { 904N/A $already_configured = 1; 904N/A &migrateObjConf($objConfFile, \@lines); 904N/A next if ($already_configured); 904N/A my $tmpObjConfFile = "$objConfFile"."tmp"; 904N/A open(TMPOBJ,">$tmpObjConfFile") or $tmpObjConfStatus = undef; 904N/A if (defined $tmpObjConfStatus) { 904N/A foreach my $line (@lines) { 904N/A if (($line =~ /^<Object/i) && 904N/A (($line =~ /name=default>/i) || 904N/A ($line =~ /name=default\s/i) || 904N/A ($line =~ /name="default"/i))) { 904N/A addToObjConf(\*TMPOBJ); 904N/A print "UPDATED: $objConfFile \n"; 904N/A } elsif ($line =~ /PathCheck\s+fn\s*=\s*(\S+)\s+(\S+)\s*=\s*(\S+)$/) { 904N/A if (($funcName =~ /find-index/) and ($valueName =~ /index-names/)) { 904N/A $values =~ s/[\"](\S+)[\"]/$1/; 904N/A my $newLine = <<__UP_TO_THIS_POINT_; 904N/APathCheck fn=$funcName $valueName=\"$values\" 904N/A print "\nERROR: Unable to write $objConfFile \n\n"; 904N/A unlink("$tmpObjConfFile"); 904N/A unlink("$objConfFile"); 904N/A rename("$tmpObjConfFile", "$objConfFile"); 904N/A chmod(0600, "$objConfFile"); 904N/A chown $statInfo[4], $statInfo[5], $objConfFile; 904N/A# ----------------------------------------------------------------------------- 904N/A# Append the MIME_TYPES_APPEND_STRING value at the end of 904N/A# all the mime types file. 904N/A# ----------------------------------------------------------------------------- 904N/A while(scalar(@$MIME_TYPES_FILES) > 0) { 904N/A my $mimeTypesFile = pop(@$MIME_TYPES_FILES); 904N/A my $mimeTypesStatus = 1; 904N/A if (defined isValidFile($mimeTypesFile)) { 904N/A # Get the current File Stat. 904N/A my @statInfo = stat $mimeTypesFile; 904N/A # Verify if the changes already exist. 904N/A if (open(MIME_R,"<$mimeTypesFile")) { 904N/A my @contents = <MIME_R>; 904N/A for (my $i = $#contents; $i > 0; $i--) { 904N/A if ($contents[$i] =~ /magnus-internal\/php/g) { 904N/A open(MIME,">>$mimeTypesFile") or $mimeTypesStatus = undef; 904N/A if (defined $mimeTypesStatus) { 904N/A addToMimeTypes(\*MIME); 904N/A print "UPDATED: $mimeTypesFile \n"; 904N/A print "\nERROR: Unable to write $mimeTypesFile. \n\n"; 904N/A chown $statInfo[4], $statInfo[5], $mimeTypesFile; 904N/A# ----------------------------------------------------------------------------- 904N/A# Add the required magnus conf entry 904N/A# ----------------------------------------------------------------------------- 904N/A my $phpNsapi = $phpSoName; 904N/A $entry = <<__UP_TO_THIS_POINT_; 904N/AInit fn="load-modules" shlib="$phpNsapi" shlib_flags="global|now" 904N/A funcs="php5_init,php5_close,php5_execute,php5_auth_trans" 904N/A php_ini="$PHP_CONF_ROOT" 904N/A php_ini_scandir="$PHP_MODULES_CONF_ROOT" 904N/A errorString="PHP failed to initialize." 904N/A $entry = <<__UP_TO_THIS_POINT_; 904N/AInit fn="load-modules" shlib="$fastCGISoName" 904N/A print $FILENAME $entry; 904N/A# ----------------------------------------------------------------------------- 904N/A# Add the required mime types entry 904N/A# ----------------------------------------------------------------------------- 904N/A my $entry = <<__UP_TO_THIS_POINT_; 904N/A print $FILENAME $entry; 904N/A# ----------------------------------------------------------------------------- 904N/A# Add the required obj conf entry 904N/A# ----------------------------------------------------------------------------- 904N/A # On windows, replace \ with / in paths 904N/A my $l_php_root = $PHP_ROOT; 904N/A $l_php_root =~ s/\\/\//g; 904N/A my $childs = &detectDefaultChildren(); 904N/A my $unixFastCGIEntry = <<__UNIX_FASTCGI_ENTRY_ 904N/A bind-path="localhost:3101" 904N/A app-env="PHPRC=$PHP_CONF_ROOT" 904N/A app-env="PHP_INI_SCANDIR=$PHP_MODULES_CONF_ROOT" 904N/A app-env="PHP_FCGI_CHILDREN=$childs" 904N/A app-env="PHP_FCGI_MAX_REQUESTS=2000" 904N/A app-env="FCGI_WEB_SERVER_ADDRS=127.0.0.1" 904N/A my $windowsFastCGIEntry = <<__WINDOWS_FASTCGI_ENTRY_ 904N/A bind-path="$INSTANCE_NAME--php_cgi" 904N/A app-env="PHPRC=$l_php_root" 904N/A app-env="PHP_FCGI_CHILDREN=$childs" 904N/A app-env="PHP_FCGI_MAX_REQUESTS=2000" 904N/A__WINDOWS_FASTCGI_ENTRY_ 904N/A my $nsapiEntry = <<__NSAPI_ENTRY_ 904N/A $entry = $windowsFastCGIEntry; 904N/A $entry = $unixFastCGIEntry; 904N/A print $FILENAME $entry; 904N/A# ----------------------------------------------------------------------------- 904N/A# Check if SAPI is nsapi 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A# ----------------------------------------------------------------------------- 904N/A# Check all the necessary files writable before adding the entries 904N/A# ----------------------------------------------------------------------------- 904N/Asub checkFilesWritable { 904N/A my @TMP_OBJ_CONF_FILES = @$OBJ_CONF_FILES; 904N/A my @TMP_MIME_TYPES_FILES = @$MIME_TYPES_FILES; 904N/A while(scalar(@TMP_OBJ_CONF_FILES) > 0) { 904N/A my $objConfFile = pop(@TMP_OBJ_CONF_FILES); 904N/A exit 1 unless defined isValidFile("$objConfFile"); 904N/A while(scalar(@TMP_MIME_TYPES_FILES) > 0) { 904N/A my $mimeTypesFile = pop(@TMP_MIME_TYPES_FILES); 904N/A exit 1 unless defined isValidFile("$mimeTypesFile"); 904N/A# ----------------------------------------------------------------------------- 904N/A# getValidAbsoluteFilePath 904N/A# To get the valid absolute file path 904N/A# ----------------------------------------------------------------------------- 904N/Asub getValidAbsoluteFilePath { 904N/A my ($fileName,$filePath,$fileNameSuffix) = fileparse("$file"); 904N/A if ($fileName eq $file) { 904N/A $file = undef unless defined isValidFile($file); 904N/A# ----------------------------------------------------------------------------- 904N/A# getValidAbsoluteFilePath 904N/A# ----------------------------------------------------------------------------- 904N/A print "\nERROR: $file is not writable. \n\n"; 904N/A print "\nERROR: $file not found, $! \n\n"; 904N/A# ----------------------------------------------------------------------------- 904N/A# detect current architecture and come up with default values. 904N/A# set default value to a higher value on Niagara based servers. 904N/A# ----------------------------------------------------------------------------- 904N/Asub detectDefaultChildren { 904N/A if ($OSNAME =~ /SOLARIS/i) { 904N/A $default *= 3 if ($type =~ /sun4u/i); 904N/A $default *= 6 if ($type =~ /sun4v/); 904N/A# ----------------------------------------------------------------------------- 904N/A# print the usage command 904N/A# ----------------------------------------------------------------------------- 904N/A print "This script will configure a web server instance to run PHP scripts\n" . 904N/A "either as FastCGI or NSAPI \n". 904N/A " setupPHP -instancename=<instance name> [-sapi=fastcgi|nsapi]\n" . 904N/A "This below example configures Web Server to run PHP in FastCGI mode (Default)\n". 904N/A " setupPHP -instancename=https-php\n" . 904N/A "This below example configures Web Server to run PHP in NSAPI mode\n". 904N/A " setupPHP -instancename=https-php -sapi=nsapi\n"; 904N/A# ----------------------------------------------------------------------------- 904N/A# print the post setup steps 904N/A# ----------------------------------------------------------------------------- 904N/A #remove "https-" from the instance name and use it as the config name 904N/A my $configName = undef; 904N/A $configName = $INSTANCE_NAME; 904N/A $configName = substr($INSTANCE_NAME, 6) if ($INSTANCE_NAME =~ /^https/); 904N/A my $result = <<__UP_TO_THIS_POINT_; 904N/AThe following steps are necessary to make the changes to all the nodes. 904N/A(1) Start the admin server 904N/A(2) Connect to the admin server using wadm command 904N/A(3) Pull the modified config from the node to config store 904N/A using the following command in wadm console: 904N/A pull-config --config=$configName nodehost 904N/A For Example: If the host name for the node is xyz.com then enter the command like, 904N/A(4) Deploy the new changes to all nodes using 904N/A the following command in wadm console: 904N/A deploy-config $configName