Skip to content

Commit

Permalink
Update the apache install and related scripts to allow the vhost dire…
Browse files Browse the repository at this point in the history
…ctory to be configurable.
  • Loading branch information
patrickcarlohickman committed Jan 23, 2023
1 parent 6618d74 commit c6269f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions setup/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ SSH_EMAIL_ADDRESS=
GIT_USER_NAME=
GIT_EMAIL_ADDRESS=

# install-apache.sh
VHOST_DIRECTORY="/var/www/vhost"

# install-mysql.sh
MYSQL_ROOT_PASSWORD=
MYSQL_USER_NAME=
Expand Down
8 changes: 8 additions & 0 deletions setup/installers/install-apache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ensure_not_installed "Apache"
ensure_variable_set "WSL_USER"

readonly WSL_USER
readonly VHOST_DIRECTORY="${VHOST_DIRECTORY:-/var/www/vhost}"

log_info "Installing Apache. This may take a few minutes..."

Expand All @@ -27,6 +28,13 @@ a2enmod headers
a2enmod rewrite
a2enmod expires

log_info "Creating vhost directory."

if [[ ! -d "${VHOST_DIRECTORY}" ]]; then
mkdir -p "${VHOST_DIRECTORY}"
chmod 777 "${VHOST_DIRECTORY}"
fi

log_info "Enabling all available sites."

# Add this file so that all available sites are automatically enabled.
Expand Down
8 changes: 4 additions & 4 deletions setup/resources/apache/apache-site-stub.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<VirtualHost *:80>
ServerName stub-domain.test
ServerAlias www.stub-domain.test
DocumentRoot /var/www/vhost/stub-folder/public/
DocumentRoot stub-vhost/stub-folder/public/
Options Indexes FollowSymLinks

<Directory "/var/www/vhost/stub-folder/public/">
<Directory "stub-vhost/stub-folder/public/">
AllowOverride All
<IfVersion < 2.4>
Allow from all
Expand All @@ -31,14 +31,14 @@
<VirtualHost *:443>
ServerName stub-domain.test
ServerAlias www.stub-domain.test
DocumentRoot /var/www/vhost/stub-folder/public/
DocumentRoot stub-vhost/stub-folder/public/
Options Indexes FollowSymLinks

SSLEngine on
SSLCertificateFile "/etc/ssl/certs/ssl-cert-snakeoil.pem"
SSLCertificateKeyFile "/etc/ssl/private/ssl-cert-snakeoil.key"

<Directory "/var/www/vhost/stub-folder/public/">
<Directory "stub-vhost/stub-folder/public/">
AllowOverride All
<IfVersion < 2.4>
Allow from all
Expand Down
3 changes: 3 additions & 0 deletions setup/resources/apache/make-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ readonly NEW_SITE_DOMAIN="${1}"
readonly NEW_SITE_DIRECTORY="${2:-${1}}"
readonly NGROK_START_NAME="${3:-${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 NGROK_DIRECTORY="${NGROK_DIRECTORY:-/opt/ngrok}"
readonly NGROK_CONFIG="${NGROK_DIRECTORY}/conf/ngrok.yml"
Expand All @@ -35,6 +37,7 @@ cp "${STUB_FILE}" "${NEW_SITE_CONFIG}"

# Replace the stub placeholders with the new site values.
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}"

# Make sure the DocumentRoot directory of the new site actually exists.
Expand Down

0 comments on commit c6269f7

Please sign in to comment.