Half-Elf on Tech

Thoughts From a Professional Lesbian

Tag: multisite

  • Dumping ms-files

    Dumping ms-files

    Trash Can On It's SideNOTE: You do not, under any circumstances, have to do this to continue using WordPress Multisite. I just wanted to see if I could.

    I have been toying around with this. Since WP 3.5 doesn’t use ms-files anymore, I wanted to see how much of a pain this would be. While I was at the DMV (I now have a California Drivers License), I started sketching out the methods and possibilities for how one might do this as safely as possible, without bolluxing up your site. I got about 90% successful with it, so this is something I would never suggest you do on a massive, live site. If you compare it to what I did to move images from uploads to blogs.dir for the main site, it’s far more complex and annoying.

    Do you have to do this? Again, no! Everything will work just fine. Can you do it? Sure. Why did I? Support. I already know all the mishegas with blogs.dir, but the new location, and it’s lack of ms-files, promises other, weird, errors. I want to repeat, you don’t need to do anything. The Core Team was fantastic with the work they did to turn off ms-files for fresh 3.5 and up installs is nothing short of phenomenal. This was just to assuage my curious nature, and learn more about the way things work.

    You ready? Here we go.

    I decided to move the images at http://test.ipstenu.org/ to start with, so everything will use that as my example. This is after I played with it on a local site and got my steps mostly solid. I knew that live is always different than test, so I backed up the DB first (always, always, backup first!) and went to town.

    Move the images

    This is obvious. Move your images from blogs.dir/SITENUM/files/ to /uploads/sites/SITENUM/ (or make an alias). I went and did it via command line in the /uploads/sites/ folder, doing this:

    $ cp -r ~/public_html/wp-content/blogs.dir/10/files .
    $ mv files 10
    

    Lather, rinse, repeat. I could have scripted it, but I was working out the kinks until I had two left.

    Edit all sites

    Upload Path, Upload URL Path and Fileupload Url. You can blank them all out.(Corrected thanks to Nacin.)

    Blank me out

    Since you’re blanking it out for everyone you can probably do this via SQL, but since I was doing the sites one at a time, I did them one at a time.

    Fix the Database
    Search/replace each posts table for each site, changing /files/ to /uploads/SITENUM/

    UPDATE wp_10_posts SET post_content = REPLACE (
    post_content,
    '="http://test.ipstenu.org/files/',
    '="http://test.ipstenu.org/wp-content/uploads/sites/10/');
    

    Full Trash, ColorWhy did I do it that way? Because of this blog. I talk a lot about code here, and I know I’ve talked about moving files around before. If you don’t do that, you’re okay with a less precise search, but why bother? This works, it’s safe, and I’d use it again.

    That got annoying really fast. I went and grabbed my favorite Search And Replace for WordPress (and any other database) tool. Seriously I love that. I used that to follow up, change everything, and it actually worked really well for me.

    Another DB Fix!

    One of the changes in 3.5 was turning off rewriting. This took me forever and a day to find. After I did that, my images showed up fine, but the little buggers kept uploading to /files! Turns out it was all because of the site option ms_files_rewriting

    The way I got around this was by putting the following in my wp-config.php file:

    define( 'UPLOADBLOGSDIR', 'wp-content/uploads/sites' );

    And then I ran this in SQL to turn off ms_files_rewriting. Or so I thought. More in a second.

    INSERT INTO `my_database`.`wp_sitemeta` (`meta_id`, `site_id`, `meta_key`, `meta_value`) VALUES (NULL, '1', 'ms_files_rewriting', '0');
    

    I came up with that after reading through /wp-includes/functions.php line 1515.

    For most sites, this worked, but in my later work, I determined that it actually wasn’t working. It was ignoring this. I don’t know why, but every test I did merrily ignored this setting, so I finally growled and wrote this mu-plugin function:

    function stupid_ms_files_rewriting() {
            $url = '/wp-content/uploads/sites/' . get_current_blog_id();
            define( 'BLOGUPLOADDIR', $url );
    }
    add_action('init','stupid_ms_files_rewriting');
    

    It’s stupid simple, it’s probably not a good idea, but it works for the three sites that have the stupids.

    Finish up .htaccess.

    .htaccess, remove the ms-files.php line for ms-files, or comment it out. This is pretty simple.

    Empty TrashWhy not move the main site to /uploads/?

    Because of the way I fixed the uploadblogsdir. It defaulted everyone to /sites/ and after an hour I said fuck it.

    Any weird problems?

    Yeah, two sites (this one and my grandmothers) decided that they wanted to be repetitious and spat out URLs like this: wp-content/uploads/sites/8/sites/8/

    Since that wasn’t right at all, and I was a little too eggnoggy to parse why, I did this:

    RewriteCond %{HTTP_HOST} ^taffys\.org
    RewriteRule ^wp-content/uploads/sites/8/sites/8/(.*) /wp-content/uploads/sites/8/$1 [L,R=301]
    

    I swear I have no idea why three sites got stuck with /files/ and two more decided to double down, Vegas style, but frankly I’m pleased I got through this far on my own.

    I can’t stress enough that you do not have to do this!

  • Multisite eBooks Updated for WordPress 3.5

    Multisite eBooks Updated for WordPress 3.5

    Cat BookNo, it’s not out yet, but it is in Release Candidate land. This means that you can download and test 3.5 RC3 now to help us debug and finish up so that WP 3.5 is ready ASAP. Nacin says, don’t put this on a live site unless you’re daring. I’m running it here, which is a Multisite, so I can tell you it works.

    In preparation for all this, I’ve updated WordPress Multisite 101 and WordPress Multisite 110 for use with 3.5. Very little was needed to be done, but getting to say “Yes, you can install WP in it’s own directory!” is one of the happiest things I get to write. The only thing that’ll make me happier is the day I say “It’s easy to change the blog slug.”

    In addition to adding in the 3.5 information, each ebook has been updated to reflect other community changes, such as new plugins to help you make it through the day, and the magic of per-site-registration.

    As always, my ebooks are Pay What You Will. I suggest a $5 donation, but I also encourage you to download, read it, find value, and then come back. Sadly I can’t do that with the Kindle copies, which are priced at $7.99 in order to break even with those costs.

    Oh and the reasons you should test 3.5 before it drops:

    • You wrote a theme/plugin
    • You support people who use WP
    • You want a much better media upload interface
    • You want to give WordPress it’s own directory and run multisite
  • Multisite Login Loop

    Multisite Login Loop

    Congratulations, you’ve decided to go Multisite and added in all your lines to your config file. You’re raring to go, and the last step is to log out and back in.

    But you can’t.

    You get to the login screen, enter your credentials, and the page just refreshes. What’s on earth is going on?

    This is actually a pretty rare thing, and I was only able to reproduce it when I moved my site on the server. The fix is actually pretty easy, and there are three things to do.

    1) Edit your wp-config.php.

    Visit https://api.wordpress.org/secret-key/1.1/salt/ and get new salts/hashes. This should prompt your users to re-login and hopefully generate new cookies.

    2) Dump your cache.

    Sometimes, however, browsers are idiots and you have to flush the local cache. You shouldn’t need to dump caching plugins, since that doesn’t impact logins.

    3) Delete your cookies.

    I hate this one. Delete the cookies only for your domain if possible. Chrome hides this, but it’s doable for all sites.

    4) Check your .htaccess

    A lot of people miss this. When the directions say ‘Replace your .htaccess with this…’ what they mean is replace. And yet many people leave in the old WordPress rules. Remember to replace your .htaccess calls for WP with the correct one: Multisite .htaccess rules

    5) Check your wp-config.php again

    You need to have both define('WP_ALLOW_MULTISITE', true); and define('MULTISITE', true); in there.

    But what if you have this problem on Single Site? Do the same thing, but if you’re using CloudFlare, go check your settings. They’ve been known to cause problems with this, due to handling of redirects. Me and a coworker wasted a couple hours on that, before someone else pointed it out.

    Edited to add….

    6) Kick wp-config.php in the butt

    Tom McFarlin came up with added this to your file:

    define('ADMIN_COOKIE_PATH', '/');
    define('COOKIE_DOMAIN', '');
    define('COOKIEPATH', '');
    define('SITECOOKIEPATH', '');
    

    This kicks the cookies.

  • Switching Network Types

    Switching Network Types

    This actually isn’t hard to do, but it can be tricky to complete if you don’t remember what you started with.

    To start with, let’s say I have a multisite with subdomains: ipstenu.loc. I’ve added in two subsites, foo.ipstenu.loc and bar.ipstenu.loc. But then I decide I really wanted to have ipstenu.loc/bar and ipstenu.loc/foo instead.

    The easy part is first. I know my wp-config.php has this:

    define('WP_ALLOW_MULTISITE', true);
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    $base = '/';
    define('DOMAIN_CURRENT_SITE', 'ipstenu.loc');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE',1);
    

    All I have to change is the one line define('SUBDOMAIN_INSTALL', true); to define('SUBDOMAIN_INSTALL', false); and now I’m using sub-folders!

    But that means that foo.ipstenu.loc isn’t really valid. Amusingly, it doesn’t break anything at first, so the still will work. But once I change the .htaccess, things will get hinky, so I’m going to do the ‘hard’ part.

    Go in to Network Admin -> Sites and Edit each site that uses a subdomain and you’ll see this:

    Looks familiar, right? I’m going to change foo.ipstenu.org to ipstenu.org and the line with / becomes /foo/:

    As soon as I hit save, the site is ‘moved.’ Great! Do this for all my sites and .. wait. Now they look all ugly!

    That’s because I have to edit the .htaccess. Go to Network Admin -> Settings -> Network Setup, and copy the .htaccess from there, replace, and now it works too.

    The one last step is re-saving the permalinks in your main site, and remembering your links are about to break. What’s that now? Oh, yes, you see ipstenu.loc now gets /blog/ shoved in for any posts, so ipstenu.org/2012/postname became ipstenu.loc/blog/2012/postname. The catch here is that if you don’t resave the permalinks, they will continue to work until you do. Once you hit ‘save’ on permalinks, blog jumps in, and WordPress cheerfully redirects people for you, so you lose nothing.

    And now you know!

  • Google Apps

    Google Apps

    Google AppsI don’t like Google very much. However when my grandmother had a request for something to be added to her website, I realized Google’s email would actually be much easier for them, especially since her domain, taffys.org, is mapped to this server as a part of my Multisite network. Oh, it’s not terribly hard to make emails for her, but she wanted someone local to do that.

    There’s a minor story behind that, but the shortest version is she’s doing some totally awesome not-for-profit work with Parkinsons patients. One of the things she wants is an email, used by many people, to ‘collect’ messages like ‘I’ll be there.’ While I could do this on my site, it’s actually easier to get this up on Google, where I can tell people login to go to http://mail.google.com/a/taffys.org or http://mail.taffys.org and it’s something they know.

    I chose to do this by command line, for the experience. If I wanted to do it via cpanel and WHM, you’d go in to edit the DNS zone for the server and add in the mx records.

    MX Records

    The command dig mx taffys.org tells me what I have right now, which I knew was self referential.

    ; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5_8.5 <<>> mx taffys.org
    ;; global options:  printcmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20605
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
    
    ;; QUESTION SECTION:
    ;taffys.org.			IN	MX
    
    ;; ANSWER SECTION:
    taffys.org.		14010	IN	MX	0 taffys.org.
    
    ;; AUTHORITY SECTION:
    taffys.org.		78943	IN	NS	ns1.ipstenu.org.
    taffys.org.		78943	IN	NS	ns2.ipstenu.org.
    
    ;; ADDITIONAL SECTION:
    taffys.org.		6943	IN	A	50.28.84.96
    
    ;; Query time: 11 msec
    ;; SERVER: 69.167.128.254#53(69.167.128.254)
    ;; WHEN: Tue Nov 13 08:09:06 2012
    ;; MSG SIZE  rcvd: 104
    

    Looks like that for all my stuff. Okay, no problem, I go in and edit /var/named/taffys.org.db and find this:

    taffys.org. IN MX 0 taffys.org.
    

    Change it to this:

    ; Original
    ; taffys.org. IN MX 0 taffys.org.
    
    ; Gmail
    taffys.org.             14400   IN      MX      10 ASPMX.L.GOOGLE.COM.
    taffys.org.             14400   IN      MX      30 ASPMX2.GOOGLEMAIL.COM.
    taffys.org.             14400   IN      MX      20 ALT1.ASPMX.L.GOOGLE.COM.
    taffys.org.             14400   IN      MX      30 ASPMX4.GOOGLEMAIL.COM.
    taffys.org.             14400   IN      MX      30 ASPMX5.GOOGLEMAIL.COM.
    taffys.org.             14400   IN      MX      20 ALT2.ASPMX.L.GOOGLE.COM.
    taffys.org.             14400   IN      MX      30 ASPMX3.GOOGLEMAIL.COM.
    

    And then I ran /usr/sbin/rndc reload taffys.org to refresh it. But ... wait. Why does it still say I'm on taffys.org? Per usual, I didn't bother to change my TTL. As everyone always reminds me, if you make a change to DNS without lowering your TTL values, you're gonna have a bad time. Since I'm (rarely) in a rush for this stuff, meh. Besides, it takes 24-48 hours from changing TTL for it to be usable, and then I can make my change. Followed by waiting again, and then changing it back? DNS is pretty zippy these days. 72 hours max, and usually less, so I just don't.

    While I waited on that, I went ahead and made a Google Apps account for taffys.org. When you go to Google Apps they only show you business and education. I'm neither (though I suppose what I'm doing for Taffy would be non-profit). Really they're trying to sell, which makes sense. If you go to their pricing model, you'll see the free option. Unless you're running a business, click that.

    The rest of the directions are really straight forward, and Google shows you what to do. It's really just set up the account stuff from there out. The directions to make mail.yourdomain.com are under Create a custom web address.

    If you want to do it with a GUI, it's even easier. I went into my DNS management setup on cpanel and did this:

    Will I do this for other domains? Maybe. I think I'll be doing this for hosting going forward, since the people I host rarely (ever?) use cPanel. Congrats, Taffy! You're the first! Liv's the second.

    Now I have to fix up Taffy's site.

  • WordPress Multisite Subdomains Without Wildcards

    The easiest way to run a Multisite network with subdomains is to use wildcard subdomains, because they’ll automagically map anything.yourdomain.com to yourdomain.com and WordPress will in turn translate that for you.

    When you’re on shared hosting, you can’t do that. But don’t worry! If you’re willing to do it manually, every time you have a new subdomain, you can still have subdomains! This is really easy, if weird.

    Go to manage domains on your Panel and click on ‘Add New Domain / Sub-Domain’

    Add your subdomain as ‘mysub.yourdomain.com’ and check the box to remove www (it’s a subdomain, you don’t need it, and it causes weird issues with some plugins).

    Set the Web Directory to where you have your main domain installed (normally this will be /home/username/yourdomain.com ) – yes, I really mean exactly the same. This is what wildcards do for you, but since you don’t have it, you need to do this. It should look like this:

    That’s it! Now you just scroll down and press Fully Host This Domain and wait till it’s provisioned. Once that’s done, you can go to mysub.yourdomain.com and it will take you to yourdomain.com! Add in a subdomain within WordPress called ‘mysub’ and everything will work exactly like it should.