@@ -123,38 +123,13 @@ find_version_from_git_tags() {
123123
124124# Install PHP Composer
125125addcomposer () {
126- " ${PHP_INSTALL_DIR} /bin/php " -r " copy('https://getcomposer.org/installer', 'composer-setup.php');"
126+ " ${PHP_SRC} " -r " copy('https://getcomposer.org/installer', 'composer-setup.php');"
127127 HASH=" $( wget -q -O - https://composer.github.io/installer.sig) "
128- " ${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;"
129- " ${PHP_INSTALL_DIR} /bin/php" composer-setup.php
130- " ${PHP_INSTALL_DIR} /bin/php" -r " unlink('composer-setup.php');"
131-
132- mv composer.phar " ${PHP_INSTALL_DIR} /bin/composer"
128+ " ${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;"
129+ " ${PHP_SRC} " composer-setup.php --install-dir=" /usr/local/bin" --filename=composer
130+ " ${PHP_SRC} " -r " unlink('composer-setup.php');"
133131}
134132
135- # Install PHP if it's missing
136-
137-
138- # Persistent / runtime dependencies
139- RUNTIME_DEPS=" wget ca-certificates git build-essential xz-utils"
140-
141- # PHP dependencies
142- PHP_DEPS=" libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
143-
144- . /etc/os-release
145-
146- if [ " ${VERSION_CODENAME} " = " bionic" ]; then
147- PHP_DEPS=" ${PHP_DEPS} libargon2-0-dev"
148- else
149- PHP_DEPS=" ${PHP_DEPS} libargon2-dev"
150- fi
151-
152- # Dependencies required for running "phpize"
153- PHPIZE_DEPS=" autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
154-
155- # Install dependencies
156- check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
157-
158133install_php () {
159134 PHP_VERSION=" $1 "
160135 PHP_INSTALL_DIR=" ${PHP_DIR} /${PHP_VERSION} "
@@ -216,30 +191,48 @@ install_php() {
216191 echo " xdebug.mode = debug" >> " ${XDEBUG_INI} "
217192 echo " xdebug.start_with_request = yes" >> " ${XDEBUG_INI} "
218193 echo " xdebug.client_port = 9003" >> " ${XDEBUG_INI} "
194+ }
219195
220- # Install PHP Composer if needed
221- if [[ " ${INSTALL_COMPOSER} " = " true" ]] || [[ $( composer --version) = " " ]]; then
222- addcomposer
223- fi
196+ if [ " ${PHP_VERSION} " != " none" ]; then
197+ # Persistent / runtime dependencies
198+ RUNTIME_DEPS=" wget ca-certificates git build-essential xz-utils"
224199
225- CURRENT_DIR=" ${PHP_DIR} /current"
226- if [[ ! -d " ${CURRENT_DIR} " ]]; then
227- ln -s -r " ${PHP_INSTALL_DIR} " ${CURRENT_DIR}
228- fi
200+ # PHP dependencies
201+ PHP_DEPS=" libssl-dev libcurl4-openssl-dev libedit-dev libsqlite3-dev libxml2-dev zlib1g-dev libsodium-dev libonig-dev"
229202
230- if [ " ${OVERRIDE_DEFAULT_VERSION} " = " true" ]; then
231- if [[ $( ls -l ${CURRENT_DIR} ) != * " -> ${PHP_INSTALL_DIR} " * ]] ; then
232- rm " ${CURRENT_DIR} "
233- ln -s -r " ${PHP_INSTALL_DIR} " " ${CURRENT_DIR} "
234- fi
203+ . /etc/os-release
204+
205+ if [ " ${VERSION_CODENAME} " = " bionic" ]; then
206+ PHP_DEPS=" ${PHP_DEPS} libargon2-0-dev"
207+ else
208+ PHP_DEPS=" ${PHP_DEPS} libargon2-dev"
235209 fi
236210
237- rm -rf " ${PHP_SRC_DIR} "
238- updaterc " if [[ \"\$ {PATH}\" != *\" ${CURRENT_DIR} \" * ]]; then export PATH=\" ${CURRENT_DIR} /bin:\$ {PATH}\" ; fi"
239- }
211+ # Dependencies required for running "phpize"
212+ PHPIZE_DEPS=" autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c"
240213
241- find_version_from_git_tags PHP_VERSION https://github.com/php/php-src " tags/php-"
242- install_php " ${PHP_VERSION} "
214+ # Install dependencies
215+ check_packages $RUNTIME_DEPS $PHP_DEPS $PHPIZE_DEPS
216+
217+ find_version_from_git_tags PHP_VERSION https://github.com/php/php-src " tags/php-"
218+ install_php " ${PHP_VERSION} "
219+
220+ PHP_SRC=" ${PHP_INSTALL_DIR} /bin/php"
221+ else
222+ set +e
223+ PHP_SRC=$( which php)
224+ set -e
225+ fi
226+
227+ # Install PHP Composer if needed
228+ if [[ " ${INSTALL_COMPOSER} " = " true" ]]; then
229+ if [ -z " ${PHP_SRC} " ]; then
230+ echo " (!) Could not install Composer. PHP not found."
231+ exit 1
232+ fi
233+
234+ addcomposer
235+ fi
243236
244237# Additional php versions to be installed but not be set as default.
245238if [ ! -z " ${ADDITIONAL_VERSIONS} " ]; then
@@ -253,9 +246,26 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
253246 IFS=$OLDIFS
254247fi
255248
256- chown -R " ${USERNAME} :php" " ${PHP_DIR} "
257- chmod -R g+r+w " ${PHP_DIR} "
258- find " ${PHP_DIR} " -type d -print0 | xargs -n 1 -0 chmod g+s
249+ if [ " ${PHP_VERSION} " != " none" ]; then
250+ CURRENT_DIR=" ${PHP_DIR} /current"
251+ if [[ ! -d " ${CURRENT_DIR} " ]]; then
252+ ln -s -r " ${PHP_INSTALL_DIR} " ${CURRENT_DIR}
253+ fi
254+
255+ if [ " ${OVERRIDE_DEFAULT_VERSION} " = " true" ]; then
256+ if [[ $( ls -l ${CURRENT_DIR} ) != * " -> ${PHP_INSTALL_DIR} " * ]] ; then
257+ rm " ${CURRENT_DIR} "
258+ ln -s -r " ${PHP_INSTALL_DIR} " " ${CURRENT_DIR} "
259+ fi
260+ fi
261+
262+ rm -rf " ${PHP_SRC_DIR} "
263+ updaterc " if [[ \"\$ {PATH}\" != *\" ${CURRENT_DIR} \" * ]]; then export PATH=\" ${CURRENT_DIR} /bin:\$ {PATH}\" ; fi"
264+
265+ chown -R " ${USERNAME} :php" " ${PHP_DIR} "
266+ chmod -R g+r+w " ${PHP_DIR} "
267+ find " ${PHP_DIR} " -type d -print0 | xargs -n 1 -0 chmod g+s
268+ fi
259269
260270# Clean up
261271rm -rf /var/lib/apt/lists/*
0 commit comments