Multisite Archives - Justin Silver https://www.justinsilver.com/tag/multisite/ Technology, Travel, and Pictures Fri, 01 Mar 2019 18:00:40 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.1 https://www.justinsilver.com/wp-content/uploads/2013/06/cropped-apple-touch-icon-160x160.png Multisite Archives - Justin Silver https://www.justinsilver.com/tag/multisite/ 32 32 502 Bad Gateway on NGINX with BuddyPress https://www.justinsilver.com/technology/linux/502-bad-gateway-nginx-buddypress/?utm_source=rss&utm_medium=rss&utm_campaign=502-bad-gateway-nginx-buddypress https://www.justinsilver.com/technology/linux/502-bad-gateway-nginx-buddypress/#comments Thu, 28 Mar 2013 02:12:53 +0000 http://justin.ag/?p=2983 I recently switched over from Apache to NGINX for my WordPress hosting, and it was surprisingly easier than I expected. Alongside the W3 Total Cache plugin to handle my minification and object/db caching my...

The post 502 Bad Gateway on NGINX with BuddyPress appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

I recently switched over from Apache to NGINX for my WordPress hosting, and it was surprisingly easier than I expected. Alongside the W3 Total Cache plugin to handle my minification and object/db caching my sites are blazing fast. The one problem I did run into was random 502 errors on some pages. The fix was to update the server{} block of nginx.conf to include parameters for proxy_* buffers and fastcgi_* buffers. In my configuration this is in an include file so that it can be easily imported into all the different servers that I run on this host.

My full configuration for WordPress (which also supports pretty URLs, MultiSite, BuddyPress, and WooCommerce) is:

# Use the Nginx-Helper plugin to automatically generate this map
# https://wordpress.org/plugins/nginx-helper/
map $http_host $blogid {
    default                         0;
    include /var/www/example.com/html/wp-content/uploads/nginx-helper/map.conf;
}

server {
    # accept connections on all IP addresses, port 80
    listen                          80;

    # listing on SSL port 443?
    #listen                         443 ssl;
    #ssl                            on;
    #ssl_certificate                /etc/nginx/ssl/example.com.crt;
    #ssl_certificate_key            /etc/nginx/ssl/example.com.key;

    # name this server
    server_name                     example.com www.example.com;

    # set the root folder for web files
    root                            /var/www/example.com/html;

    # MultiSite Configuration ################

        # avoid PHP readfile()
        location ^~ /blogs.dir {
            internal;
            alias                       /var/www/com.rovair/www/html/wp-content/blogs.dir;
            access_log                  off;
            log_not_found               off;
            expires                     max;
        }

        # WPMU files
        location ~ ^/files/(.*)$ {
            try_files                   /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1;
            access_log                  off;
            log_not_found               off;
            expires                     max;
        }

    # End MultiSite Configuration ############

    index                           index.php;

    # serve static files and send everything else to WordPress
    try_files $uri $uri/ /index.php?$args;

    # send PHP requests to fastcgi (uses spawn-fcgi)
    location ~ \.php$ {
        # zero-day exploit defense.
        try_files                       $uri =404;

        # performance boosts for PHP
        sendfile                        on;
        tcp_nopush                      off;
        keepalive_requests              0;

        # proxy buffers - no 502 errors!
        proxy_buffer_size               128k;
        proxy_buffers                   4 256k;
        proxy_busy_buffers_size         256k;

        # fastcgi buffers - no 502 errors!
        fastcgi_buffering               on;
        fastcgi_buffer_size             16k;
        fastcgi_buffers                 16 16k;

        # max timeouts (should match php.ini)
        fastcgi_connect_timeout         600s;
        fastcgi_send_timeout            600s;
        fastcgi_read_timeout            600s;

        # index page
        fastcgi_index                   index.php;

        # pass request to fastcgi/php-cgi via spawn-fcgi
        fastcgi_pass                    localhost:53217;

        # default fastcgi_params
        include                         fastcgi_params;

        # override fastcgi_params
        fastcgi_param                   SERVER_NAME $host;
        fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;

        break;
    }
}

