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