-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathal2023-remi-php-add.sh
147 lines (117 loc) · 3.28 KB
/
al2023-remi-php-add.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
cd $(dirname $(readlink -f "${BASH_SOURCE:-}"))
set -ex
# Install function
install_php() {
local remiv=$1
local phpv=$2
shift 2
set +x
declare -a mods=()
for mod
do
mods+=( php${phpv}-php-${mod} )
done
set -x
dnf -q -y \
--excludepkgs='php php-* php8.*' \
--enablerepo="al2023-f34*,al2023-remi${remiv}*" \
--exclude='php-*' install "${mods[@]}"
}
# Dump function
dump_info() {
echo "[dnf history]"
dnf history
echo "[rpm packages]"
rpm -qa | sort
echo "[file context]"
semanage fcontext -lC
}
if php -v
then
echo already installed
exit 1
fi
case "$1" in
56|7[01234]|8[01])
remiv=34
;;
82)
remiv=35
;;
*)
phpv=${1:?"Usage: $0 [56|70-74|80-82]"}
exit 1
;;
esac
phpv="$1"
readonly remidir="/opt/remi/php${phpv}"
readonly tempfpfx="$(basename $0 .sh)-$(date +'%Y%m%d')"
# Dump before
tempf=$(mktemp -t ${tempfpfx}-before-XXXXX.tmp)
dump_info > ${tempf}
echo "### before --> ${tempf}"
# Install
if ! rpm -q distribution-gpg-keys
then
dnf -q -y install distribution-gpg-keys
fi
install_php ${remiv} ${phpv} \
cli common fpm pear devel
if ! [ "${MINIMUL}" = '1' ]
then
install_php ${remiv} ${phpv} \
bcmath intl mbstring mysqlnd pdo \
pecl-igbinary pecl-imagick-im7 pecl-memcache pecl-memcached \
pecl-redis pecl-geoip pecl-imagick-im7
fi
# Register alternative
alternatives \
--install /usr/bin/php php ${remidir}/root/usr/bin/php 20 \
--slave /usr/bin/pear pear ${remidir}/root/usr/bin/pear \
--slave /usr/bin/pecl pecl ${remidir}/root/usr/bin/pecl \
--slave /usr/bin/phar.phar phar ${remidir}/root/usr/bin/phar.phar \
--slave /usr/bin/phpize phpize ${remidir}/root/usr/bin/phpize \
--slave /usr/bin/php-cgi php-cgi ${remidir}/root/usr/bin/php-cgi \
--slave /usr/bin/php-config php-config ${remidir}/root/usr/bin/php-config \
--slave /etc/php.ini php-ini /etc/opt/remi/php${phpv}/php.ini \
--slave /var/log/php-fpm php-log /var/opt/remi/php${phpv}/log/php-fpm/
# Set php-timezone
if grep -q -E '^;date\.timezone\s+=' /etc/php.ini
then
sed --follow-symlinks -i.bak -E \
'/;date\.timezone\s+=/s/^;//; /^date\.timezone\s+=/s/$/ "Asia\/Tokyo"/' \
/etc/php.ini
fi
# Change log file path
readonly etcd="/etc/opt/remi/php${phpv}"
for f in ${etcd}/php-fpm.d/www.conf ${etcd}/php-fpm.conf
do
sed --follow-symlinks -i.bak -E \
'/^(slowlog|php_admin_value|error_log)[^=]+=.+\/.+\.log$/s#/.+/(.+)$#/var/log/php-fpm/\1#' \
${f}
done
# Register php-fpm as an alias
mkdir /etc/systemd/system/php${phpv}-php-fpm.service.d || true
cat << 'EOF' >> /etc/systemd/system/php${phpv}-php-fpm.service.d/override.conf
[Install]
Alias=php-fpm.service
EOF
# Add file-context
semanage fcontext -d -t httpd_log_t /var/log/php-fpm || true
semanage fcontext -a -t httpd_log_t /var/log/php-fpm
restorecon -Rv /var/log/
# Reset systemd
systemctl daemon-reload
systemctl enable --now php${phpv}-php-fpm
# Dump after
tempf=$(mktemp -t ${tempfpfx}-after-XXXXX.tmp)
dump_info > ${tempf}
echo "### after --> ${tempf}"
# Show Information
alternatives --display php
php-config --prefix
ls -l /etc/php.ini
ls -l /var/log/php-fpm
grep -r --exclude='*.bak' -E '^[^;].+\.log$' /etc/opt/remi/
exit 0