Skip to content

Instantly share code, notes, and snippets.

@juanmaguitar
Last active July 19, 2024 18:41
Show Gist options
  • Save juanmaguitar/96b16aeb1ef62d042fef5d5a36beaf76 to your computer and use it in GitHub Desktop.
Save juanmaguitar/96b16aeb1ef62d042fef5d5a36beaf76 to your computer and use it in GitHub Desktop.
Local Wordpress Multisite Trellis Installation
#!/usr/bin/env bash
# Config Variables
args=("$@")
SUBDOMAIN_KEY=${args[0]}
source ../site/.env
sudo sh -c "echo '192.168.50.5 $SUBDOMAIN_KEY.$DOMAIN_CURRENT_SITE' >> /etc/hosts"
#!/usr/bin/env bash
dropbox_uploader.sh download WORDPRESS/material ./material
curl -# -SL https://git.io/vVzAr > composer.json
composer update & composer install
{
"name": "roots/bedrock",
"type": "project",
"license": "MIT",
"description": "A modern WordPress stack",
"homepage": "https://roots.io/bedrock/",
"authors": [
{
"name": "Scott Walkinshaw",
"email": "[email protected]",
"homepage": "https://github.com/swalkinshaw"
},
{
"name": "Ben Word",
"email": "[email protected]",
"homepage": "https://github.com/retlehs"
}
],
"keywords": [
"bedrock", "roots", "wordpress", "stack", "composer", "vagrant", "wp"
],
"support": {
"issues": "https://github.com/roots/bedrock/issues",
"forum": "https://discourse.roots.io/category/bedrock"
},
"config": {
"preferred-install": "dist"
},
"repositories": [
{
"type": "package",
"package": {
"name": "gavick/perfetta",
"type": "wordpress-theme",
"version": "1.5",
"dist": {
"type": "zip",
"url": "material/gk_perfetta.zip"
}
}
},
{
"type": "package",
"package": {
"name": "gavick/portofolio",
"type": "wordpress-theme",
"version": "1.5",
"dist": {
"type": "zip",
"url": "material/gk_portofolio.zip"
}
}
},
{
"type": "package",
"package": {
"name": "custom/folly",
"type": "wordpress-theme",
"version": "1",
"dist": {
"type": "zip",
"url": "material/folly.zip"
}
}
},
{
"type": "package",
"package": {
"name": "custom/rokophoto",
"type": "wordpress-theme",
"version": "1.0.7",
"dist": {
"type": "zip",
"url": "material/rokophoto-lite.1.0.7.zip"
}
}
},
{
"type": "package",
"package": {
"name": "custom/silvia",
"type": "wordpress-theme",
"version": "1.0.4",
"dist": {
"type": "zip",
"url": "material/silvia.1.0.4.zip"
}
}
},
{
"type": "package",
"package": {
"name": "custom/wp-migrate-db-pro",
"type": "wordpress-plugin",
"version": "1.5.5",
"dist": {
"type": "zip",
"url": "material/wp-migrate-db-pro-1.5.5.zip"
}
}
},
{
"type": "package",
"package": {
"name": "custom/wp-migrate-db-pro-media-files",
"type": "wordpress-plugin",
"version": "1.4.3",
"dist": {
"type": "zip",
"url": "material/wp-migrate-db-pro-media-files-1.4.3.zip"
}
}
},
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
"require": {
"php": ">=5.5",
"composer/installers": "~1.0.12",
"vlucas/phpdotenv": "^2.0.1",
"johnpbloch/wordpress": "4.4.2",
"oscarotero/env": "^1.0",
"roots/wp-password-bcrypt": "1.0.0",
"wpackagist-plugin/jetpack": "~3",
"wpackagist-plugin/wpro": "~1",
"wpackagist-plugin/sendgrid-email-delivery-simplified": "~1",
"wpackagist-plugin/authy-two-factor-authentication": "~2",
"wpackagist-plugin/social-networks-auto-poster-facebook-twitter-g": "3.5.3",
"wpackagist-plugin/wordpress-importer": "0.6.1",
"gavick/perfetta": "~1",
"gavick/portofolio": "~1",
"custom/folly": "~1",
"custom/rokophoto": "1.0.7",
"custom/silvia": "1.0.4",
"custom/wp-migrate-db-pro": "1.5.5",
"custom/wp-migrate-db-pro-media-files": "1.4.3"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.5.1"
},
"extra": {
"installer-paths": {
"web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
"web/app/plugins/{$name}/": ["type:wordpress-plugin"],
"web/app/themes/{$name}/": ["type:wordpress-theme"]
},
"wordpress-install-dir": "web/wp"
},
"scripts": {
"test": [
"vendor/bin/phpcs --ignore=web/wp/,vendor/ -n -s ."
]
}
}

Step 1

Make sure all dependencies have been installed before moving on:

Step 2

Create a recommended structure for trellis

myexample.com/     # → Root folder for the project
├── trellis/        # → Your clone of this repository
└── mysite/        # → A Bedrock-based WordPress site
    └── web/
        ├── app/  # → WordPress content directory (themes, plugins, etc.)
        └── wp/   # → WordPress core (don't touch!)

by doing...

1- Create a new project directory named myexample.com:

mkdir myexample.com && cd myexample.com

2- Clone Trellis to a trellis folder:

git clone --depth=1 [email protected]:roots/trellis.git && rm -rf trellis/.git

3- Clone Bedrock to a mysite folder:

git clone --depth=1 [email protected]:roots/bedrock.git mysite && rm -rf mysite/.git

4- Install the Ansible Galaxy roles:

cd trellis && ansible-galaxy install -r requirements.yml

These changes are based on the instructions at https://roots.io/trellis/docs/installing-trellis/

Step 3

Customize the configuration files for setting the local development enviroment by doing (from trellis directory)

curl -# -SL https://git.io/vVzap | bash -s myexample

This command does some changes at the following files:

  • group_vars/all/users.yml
  • group_vars/development/vault.yml
  • group_vars/development/wordpress_sites.yml

These changes are based on the instructions at:

w/ some modifications on my own to solve some issues i've found in the way

Step 4

Launch the virtual machine (from trellis directory) with

vagrant up

and visit the main site of the wordpress network at http://myexample.local

Step 5

Log in with admin:admin and create a new site in the network called test.myexample.local

Add manually the following line to /etc/hosts

192.168.50.5    test.myexample.local

Or just do (to add it automatically) from trellis directory

curl -# -SL https://git.io/vVzpH | bash -s test

Visit the new site of the network at http://test.myexample.local

Step 6

Download local .zip files, set composer.json and install dependencies (plugins and themes) by doing (from site directory)

curl -# -SL https://git.io/vVzpy | bash 
#!/usr/bin/env bash
# Config Variables
args=("$@")
KEY_SITE=${args[0]}
# Magic...
echo "Processing: group_vars/all/users.yml"
sed -i -e 's/admin_user: admin/admin_user: root/g' group_vars/all/users.yml
rm -rf group_vars/all/*.yml-e
echo "Processing: group_vars/development/vault.yml"
sed -i -e "s/ example.com\:/ $KEY_SITE.com\:/g" group_vars/development/vault.yml
rm -rf group_vars/development/*.yml-e
# set "wordpress_sites.yml" configuration
echo "Processing: group_vars/development/wordpress_sites.yml"
cat <<EOF > group_vars/development/wordpress_sites.yml
wordpress_sites:
$KEY_SITE.com:
site_hosts:
- $KEY_SITE.local
local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
admin_email: info@$KEY_SITE.local
multisite:
enabled: true
subdomains: true
ssl:
enabled: false
cache:
enabled: false
env:
wp_home: http://$KEY_SITE.local
wp_siteurl: http://$KEY_SITE.local/wp
wp_env: development
db_name: ${KEY_SITE}_dev
db_user: ${KEY_SITE}_dbuser
db_password: ${KEY_SITE}_dbpassword
domain_current_site: $KEY_SITE.local # required
EOF
# add multisite params to "application.php" configuration
echo "Processing: ../site/config/application.php"
cat <<EOF >> ../site/config/application.php
/* Multisite */
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true); // Set to false if using subdirectories
define('DOMAIN_CURRENT_SITE', env('DOMAIN_CURRENT_SITE'));
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
EOF
echo "Custom Config Finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment