From 59682aa9b355923c42f26f66d92abb3d157b66c6 Mon Sep 17 00:00:00 2001 From: apolopena <3060702+apolopena@users.noreply.github.com> Date: Sun, 23 Jan 2022 14:19:00 -0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20REFACTOR:=20generation=20o?= =?UTF-8?q?f=20php-fpm.conf=20for=20https://github.com/apolopena/gitpod-la?= =?UTF-8?q?ravel-starter/issues/156?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gp/bash/helpers.sh | 5 +++-- .gp/bash/php.sh | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.gp/bash/helpers.sh b/.gp/bash/helpers.sh index d02ae7be..7178d36a 100644 --- a/.gp/bash/helpers.sh +++ b/.gp/bash/helpers.sh @@ -375,8 +375,9 @@ laravel_ui_version() { fi } -# Dynamically Configures php-fpm based on currently used bersion of PHP -# NOTE: If you want to configure this further do it elsewhere or open a PR +# php_fpm_conf +# Configures the php-fpm.conf depending on PHP version ($1) and the output file ($2) +# NOTE: If you want to configure this further parse the result of this from elsewhere. php_fpm_conf() { [[ -z $1 || -z $2 ]] && 2>&1 echo " ERROR: utils.sh --> php_fpm_conf(): Bad args. Script aborted" && exit 1 echo "\ diff --git a/.gp/bash/php.sh b/.gp/bash/php.sh index e3cd055e..9cbd5ace 100644 --- a/.gp/bash/php.sh +++ b/.gp/bash/php.sh @@ -108,6 +108,29 @@ configure_php() { fi } +configure_apache() { + local loc=/var/log/apache2 + mv /tmp/apache2.conf /etc/apache2/apache2.conf + sudo chown gitpod:gitpod "$loc/access.log" "$loc/error.log" "$loc/other_vhosts_access.log" + return $? +} + +generate_php_fpm_conf() { + local php_fpm_conf_path="$GITPOD_REPO_ROOT/.gp/conf/php-fpm/php-fpm.conf" + local active_php_version= + active_php_version="$(. /tmp/utils.sh php_version)" + local msg="Autogenerating php-fpm configuration file for PHP $active_php_version in $php_fpm_conf_path" + echo " $msg" | tee -a $log + bash /tmp/helpers.sh php_fpm_conf "$active_php_version" "$php_fpm_conf_path" + local ec=$? + if [[ $ec -eq 0 ]]; then + echo " SUCCESS: $msg" | tee -a $log + else + 2>&1 echo " ERROR: $msg" | tee -a $log + return 1 + fi +} + keep_existing_php() { local msg1 msg2= [[ $1 == 'fallback' ]] && @@ -125,15 +148,6 @@ keep_existing_php() { exit 0 } -configure_apache() { - local loc=/var/log/apache2 - mv /tmp/apache2.conf /etc/apache2/apache2.conf - sudo chown gitpod:gitpod "$loc/access.log" "$loc/error.log" "$loc/other_vhosts_access.log" - return $? -} - - - # BEGIN: MAIN echo "BEGIN: php.sh" | tee -a $log php_version=$(. /tmp/utils.sh parse_ini_value /tmp/starter.ini PHP version) @@ -170,9 +184,14 @@ if ! configure_php; then 2>&1 echo " php.sh was aborted: Optional php installation failed to be configured!" | tee -a $log && exit 1 fi +# Generate php-fpm.conf +if ! generate_php_fpm_conf; then + 2>&1 echo " WARNING: php-fpm.conf was not autogenerated. PHP for nginx may not work properly." | tee -a $log +fi + # Configure Apache if ! configure_apache; then - 2>&1 echo " WARNING: Apache configuration failed. Apache may not work properly." | tee -a $log && exit 1 + 2>&1 echo " WARNING: Apache configuration failed. Apache may not work properly." | tee -a $log fi echo "END: php.sh" | tee -a $log