bye bye Travis
[plcapi.git] / tests / ci / setup / setup_php.sh
1 #!/bin/sh
2
3 # Has to be run as admin
4
5 # @todo make it optional to install xdebug. It is fe. missing in sury's ppa for Xenial
6 # @todo make it optional to disable xdebug ?
7
8 set -e
9
10 configure_php_ini() {
11     # note: these settings are not required for cli config
12     echo "cgi.fix_pathinfo = 1" >> "${1}"
13     echo "always_populate_raw_post_data = -1" >> "${1}"
14
15     # we disable xdebug for speed for both cli and web mode
16     phpdismod xdebug
17 }
18
19 # install php
20 PHP_VERSION="$1"
21 DEBIAN_VERSION="$(lsb_release -s -c)"
22
23 if [ "${PHP_VERSION}" = default ]; then
24     if [ "${DEBIAN_VERSION}" = jessie -o "${DEBIAN_VERSION}" = precise -o "${DEBIAN_VERSION}" = trusty ]; then
25         PHPSUFFIX=5
26     else
27         PHPSUFFIX=
28     fi
29     # @todo check for mbstring presence in php5 (jessie) packages
30     DEBIAN_FRONTEND=noninteractive apt-get install -y \
31         php${PHPSUFFIX} \
32         php${PHPSUFFIX}-cli \
33         php${PHPSUFFIX}-dom \
34         php${PHPSUFFIX}-curl \
35         php${PHPSUFFIX}-fpm \
36         php${PHPSUFFIX}-mbstring \
37         php${PHPSUFFIX}-xdebug
38 else
39     # on GHA runners ubuntu version, php 7.4 and 8.0 seem to be preinstalled. Remove them if found
40     for PHP_CURRENT in $(dpkg -l | grep -E 'php.+-common' | awk '{print $2}'); do
41         if [ "${PHP_CURRENT}" != "php${PHP_VERSION}-common" ]; then
42             apt-get purge -y "${PHP_CURRENT}"
43         fi
44     done
45
46     DEBIAN_FRONTEND=noninteractive apt-get install -y language-pack-en-base software-properties-common
47     LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
48     apt-get update
49
50     DEBIAN_FRONTEND=noninteractive apt-get install -y \
51         php${PHP_VERSION} \
52         php${PHP_VERSION}-cli \
53         php${PHP_VERSION}-dom \
54         php${PHP_VERSION}-curl \
55         php${PHP_VERSION}-fpm \
56         php${PHP_VERSION}-mbstring \
57         php${PHP_VERSION}-xdebug
58
59     update-alternatives --set php /usr/bin/php${PHP_VERSION}
60 fi
61
62 PHPVER=$(php -r 'echo implode(".",array_slice(explode(".",PHP_VERSION),0,2));' 2>/dev/null)
63
64 configure_php_ini /etc/php/${PHPVER}/fpm/php.ini
65
66 # use a nice name for the php-fpm service, so that it does not depend on php version running. Try to make that work
67 # both for docker and VMs
68 service "php${PHPVER}-fpm" stop
69 if [ -f "/etc/init.d/php${PHPVER}-fpm" ]; then
70     ln -s "/etc/init.d/php${PHPVER}-fpm" /etc/init.d/php-fpm
71 fi
72 if [ -f "/lib/systemd/system/php${PHPVER}-fpm.service" ]; then
73     ln -s "/lib/systemd/system/php${PHPVER}-fpm.service" /lib/systemd/system/php-fpm.service
74     if [ ! -f /.dockerenv ]; then
75         systemctl daemon-reload
76     fi
77 fi
78
79 # @todo shall we configure php-fpm?
80
81 service php-fpm start
82
83 # configure apache
84 a2enconf php${PHPVER}-fpm
85 service apache2 restart