#!/bin/bash
# PHP installer for Apache httpd.
###SHELLPACK preamble phpbuild-install 7.3.5
WEB_LOCATION=https://www.php.net/distributions
MIRROR_LOCATION="$WEBROOT/php/"

PHP_VERSION=7.3.5
APACHE_VERSION=2.4.39

# PHP XCache version to use for PHP 5.6
XCACHE_VERSION=3.2.0

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

###SHELLPACK sources_fetch php-${PHP_VERSION}.tar.bz2 phpbuild-${PHP_VERSION}
###SHELLPACK build_start phpbuild-${PHP_VERSION}
###SHELLPACK build_configure phpbuild-${PHP_VERSION} --with-apxs2=$SHELLPACK_SOURCES/apachebuild-${APACHE_VERSION}-installed/bin/apxs --with-mysql --with-config-file-path=$SHELLPACK_SOURCES/phpbuild-${PHP_VERSION}-installed/
###SHELLPACK make_make_install

# post build crap
cp $SHELLPACK_SOURCES/phpbuild-${PHP_VERSION}/php.ini-development $SHELLPACK_SOURCES/phpbuild-${PHP_VERSION}-installed/php.ini

printf '%s\n\t%s\n%s\n\n' '<FilesMatch "\.ph(p[2-6]?|tml)$">' 'SetHandler application/x-httpd-php' '</FilesMatch>' >> $SHELLPACK_SOURCES/apachebuild-${APACHE_VERSION}-installed/conf/httpd.conf

printf '%s\n\t%s\n%s\n' '<FilesMatch "\.phps$">' 'SetHandler application/x-httpd-php-source' '</FilesMatch>' >> $SHELLPACK_SOURCES/apachebuild-${APACHE_VERSION}-installed/conf/httpd.conf

echo Generating phpinfo.php file
echo "<?php phpinfo(); ?>" >> $SHELLPACK_SOURCES/apachebuild-${APACHE_VERSION}-installed/htdocs/phpinfo.php

WEB_LOCATION=https://xcache.lighttpd.net/pub/Releases/$XCACHE_VERSION
###SHELLPACK sources_fetch xcache-$XCACHE_VERSION.tar.gz xcache-$XCACHE_VERSION
$SHELLPACK_SOURCES/phpbuild-${PHP_VERSION}-installed/bin/phpize
###SHELLPACK build_configure xcode-${XCACHE_VERSION} --enable-xcache --with-php-config=$SHELLPACK_SOURCES/phpbuild-${PHP_VERSION}-installed/bin/php-config
###SHELLPACK make_make_install

cat xcache.ini >> $SHELLPACK_SOURCES/phpbuild-${PHP_VERSION}-installed/php.ini

echo php installed successfully
