-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
executable file
·149 lines (121 loc) · 4.36 KB
/
install.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
147
148
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
##############
# display help
##############
function printUsage() {
echo -e "PHP-SPX profiler installer. needs sudo!"
echo -e "usage sudo ./install.sh <version> <type>"
echo -e "\t <version>: one of 5.6, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 or 8.2"
echo -e "\t <type>: one of fpm or cli"
echo -e "Ex1: sudo ./setup_spx 7.3 cli"
echo -e "Ex2: sudo ./setup_spx 7.4 fpm"
}
############################
# validate input arguments
############################
if [ -z "$1" ]; then
echo -e "no php version provided, aborting!"
printUsage
exit 1
fi
if [ -z "$2" ]; then
echo -e "no php type provided, aborting!"
printUsage
exit 1
fi
hasRoot=$( groups $(whoami) | grep 'root\|sudo')
if [ -z "${hasRoot}" ]; then
echo -e "This script requires sudo permissions, aborting!"
printUsage
exit 1
fi
PHP_VERSION=$1
PHP_TYPE=$2
############################
# find the correct paths
############################
PHP_INI_DIR="/etc/php/${PHP_VERSION}/${PHP_TYPE}"
ls -al $PHP_INI_DIR || (echo "can not locate PHP_INI_DIR at $PHP_INI_DIR. Aborting!" && exit 1)
PHP_BIN="php${PHP_VERSION}"
which php${PHP_VERSION} -v || (echo "can not locate $PHP_BIN. Defaulting to 'php'!" && PHP_BIN="php")
PHP_EXTENSION_DIR=$($PHP_BIN -i | grep extension_dir | cut -d " " -f 5 | head -1)
ls -al $PHP_EXTENSION_DIR || (echo "can not locate PHP_EXTENSION_DIR at $PHP_EXTENSION_DIR. Aborting!" && exit 1)
######## BUILD ARGUMENTS###########
#>>>> PHP_VERSION
#>>>> PHP_TYPE
#>>>> PHP_INI_DIR
#>>>> PHP_BIN
#>>>> PHP_EXTENSION_DIR
###################################
echo "started building using:"
echo "PHP_VERSION=$PHP_VERSION"
echo "PHP_TYPE=$PHP_TYPE"
echo "PHP_INI_DIR=$PHP_INI_DIR"
echo "PHP_BIN=$PHP_BIN"
echo "PHP_EXTENSION_DIR=$PHP_EXTENSION_DIR"
##########################################
# cleanup any [eventual] old setups
##########################################
rm -rf "${PHP_INI_DIR}/conf.d/20-spx.ini"
rm -rf "${PHP_EXTENSION_DIR}/spx.so"
apt remove -y "php${PHP_VERSION}-dev"
apt autoremove -y
apt update
apt install -y make git "php${PHP_VERSION}-dev" "zlib1g-dev"
rm -rf ./php-spx
##########################################
# Clone PHP-SPX, latest version
##########################################
git clone https://github.com/NoiseByNorthwest/php-spx.git
cd "php-spx" || exit 1
git checkout release/latest
########################################################
# Build PHP-SPX with the correct current PHP configs
########################################################
#make distclean
phpize${PHP_VERSION} –clean
./configure "--with-php-config=/usr/bin/php-config${PHP_VERSION}"
make
########################################################
# Move built modules to the corresponding paths
########################################################
rm -rf "${PHP_EXTENSION_DIR}/spx.so" "${PHP_EXTENSION_DIR}/spx.la"
chmod 644 ./modules/spx.so ./modules/spx.la
cp ./modules/spx.so ./modules/spx.la "${PHP_EXTENSION_DIR}"
rm -rf ./modules/spx.so ./modules/spx.la
ls -al "${PHP_EXTENSION_DIR}/spx.so"
########################################################
# Create PHP-SPX extension INI file
########################################################
touch "${PHP_INI_DIR}/conf.d/20-spx.ini"
echo "extension=${PHP_EXTENSION_DIR}/spx.so" > "${PHP_INI_DIR}/conf.d/20-spx.ini"
echo "process.dumpable = yes" >> "${PHP_INI_DIR}/php.ini"
echo "spx.http_enabled=1" >> "$PHP_INI_DIR/conf.d/20-spx.ini"
echo "spx.http_key="dev"" >> "$PHP_INI_DIR/conf.d/20-spx.ini"
echo 'spx.http_ip_whitelist="*"' >> "$PHP_INI_DIR/conf.d/20-spx.ini"
########################################################
# Eventually restart the FPM
########################################################
if [ $PHP_TYPE == "fpm" ]; then
if [ $(ps --no-headers -o comm 1) == "systemd" ]; then
systemctl restart php${PHP_VERSION}-fpm
fi
fi
########################################################
# And we are done
########################################################
rm -rf ./php-spx
echo -e "PHP SPX Profiler successfully installed for php ${PHP_TYPE} ${PHP_VERSION}. Checking the extension from the loaded modules.."
if [ ${PHP_TYPE} == "fpm" ]
then
"php-${PHP_TYPE}${PHP_VERSION}" -m | grep SPX
else
"php${PHP_VERSION}" -m | grep SPX
fi
echo -e "Please refer to https://github.com/NoiseByNorthwest/php-spx for how to use it."