aboutsummaryrefslogtreecommitdiff
path: root/src/php/install.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/php/install.sh')
-rwxr-xr-xsrc/php/install.sh110
1 files changed, 60 insertions, 50 deletions
diff --git a/src/php/install.sh b/src/php/install.sh
index 0c577b1..48140e1 100755
--- a/src/php/install.sh
+++ b/src/php/install.sh
@@ -123,38 +123,13 @@ find_version_from_git_tags() {
# Install PHP Composer
addcomposer() {
- "${PHP_INSTALL_DIR}/bin/php" -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
+ "${PHP_SRC}" -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
- "${PHP_INSTALL_DIR}/bin/php" -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- "${PHP_INSTALL_DIR}/bin/php" composer-setup.php
- "${PHP_INSTALL_DIR}/bin/php" -r "unlink('composer-setup.php');"
-
- mv composer.phar "${PHP_INSTALL_DIR}/bin/composer"
+ "${PHP_SRC}" -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
+ "${PHP_SRC}" composer-setup.php --install-dir="/usr/local/bin" --filename=composer
+ "${PHP_SRC}" -r "unlink('composer-setup.php');"
}
-# Install PHP if it's missing
-
-
-# Persistent / runtime dependencies
-RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"
-
-# PHP dependencies
-PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
-
-. /etc/os-release
-
-if [ "${VERSION_CODENAME}" = "bionic" ]; then
- PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
-else
- PHP_DEPS="${PHP_DEPS} libargon2-dev"
-fi
-
-# Dependencies required for running "phpize"
-PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
-
-# Install dependencies
-check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
-
install_php() {
PHP_VERSION="$1"
PHP_INSTALL_DIR="${PHP_DIR}/${PHP_VERSION}"
@@ -216,30 +191,48 @@ install_php() {
echo "xdebug.mode = debug" >> "${XDEBUG_INI}"
echo "xdebug.start_with_request = yes" >> "${XDEBUG_INI}"
echo "xdebug.client_port = 9003" >> "${XDEBUG_INI}"
+}
- # Install PHP Composer if needed
- if [[ "${INSTALL_COMPOSER}" = "true" ]] || [[ $(composer --version) = "" ]]; then
- addcomposer
- fi
+if [ "${PHP_VERSION}" != "none" ]; then
+ # Persistent / runtime dependencies
+ RUNTIME_DEPS="wget ca-certificates git build-essential xz-utils"
- CURRENT_DIR="${PHP_DIR}/current"
- if [[ ! -d "${CURRENT_DIR}" ]]; then
- ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
- fi
+ # PHP dependencies
+ PHP_DEPS="libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
- if [ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]; then
- if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${PHP_INSTALL_DIR}"* ]] ; then
- rm "${CURRENT_DIR}"
- ln -s -r "${PHP_INSTALL_DIR}" "${CURRENT_DIR}"
- fi
+ . /etc/os-release
+
+ if [ "${VERSION_CODENAME}" = "bionic" ]; then
+ PHP_DEPS="${PHP_DEPS} libargon2-0-dev"
+ else
+ PHP_DEPS="${PHP_DEPS} libargon2-dev"
fi
- rm -rf "${PHP_SRC_DIR}"
- updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"
-}
+ # Dependencies required for running "phpize"
+ PHPIZE_DEPS="autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
-find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
-install_php "${PHP_VERSION}"
+ # Install dependencies
+ check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
+
+ find_version_from_git_tags PHP_VERSION https://github.com/php/php-src "tags/php-"
+ install_php "${PHP_VERSION}"
+
+ PHP_SRC="${PHP_INSTALL_DIR}/bin/php"
+else
+ set +e
+ PHP_SRC=$(which php)
+ set -e
+fi
+
+# Install PHP Composer if needed
+if [[ "${INSTALL_COMPOSER}" = "true" ]]; then
+ if [ -z "${PHP_SRC}" ]; then
+ echo "(!) Could not install Composer. PHP not found."
+ exit 1
+ fi
+
+ addcomposer
+fi
# Additional php versions to be installed but not be set as default.
if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
@@ -253,9 +246,26 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
IFS=$OLDIFS
fi
-chown -R "${USERNAME}:php" "${PHP_DIR}"
-chmod -R g+r+w "${PHP_DIR}"
-find "${PHP_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
+if [ "${PHP_VERSION}" != "none" ]; then
+ CURRENT_DIR="${PHP_DIR}/current"
+ if [[ ! -d "${CURRENT_DIR}" ]]; then
+ ln -s -r "${PHP_INSTALL_DIR}" ${CURRENT_DIR}
+ fi
+
+ if [ "${OVERRIDE_DEFAULT_VERSION}" = "true" ]; then
+ if [[ $(ls -l ${CURRENT_DIR}) != *"-> ${PHP_INSTALL_DIR}"* ]] ; then
+ rm "${CURRENT_DIR}"
+ ln -s -r "${PHP_INSTALL_DIR}" "${CURRENT_DIR}"
+ fi
+ fi
+
+ rm -rf "${PHP_SRC_DIR}"
+ updaterc "if [[ \"\${PATH}\" != *\"${CURRENT_DIR}\"* ]]; then export PATH=\"${CURRENT_DIR}/bin:\${PATH}\"; fi"
+
+ chown -R "${USERNAME}:php" "${PHP_DIR}"
+ chmod -R g+r+w "${PHP_DIR}"
+ find "${PHP_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s
+fi
# Clean up
rm -rf /var/lib/apt/lists/*