-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathphp-update.sh
More file actions
243 lines (202 loc) · 8.55 KB
/
php-update.sh
File metadata and controls
243 lines (202 loc) · 8.55 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env bash
#----------------------------------------------------------------------------------
# EngineScript - A High-Performance WordPress Server Built on Ubuntu and Cloudflare
#----------------------------------------------------------------------------------
# Website: https://EngineScript.com
# GitHub: https://github.com/Enginescript/EngineScript
# License: GPL v3.0
#----------------------------------------------------------------------------------
# EngineScript Variables
source /usr/local/bin/enginescript/enginescript-variables.txt || { echo "Error: Failed to source /usr/local/bin/enginescript/enginescript-variables.txt" >&2; exit 1; }
source /home/EngineScript/enginescript-install-options.txt || { echo "Error: Failed to source /home/EngineScript/enginescript-install-options.txt" >&2; exit 1; }
# Source shared functions library
source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh || { echo "Error: Failed to source /usr/local/bin/enginescript/scripts/functions/shared/enginescript-common.sh" >&2; exit 1; }
#----------------------------------------------------------------------------------
# Start Main Script
# Prompt for EngineScript Update
if prompt_yes_no "Do you want to update EngineScript before continuing?\nThis will ensure you have the latest core scripts and variables."; then
/usr/local/bin/enginescript/scripts/update/enginescript-update.sh 2>> /tmp/enginescript_install_errors.log
else
echo "Skipping EngineScript update."
fi
print_last_errors
debug_pause "EngineScript Update"
# Accept target version from argument (used by menu) or fall back to variables + override
if [[ -n "${1}" ]]; then
NEW_PHP_VER="${1}"
else
NEW_PHP_VER="${PHP_VER}"
fi
# Auto-detect currently installed PHP-FPM version
OLD_PHP_VER=""
for ver in 8.1 8.2 8.3 8.4 8.5; do
if [[ "${ver}" != "${NEW_PHP_VER}" ]] && dpkg -l | grep -q "php${ver}-fpm"; then
OLD_PHP_VER="${ver}"
fi
done
if [[ -z "${OLD_PHP_VER}" ]]; then
# Check if target version is already installed
if dpkg -l | grep -q "php${NEW_PHP_VER}-fpm"; then
echo "PHP ${NEW_PHP_VER} is already installed. Nothing to upgrade."
exit 0
else
echo "No existing PHP-FPM installation detected. Use php-install.sh for fresh installs."
exit 1
fi
fi
echo ""
echo "============================================================="
echo ""
echo "PHP Upgrade: Migrating from PHP ${OLD_PHP_VER} to PHP ${NEW_PHP_VER}"
echo ""
echo "============================================================="
echo ""
echo "Detected PHP ${OLD_PHP_VER} installation. Proceeding with upgrade..."
# Stop old PHP service
echo "Stopping PHP ${OLD_PHP_VER} service..."
systemctl stop "php${OLD_PHP_VER}-fpm" 2>/dev/null || true
# Install new PHP version
echo "Installing PHP ${NEW_PHP_VER}..."
# Define the PHP packages to install
php_packages="php${NEW_PHP_VER}
php${NEW_PHP_VER}-bcmath
php${NEW_PHP_VER}-common
php${NEW_PHP_VER}-curl
php${NEW_PHP_VER}-fpm
php${NEW_PHP_VER}-gd
php${NEW_PHP_VER}-imagick
php${NEW_PHP_VER}-intl
php${NEW_PHP_VER}-mbstring
php${NEW_PHP_VER}-mysql
php${NEW_PHP_VER}-redis
php${NEW_PHP_VER}-ssh2
php${NEW_PHP_VER}-xml
php${NEW_PHP_VER}-zip"
# PHP 8.5+ has opcache built-in; older versions need the separate package
php_major="${NEW_PHP_VER%%.*}"
php_minor="${NEW_PHP_VER#*.}"
if (( php_major < 8 || (php_major == 8 && php_minor < 5) )); then
php_packages="${php_packages}
php${NEW_PHP_VER}-opcache"
fi
# Install the packages with error checking
apt install -qy $php_packages 2>> /tmp/enginescript_install_errors.log || {
echo "Error: Unable to install PHP ${NEW_PHP_VER} packages. Exiting..."
exit 1
}
# Install expanded PHP packages if enabled
if [[ "$INSTALL_EXPANDED_PHP" == "1" ]]; then
echo "Installing expanded PHP ${NEW_PHP_VER} packages..."
expanded_php_packages="php${NEW_PHP_VER}-soap
php${NEW_PHP_VER}-sqlite3"
apt install -qy $expanded_php_packages 2>> /tmp/enginescript_install_errors.log || {
echo "Error: Unable to install expanded PHP ${NEW_PHP_VER} packages. Exiting..."
exit 1
}
fi
print_last_errors
debug_pause "PHP Package Installation"
# Logrotate
if [[ -f "/etc/logrotate.d/php${NEW_PHP_VER}-fpm" ]]; then
sed -i "s|rotate 12|rotate 5|g" "/etc/logrotate.d/php${NEW_PHP_VER}-fpm"
fi
# Backup PHP config
/usr/local/bin/enginescript/scripts/functions/backup/php-backup.sh 2>> /tmp/enginescript_install_errors.log
# Update PHP config with the latest EngineScript settings
/usr/local/bin/enginescript/scripts/update/php-config-update.sh 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "PHP Configuration"
# Create necessary directories and log files
mkdir -p /var/cache/opcache
mkdir -p /var/cache/php-sessions
mkdir -p /var/cache/wsdlcache
mkdir -p /var/log/opcache
mkdir -p /var/log/php
touch "/var/log/opcache/opcache.log"
touch "/var/log/php/php${NEW_PHP_VER}-fpm.log"
# Assign PHP Permissions
set_php_permissions
# Update Nginx configuration to use new PHP version
echo "Updating Nginx configuration for PHP ${NEW_PHP_VER}..."
# Update php-fpm.conf
if [[ -f "/etc/nginx/globals/php-fpm.conf" ]]; then
sed -i "s|php${OLD_PHP_VER}-fpm|php${NEW_PHP_VER}-fpm|g" "/etc/nginx/globals/php-fpm.conf"
sed -i "s|php${OLD_PHP_VER}|php${NEW_PHP_VER}|g" "/etc/nginx/globals/php-fpm.conf"
fi
# Update all nginx site configurations
for config_file in /etc/nginx/sites-available/*; do
if [[ -f "$config_file" ]]; then
sed -i "s|php${OLD_PHP_VER}-fpm|php${NEW_PHP_VER}-fpm|g" "$config_file"
sed -i "s|php${OLD_PHP_VER}|php${NEW_PHP_VER}|g" "$config_file"
fi
done
# Update phpSysInfo configuration
if [[ -f "/var/www/admin/tools/phpsysinfo/phpsysinfo.ini" ]]; then
echo "Updating phpSysInfo configuration..."
sed -i "s|php${OLD_PHP_VER}|php${NEW_PHP_VER}|g" "/var/www/admin/tools/phpsysinfo/phpsysinfo.ini"
fi
# Update admin control panel API configuration
if [[ -f "/var/www/admin/control-panel/api.php" ]]; then
echo "Updating admin control panel API configuration..."
sed -i "s|php${OLD_PHP_VER}-fpm|php${NEW_PHP_VER}-fpm|g" "/var/www/admin/control-panel/api.php"
sed -i "s|php${OLD_PHP_VER}|php${NEW_PHP_VER}|g" "/var/www/admin/control-panel/api.php"
fi
# Start new PHP service
echo "Starting PHP ${NEW_PHP_VER} service..."
systemctl enable "php${NEW_PHP_VER}-fpm" 2>> /tmp/enginescript_install_errors.log
systemctl start "php${NEW_PHP_VER}-fpm" 2>> /tmp/enginescript_install_errors.log
# Reload Nginx to pick up the new PHP configuration
echo "Reloading Nginx configuration..."
systemctl reload nginx 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "PHP Service Start"
# PHP Service Check
STATUS="$(systemctl is-active "php${NEW_PHP_VER}-fpm")"
if [[ "${STATUS}" == "active" ]]; then
echo "PASSED: PHP ${NEW_PHP_VER} is running."
echo "PHP=1" >> /var/log/EngineScript/install-log.log
else
echo "FAILED: PHP ${NEW_PHP_VER} not running. Please diagnose this issue before proceeding."
exit 1
fi
# Remove old PHP version
echo "Removing PHP ${OLD_PHP_VER} installation..."
# Stop and disable old PHP service
systemctl stop "php${OLD_PHP_VER}-fpm" 2>/dev/null || true
systemctl disable "php${OLD_PHP_VER}-fpm" 2>/dev/null || true
# Remove old PHP packages
apt purge -y php${OLD_PHP_VER}* 2>/dev/null || true
# Remove old PHP configuration directory
rm -rf "/etc/php/${OLD_PHP_VER}" 2>/dev/null || true
# Remove old PHP logrotate configuration
rm -f "/etc/logrotate.d/php${OLD_PHP_VER}-fpm" 2>/dev/null || true
# Archive old log
if [[ -f "/var/log/php/php${OLD_PHP_VER}-fpm.log" ]]; then
mv "/var/log/php/php${OLD_PHP_VER}-fpm.log" "/var/log/php/php${OLD_PHP_VER}-fpm.log.old" 2>/dev/null || true
fi
echo "PHP ${OLD_PHP_VER} has been removed."
# Cleanup
/usr/local/bin/enginescript/scripts/functions/php-clean.sh 2>> /tmp/enginescript_install_errors.log
/usr/local/bin/enginescript/scripts/functions/enginescript-cleanup.sh 2>> /tmp/enginescript_install_errors.log
print_last_errors
debug_pause "Cleanup"
# Display PHP version and modules
echo -e "\n\n=-=-=-=-=-=-=-=-=-\nPHP Info\n=-=-=-=-=-=-=-=-=-\n"
php -version
echo ""
php -m
# Final message
echo ""
echo ""
echo "============================================================="
echo ""
echo "PHP upgrade from ${OLD_PHP_VER} to ${NEW_PHP_VER} completed successfully."
echo ""
echo "Changes made:"
echo " - Installed PHP ${NEW_PHP_VER} and extensions"
echo " - Applied EngineScript configuration for PHP ${NEW_PHP_VER}"
echo " - Updated Nginx configuration"
echo " - Removed PHP ${OLD_PHP_VER} installation"
echo ""
echo "============================================================="
echo ""