Skip to content

Commit ae23433

Browse files
committed
Add PHP version management and build functions
1 parent a003270 commit ae23433

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

main.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,41 @@ function maybe_run_node_build() {
203203
fi
204204
}
205205

206+
function maybe_install_php_dep() {
207+
208+
VALID_PHP_VERSIONS=("7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
209+
if [[ -z "$PHP_VERSION" ]]; then
210+
echo "No PHP version specified. Skipping PHP setup."
211+
return
212+
fi
213+
214+
if [[ ! " ${VALID_PHP_VERSIONS[@]} " =~ " ${PHP_VERSION} " ]]; then
215+
echo "Invalid PHP version specified: $PHP_VERSION"
216+
echo "Valid versions are: ${VALID_PHP_VERSIONS[*]}"
217+
exit 1
218+
fi
219+
220+
apt install -y software-properties-common && \
221+
add-apt-repository ppa:ondrej/php && \
222+
apt update && \
223+
apt-get install -y php"$PHP_VERSION"-cli php"$PHP_VERSION"-curl php"$PHP_VERSION"-mbstring php"$PHP_VERSION"-xml php"$PHP_VERSION"-iconv php"$PHP_VERSION"-yaml
224+
225+
update-alternatives --set php /usr/bin/php${PHP_VERSION}
226+
}
227+
228+
function maybe_run_php_build() {
229+
230+
[[ -n "$PHP_BUILD_DIRECTORY" ]] && cd "$PHP_BUILD_DIRECTORY"
231+
[[ -n "$PHP_BUILD_COMMAND" ]] && eval "$PHP_BUILD_COMMAND"
232+
233+
if [[ -n "$PHP_BUILD_SCRIPT" ]]; then
234+
chmod +x "$PHP_BUILD_SCRIPT"
235+
./"$PHP_BUILD_SCRIPT"
236+
fi
237+
238+
update-alternatives --set php /usr/bin/php${DEFAULT_PHP_VERSION}
239+
}
240+
206241
function setup_wordpress_files() {
207242

208243
mkdir -p "$HTDOCS"
@@ -332,9 +367,11 @@ function main() {
332367
setup_hosts_file
333368
check_branch_in_hosts_file
334369
setup_ssh_access
370+
maybe_install_submodules
335371
maybe_install_node_dep
336372
maybe_run_node_build
337-
maybe_install_submodules
373+
maybe_install_php_dep
374+
maybe_run_php_build
338375
setup_wordpress_files
339376
block_emails
340377
deploy

0 commit comments

Comments
 (0)