Some quick notes:

  • The various buffer parameters prevent semi-random 502 errors, for example trying to logout of a BuddyPress site always resulted in a 502, and remaining logged in
  • try_files will test to see if a file/directory exists and if not passes it off to WordPress’ index.php file – the ?$args at the end is important for WordPress to receive the entire $_REQUEST

The post 502 Bad Gateway on NGINX with BuddyPress appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/linux/502-bad-gateway-nginx-buddypress/feed/ 1
Activate WP SlimStat Dashboard Widgets in WordPress Multisite https://www.justinsilver.com/technology/wordpress/activate-wp-slimstat-dashboard-widgets-in-wordpress-multisite/?utm_source=rss&utm_medium=rss&utm_campaign=activate-wp-slimstat-dashboard-widgets-in-wordpress-multisite https://www.justinsilver.com/technology/wordpress/activate-wp-slimstat-dashboard-widgets-in-wordpress-multisite/#comments Wed, 07 Nov 2012 00:24:26 +0000 http://justin.ag/?p=2807 If you have WordPress Multisite installed and the WP SlimStat plugin activated network wide, the optional WP SlimStat Dashboard widgets won’t be available to you. The problem is that the dashboard widgets file is...

The post Activate WP SlimStat Dashboard Widgets in WordPress Multisite appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

If you have WordPress Multisite installed and the WP SlimStat plugin activated network wide, the optional WP SlimStat Dashboard widgets won’t be available to you. The problem is that the dashboard widgets file is using get_option('active_plugins') to see if the plugin is active, and if it’s active network wide it won’t be in this array – it will be in get_site_options('active_sitewide_plugins'). Rather than modifying the WP SlimStat plugin files (which will be overwritten when you upgrade), I recommend adding the following filter to a custom functions plugin to add the value to the array before it is read by the dashboard widgets. Using functions.php in your theme is out because get_option() in the WP SlimStat plugin is called before it loads. You could also use a Must Use Plugin placed in /wp-content/mu-plugins.

There is some checking to make sure this only happens on the admin index page, but that’s just to be safe – it really shouldn’t have any adverse affects on your site except a few edge cases.

function activate_slimstat_dashboard_multisite($plugins){
	// only run on multisite admin index screens.
	// $pagenow isn't available, so we have to preg_match the SCRIPT_NAME (should work for subdirectories)
	if (is_multisite() && preg_match("~/wp-admin/index\.php$~", $_SERVER['SCRIPT_NAME'])){
		$slimstat_plugin = 'wp-slimstat/wp-slimstat.php';
		// check if plugin is active network wide and if so add to site plugins
		if (array_key_exists($slimstat_plugin, get_site_option('active_sitewide_plugins', array())))
			$plugins[] = $slimstat_plugin;
	}
	return $plugins;
}
add_filter( 'option_active_plugins', 'activate_slimstat_dashboard_multisite' );

The post Activate WP SlimStat Dashboard Widgets in WordPress Multisite appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/wordpress/activate-wp-slimstat-dashboard-widgets-in-wordpress-multisite/feed/ 1
WP_HOME and WP_SITEURL for WordPress Multisite Development & Migration https://www.justinsilver.com/technology/wordpress/wp_home-and-wp_siteurl-for-wordpress-multisite-development-migration/?utm_source=rss&utm_medium=rss&utm_campaign=wp_home-and-wp_siteurl-for-wordpress-multisite-development-migration Fri, 19 Oct 2012 15:10:35 +0000 http://justin.ag/?p=2677 I needed to be able to copy the wp_options table(s) to my development environment as they contain configurations that are needed. To overcome the issue of not being able to set the WP_SITEURL and...

The post WP_HOME and WP_SITEURL for WordPress Multisite Development & Migration appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

