build on PRs; nitpicks
[plcapi.git] / tests / ci / setup / setup_php.sh
index 1144910..038de3d 100755 (executable)
@@ -2,8 +2,8 @@
 
 # Has to be run as admin
 
-# To be kept in sync with setup_php_travis.sh
-
+# @todo make it optional to install xdebug. It is fe. missing in sury's ppa for Xenial
+# @todo make it optional to install fpm. It is not needed for the cd workflow
 # @todo make it optional to disable xdebug ?
 
 set -e
@@ -37,8 +37,12 @@ if [ "${PHP_VERSION}" = default ]; then
         php${PHPSUFFIX}-mbstring \
         php${PHPSUFFIX}-xdebug
 else
-    # on GHA runners ubuntu version, php 7.4 and 8.0 seem to be preinstalled. remove them if found
-
+    # on GHA runners ubuntu version, php 7.4 and 8.0 seem to be preinstalled. Remove them if found
+    for PHP_CURRENT in $(dpkg -l | grep -E 'php.+-common' | awk '{print $2}'); do
+        if [ "${PHP_CURRENT}" != "php${PHP_VERSION}-common" ]; then
+            apt-get purge -y "${PHP_CURRENT}"
+        fi
+    done
 
     DEBIAN_FRONTEND=noninteractive apt-get install -y language-pack-en-base software-properties-common
     LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
@@ -77,6 +81,8 @@ fi
 
 service php-fpm start
 
-# configure apache
-a2enconf php${PHPVER}-fpm
-service apache2 restart
+# configure apache (if installed)
+if [ -n "$(dpkg --list | grep apache)" ]; then
+    a2enconf php${PHPVER}-fpm
+    service apache2 restart
+fi