Multisite setup on VVV with bedrock

I am trying to setup multisite on VVV using bedrock stack, but I’m having some issues.

First I’ve added my multisite configuration in the vvv-custom.yml file as

my-multisite:
  hosts:
   - my-multisite.dev
   - site1.my-multisite.dev
   - site2.my-multisite.dev
   - site3.my-multisite.dev
  custom:
    wp_type: subdomain

I added the /my-multisitefolder to the /www folder. Inside it, I added the /provision folder with vvv-init.sh

#!/usr/bin/env bash

DOMAIN=`get_primary_host "${VVV_SITE_NAME}".dev`
DOMAINS=`get_hosts "${DOMAIN}"`

# Make a database, if we don't already have one
echo -e "\nCreating database 'wordpress_my_multisite' (if it's not already there)"
mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS wordpress_my_multisite"
mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON wordpress_my_multisite.* TO wp@localhost IDENTIFIED BY 'wp';"
echo -e "\n DB operations done.\n\n"

# Nginx Logs
mkdir -p ${VVV_PATH_TO_SITE}/log
touch ${VVV_PATH_TO_SITE}/log/error.log
touch ${VVV_PATH_TO_SITE}/log/access.log

# Domain setup
echo "Setting up ${DOMAIN} Nginx configs"
cp -f "${VVV_PATH_TO_SITE}/provision/vvv-nginx.conf.tmpl" "${VVV_PATH_TO_SITE}/provision/vvv-nginx.conf"
sed -i "s#{{DOMAINS_HERE}}#${DOMAINS}#" "${VVV_PATH_TO_SITE}/provision/vvv-nginx.conf"
echo "Finished ${DOMAIN} Nginx config setup"

echo "All done setting up ${DOMAIN}."
echo "Error logs are located at ${VVV_PATH_TO_SITE}/log/error.log"

And vvv-nginx.conf.tmpl

server {
    listen       80;
    listen       443 ssl;
    server_name  {{DOMAINS_HERE}};
    root         {vvv_path_to_site}/public_html/web;

    error_log    {vvv_path_to_site}/log/error.log;
    access_log   {vvv_path_to_site}/log/access.log;

    set          $upstream {upstream};

    # Don't try to rewrite static assets
    # Just return 404 if not found
    # The reason is pretty simple: each 404'd asset will try to pass that to WP
    # Spawning a bunch of unwanted requests and making things SLOOOOOOOW
    location ~ \.(png|jpg|css|js)$ {
        try_files $uri return 404;
    }

    include      /etc/nginx/nginx-wp-common.conf;

    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ /wp/$1 last;
        rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) /wp/$1 last;
    }

    # SECURITY : Deny all attempts to access hidden files .abcde
    location ~ /\. {
        deny all;
    }

    # PERFORMANCE : Set expires headers for static files and turn off logging.
    location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; log_not_found off; expires 30d;
    }

    # SECURITY : Deny all attempts to access PHP Files in the uploads directory
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        # SECURITY : Zero day Exploit Protection
        try_files $uri =404;
        # ENABLE : Enable PHP, listen fpm sock
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Then I installed bedrock in the /public_html folder, and modified .env file

DB_NAME=wordpress_my_multisite
DB_USER=wp
DB_PASSWORD=wp

# Optional variables
DB_HOST=localhost
DB_PREFIX=wp_

WP_ENV=development
WP_HOME=http://my-multisite.dev
WP_SITEURL=${WP_HOME}/wp

# Generate your keys here: https://roots.io/salts.html
AUTH_KEY=''
SECURE_AUTH_KEY=''
LOGGED_IN_KEY=''
NONCE_KEY=''
AUTH_SALT=''
SECURE_AUTH_SALT=''
LOGGED_IN_SALT=''
NONCE_SALT=''

Then I ran the vagrant with vagant up --provision and went to http://my-multisite.dev/wp, and installed the wordpress.

Then I added

define('WP_ALLOW_MULTISITE', true);

to application.php, and installed multisite. I got the message with the config rules, but for nginx theose should be set in the config above already.

I added

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'my-multisite.dev');

to the application.php, and in development.php, staging.php and production.php I’ve added

/**
 * Multisite
 */
define('PATH_CURRENT_SITE', "https://wordpress.stackexchange.com/");
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

After that I’ve removed the /wp from the WP_SITEURL in the .env file.

I can log in, and see the network, but the url has to contain /wp. And when I try to add new site, when I try to save it, I get 404 error from nginx.

I’ve removed /wp from the database in the options table, but no luck.

EDIT

It looks like I either need trellis installed, or this kind of thing is not easily doable. Not to mention for any kind of future maintenance, could be a nightmare. I’ll just have to find a way to set repo up with regular multisite install…

0

Leave a Comment