I needed to be able to copy the wp_options table(s) to my development environment as they contain configurations that are needed. To overcome the issue of not being able to set the WP_SITEURL and WP_HOME values in WordPress MultiSite, I wrote a custom filter to replace the _config_wp_siteurl() and _config_wp_home() functions that are available for non-multisite installs that is included in a plugin that is available network-wide and is configured in wp-config.php. I am then able to copy all of the database tables except wp_site and wp_blogs to a local database.

I highly recommend the URL Token Replacement Techniques for WordPress 3.0 article by Chris Murphy to help handle URLs in your content.

This example assumes a subdomain multisite install, with a domain of example.com and two subdomains, www.example.com and second.example.com. The local development URLs will be www.example.local and second.example.local respectively.

WordPress Multisite Updates

Database Changes:

Update the domain value in wp_site:

UPDATE wp_site
SET domain = 'example.local'
WHERE domain = 'example.com';

Update the domain value(s) in wp_blogs:

UPDATE wp_blogs
SET domain = 'www.example.local'
WHERE domain = 'www.example.com';
UPDATE wp_blogs
SET domain = 'second.example.local'
WHERE domain = 'second.example.com';

Plugin Code:

The following plugin should be installed network-wide.

<?php
/*
Plugin Name: MultiSite WP_HOME and WP_SITEURL
Plugin URI: http://doublesharp.com/
Description: Allows wp_options values to be overwritten in wp-config.php for MultiSite
Author: Justin Silver
Version: 1.0
Author URI: http://doublesharp.com
License: GPL2
*/

/**
 * Replace this site's WP_SITEURL URL based on constant values
 *
 * @param String  $url - The original URL
 * @return String - The replaced URL if overridden in wp-config.php
 */
function _ms_config_wp_siteurl( $url = '' ) {
    if (is_multisite()):
        global $blog_id, $current_site;
        $cur_blog_id = defined( 'BLOG_ID_CURRENT_SITE' )?
            BLOG_ID_CURRENT_SITE :
            1;
        $key = ( $blog_id!=$cur_blog_id )? $blog_id.'_' : '';
        $constant = 'WP_'.$key.'SITEURL';
        if ( defined( $constant ) )
            return untrailingslashit( constant($constant) );
    endif;
    return $url;
}
add_filter( 'option_siteurl', '_ms_config_wp_siteurl' );

/**
 * Replace this site's WP_HOME URL based on constant values
 *
 * @param String  $url - The original URL
 * @return String - The replaced URL if overridden in wp-config.php
 */
function _ms_config_wp_home( $url = '' ) {
    if (is_multisite()):
        global $blog_id;
        $cur_blog_id = defined( 'BLOG_ID_CURRENT_SITE' )?
            BLOG_ID_CURRENT_SITE :
            1;
        $key = ( $blog_id!=$cur_blog_id )? $blog_id.'_' : '';
        $constant = 'WP_'.$key.'HOME';
        if ( defined( $constant ) )
            return untrailingslashit( constant($constant) );
    endif;
    return $url;
}
add_filter( 'option_home',    '_ms_config_wp_home'    );
?>

Configure wp-config.php:

Add new constants to wp-config.php. The primary site should use the standard WP_HOME and WP_SITEURL and the tertiary URLs should use WP_{$blog_id}_HOME and WP_{$blog_id}_SITEURL where {$blog_id} is the numeric blog ID value that you want to replace from the wp_blogs table.

define('WP_HOME',      'http://www.example.local');
define('WP_SITEURL',   'http://www.example.local');
define('WP_2_HOME',    'http://secondary.example.local');
define('WP_2_SITEURL', 'http://secondary.example.local');

This post is the result of a question that I originally asked on StackOverflow – Override WP_SITEURL and WP_HOME for WordPress Multisite – and ultimately answered with the help of Chris Murphy.

The post WP_HOME and WP_SITEURL for WordPress Multisite Development & Migration appeared first on Justin Silver.

]]>