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