Skip to content

Commit

Permalink
Update the make-site.sh script to require and setup the PHP version n…
Browse files Browse the repository at this point in the history
…eeded for the new site.
  • Loading branch information
patrickcarlohickman committed Jan 23, 2023
1 parent 2255908 commit c09c751
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions setup/installers/install-apache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ a2enmod ssl
a2enmod headers
a2enmod rewrite
a2enmod expires
# Enable proxy modules for php-fpm
a2enmod proxy
a2enmod proxy_fcgi

log_info "Creating vhost directory."

Expand Down
10 changes: 10 additions & 0 deletions setup/resources/apache/apache-site-stub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
</IfVersion>
</Directory>

# Enable PHP for the virtual host.
<FilesMatch \.php$>
SetHandler "proxy:unix:/opt/phpenv/versions/stub-php-version/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/stub-domain_error.log
CustomLog ${APACHE_LOG_DIR}/stub-domain_access.log combined
</VirtualHost>
Expand Down Expand Up @@ -58,6 +63,11 @@
</IfVersion>
</Directory>

# Enable PHP for the virtual host.
<FilesMatch \.php$>
SetHandler "proxy:unix:/opt/phpenv/versions/stub-php-version/var/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>

ErrorLog ${APACHE_LOG_DIR}/stub-domain_error.log
CustomLog ${APACHE_LOG_DIR}/stub-domain_access.log combined
</VirtualHost>
11 changes: 8 additions & 3 deletions setup/resources/apache/make-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
source "$(dirname "$(dirname "$(readlink -f "${0}")")")/init-resource.sh"

function usage {
echo "Usage: $(script_name) < domain > [ directory [ ngrok_start_name ] ]"
echo "Usage: $(script_name) < domain > < php_version > [ directory [ ngrok_start_name ] ]"
}

readonly NEW_SITE_DOMAIN="${1}"
readonly NEW_SITE_DIRECTORY="${2:-${1}/public}"
readonly NGROK_START_NAME="${3:-${1}}"
readonly PHP_VERSION="${2}"
readonly NEW_SITE_DIRECTORY="${3:-${1}/public}"
readonly NGROK_START_NAME="${4:-${1}}"

readonly VHOST_DIRECTORY="${VHOST_DIRECTORY:-/var/www/vhost}"
readonly SITES_DIRECTORY="/etc/apache2/sites-available"
readonly STUB_FILENAME="apache-site-stub.conf"
readonly STUB_DOMAIN_PLACEHOLDER="stub-domain"
readonly STUB_VHOST_DIRECTORY_PLACEHOLDER="stub-vhost"
readonly STUB_DIRECTORY_PLACEHOLDER="stub-folder"
readonly STUB_PHP_VERSION_PLACEHOLDER="stub-php-version"
readonly NGROK_DIRECTORY="${NGROK_DIRECTORY:-/opt/ngrok}"
readonly NGROK_CONFIG="${NGROK_DIRECTORY}/conf/ngrok.yml"
readonly STUB_FILE="$(script_dir)/${STUB_FILENAME}"
Expand All @@ -28,6 +30,8 @@ fi

ensure_root
ensure_installed "Apache"
ensure_installed "PHPENV" "PHPENV is required but is not found at ${PHPENV_ROOT} or is not loaded. If using sudo, make sure to use a login shell (sudo -i)."
ensure_installed "phpenv_version-${PHP_VERSION}" "PHP version [${PHP_VERSION}] is required but is not installed."
ensure_file_exists "${STUB_FILE}"
ensure_file_missing "${NEW_SITE_CONFIG}"

Expand All @@ -40,6 +44,7 @@ cp "${STUB_FILE}" "${NEW_SITE_CONFIG}"
sed -i "s#${STUB_DOMAIN_PLACEHOLDER}#${NEW_SITE_DOMAIN}#g" "${NEW_SITE_CONFIG}"
sed -i "s#${STUB_VHOST_DIRECTORY_PLACEHOLDER}#${VHOST_DIRECTORY}#g" "${NEW_SITE_CONFIG}"
sed -i "s#${STUB_DIRECTORY_PLACEHOLDER}#${NEW_SITE_DIRECTORY}#g" "${NEW_SITE_CONFIG}"
sed -i "s#${STUB_PHP_VERSION_PLACEHOLDER}#${PHP_VERSION}#g" "${NEW_SITE_CONFIG}"

# Make sure the DocumentRoot directory of the new site actually exists.
if [[ "$(grep -m 1 "DocumentRoot" "${NEW_SITE_CONFIG}")" =~ DocumentRoot[[:blank:]]+(.+) ]]; then
Expand Down

0 comments on commit c09c751

Please sign in to comment.