Skip to content

Instantly share code, notes, and snippets.

@mindfullsilence
Last active February 12, 2024 20:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mindfullsilence/57b074d47d2d3e43c5962e87457b3070 to your computer and use it in GitHub Desktop.
Save mindfullsilence/57b074d47d2d3e43c5962e87457b3070 to your computer and use it in GitHub Desktop.
Root Bedrock Homestead site-type

This script will create a roots/bedrock project in your desired directory, install composer dependencies, and install wordpress via the wp-cli tool. Works with mailhog.

For global homestead installations (not per-project installs)

Place the sh file in Homestead/scripts/site-types/

In your Homestead.yaml file, use "bedrock" as the type key for a site mapping, and the value of the map key as the database. Be sure to add /web to the end of your to: key for your folder mapping. The script will generate the web folder for you. E.g.:

---
# ...

sites:
    - map: mybedrocksite.com
      to: /home/vagrant/code/mybedrocksite.com/web
      type: bedrock

databases:
    - homestead
    - mybedrocksite.com

# ...

Wordpress will be installed via wp-cli. Add your site to your hosts file:

192.168.10.10 mybedrocksite.com

Go to http://mybedrocksite.com/wp/wp-admin

Username: admin

Password: admin

#!/usr/bin/env bash
declare -A params=$6 # Create an associative array
declare -A headers=${9} # Create an associative array
declare -A rewrites=${10} # Create an associative array
paramsTXT=""
if [ -n "$6" ]; then
for element in "${!params[@]}"
do
paramsTXT="${paramsTXT}
fastcgi_param ${element} ${params[$element]};"
done
fi
headersTXT=""
if [ -n "${9}" ]; then
for element in "${!headers[@]}"
do
headersTXT="${headersTXT}
add_header ${element} ${headers[$element]};"
done
fi
rewritesTXT=""
if [ -n "${10}" ]; then
for element in "${!rewrites[@]}"
do
rewritesTXT="${rewritesTXT}
location ~ ${element} { if (!-f \$request_filename) { return 301 ${rewrites[$element]}; } }"
done
fi
if [ "$7" = "true" ]
then configureXhgui="
location /xhgui {
try_files \$uri \$uri/ /xhgui/index.php?\$args;
}
"
else configureXhgui=""
fi
block="server {
listen ${3:-80};
listen ${4:-443} ssl http2;
server_name .$1;
root \"$2\";
index index.php index.html index.htm;
charset utf-8;
$rewritesTXT
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { allow all; access_log off; log_not_found off; }
location ~ /.*\.(jpg|jpeg|png|js|css)$ {
try_files \$uri =404;
}
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
if (!-e \$request_filename) {
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ \$scheme://\$host\$uri/ permanent;
# WordPress in a subdirectory rewrite rules
rewrite ^/([_0-9a-zA-Z-]+/)?(wp-.*|xmlrpc.php) /wp/\$2 break;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php$5-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
$configureXhgui
access_log off;
error_log /var/log/nginx/$1-error.log error;
sendfile off;
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/$1.crt;
ssl_certificate_key /etc/nginx/ssl/$1.key;
}
"
echo "$block" > "/etc/nginx/sites-available/$1"
ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"
# If wp-cli is installed, try and update it
if [ -f /usr/local/bin/wp ]
then
wp cli update --stable --yes
fi
# If WP is not installed then download it
if [ -d "$2/wp" ]
then
echo "WordPress is already installed."
else
rootWebPath=`dirname $2`
# Set up files
sudo -i -u vagrant -- composer create-project roots/bedrock --no-install --no-progress -d $rootWebPath
sudo -i -u vagrant -- rsync -vua $rootWebPath/bedrock/ $rootWebPath/
sudo -i -u vagrant -- rm -rf $rootWebPath/bedrock
sudo -i -u vagrant -- rm $rootWebPath/composer.lock
sudo -i -u vagrant -- composer install --no-interaction -d $rootWebPath
# Setup dependencies
sudo -i -u vagrant -- composer require --dev wpackagist-plugin/wp-mailhog-smtp -d $rootWebPath
# Update database and url values in environment file
sudo -i -u vagrant -- sed -i 's|database_name|'$1'|g' $rootWebPath/.env
sudo -i -u vagrant -- sed -i 's|database_user|homestead|g' $rootWebPath/.env
sudo -i -u vagrant -- sed -i 's|database_password|secret|g' $rootWebPath/.env
sudo -i -u vagrant -- sed -i 's|example.com|'$1'|g' $rootWebPath/.env
# Update salt values in environment file
sudo -i -u vagrant -- sed -i "s|AUTH_KEY='generateme'|AUTH_KEY='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|SECURE_AUTH_KEY='generateme'|SECURE_AUTH_KEY='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|LOGGED_IN_KEY='generateme'|LOGGED_IN_KEY='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|NONCE_KEY='generateme'|NONCE_KEY='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|AUTH_SALT='generateme'|AUTH_SALT='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|SECURE_AUTH_SALT='generateme'|SECURE_AUTH_SALT='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|LOGGED_IN_SALT='generateme'|LOGGED_IN_SALT='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
sudo -i -u vagrant -- sed -i "s|NONCE_SALT='generateme'|NONCE_SALT='"$(openssl rand -base64 28)"'|g" $rootWebPath/.env
# UNCOMMENT THESE SUDO LINES IF YOU USE iThemes Security
# These constants are set by iThemes Security
# sudo -i -u vagrant -- sed -i "s|Config::define('DISALLOW_FILE_EDIT', true);|// Config::define('DISALLOW_FILE_EDIT', true);|g" $rootWebPath/config/application.php
# sudo -i -u vagrant -- sed -i "s|Config::define('DISALLOW_FILE_MODS', true);|// Config::define('DISALLOW_FILE_MODS', true);|g" $rootWebPath/config/application.php
# Install wordpress via wp-cli
sudo -i -u vagrant -- wp core install --url=$1 --title=$1 --admin_name=admin --admin_password=admin --admin_email=admin@$1 --path=$2/wp
sudo -i -u vagrant -- wp plugin activate wp-mailhog-smtp --path=$2/wp
# Provide user information on install
echo "WordPress has been downloaded and config file has been generated, site is installed."
echo "Login At: http://$1"
echo "Username: admin"
echo "Password: admin"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment