Velmont Tech

Musings about video, html, tech and linux

Howto use subdomain WordPress Multisite 3.x (3.0 and 3.1) without dashboard site?

with 26 comments

So I wanted to log in to write about how to set up WordPress 3.x multisite to work with subdomains but the main site NOT running WordPress. And just there I had to fix some more problems, but now I’m able to log in, everything seems to be working.

It was not that easy, I couldn’t really find any good guides on how to do this, so I’ve burned incredibly much time on it. But I will explain my setup here, so that I may remember it later.

Actually; I got it working in WordPress 3.0, but then 3.1 came, and the new Network Admin broke, so I couldn’t log in to the site.

My setup (what I want to do)

  • I have a site; example.com, where I run a django site (or whatever else that’s NOT WordPress).
  • I want to have subdomain WordPress Multisite install, so I want myblog.example.com and yourblog.example.com.
  • I also want to have custom domains where I own it, so instead of using yourblog.example.com, I want to use yourblog.net.

So those three points should be easily doable, at least it sounds like an easy and nice requirement. Well, it was not so easy, but hopefully it’ll be easier with this guide.

Obviously you need to install WordPress, and set it up to be a Multisite-install. I’ll refer the normal steps here, but use the Create A Network instructions on the WordPress codex for a more fleshed out guide.

If you use the Codex-guide or have already set up WordPress Multiuser, add the two lines from my step 5 and start from step 8.

HOWTO

  1. Setup a normal WordPress blog. You know this. Install it normally. I set mine up as wp.example.com, this will be my dashboard site (so, NOT example.com like the normal Multisite setup). Update it, if there’s updates for it (I had one, probably because I set nn_NO as language in WPLANG).

  2. When done, open up wp-config.php and add the following line just before “That’s all …”

    define('WP_ALLOW_MULTISITE', true);
    
  3. Go to Admin -> Tools -> Network. Choose subdomain, it will say like site1.wp.example.com and site2.wp.example.com, we’ll just have to fix that later.

  4. Ignore Wildcard DNS error. Make blogs.dir:

    mkdir wp-content/blogs.dir
    sudo chown www-data wp-content/blogs.dir
    
  5. Replace the WP_ALLOW_MULTISITE in your wp-config.php with the following (the last two lines are different from a normal multisite install):

    define( 'MULTISITE', true );
    define( 'SUBDOMAIN_INSTALL', true );
    $base = '/';
    define( 'DOMAIN_CURRENT_SITE', 'wp.example.com' );
    define( 'PATH_CURRENT_SITE', '/' );
    define( 'SITE_ID_CURRENT_SITE', 1 );
    define( 'BLOG_ID_CURRENT_SITE', 1 );
    
    define( 'NOBLOGREDIRECT', 'http://example.com' );
    $cookie_domain = '.example.com';
    

    PS In my current install, I did something very wrong, I didn’t make the dashboard site first, and so I had to change BLOG_ID_CURRENT_SITE to 9.

  6. If you use apache, add this to your .htaccess-file:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]
    

    However, if you’re like me, and use nginx, I use this rule to enable WordPress Multisite:

    location / {
        index  index.html index.htm index.php;
        rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
        if (!-e $request_filename) {
            rewrite ^.+/?(/wp-.*) $1 last;
            rewrite ^.+/?(/.*\.php)$ $1 last;
            rewrite ^(.+)$ /index.php?q=$1 last;
        }
    }
    
    location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|ogv|ogg)$
    {
        rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|ogv|ogg))$ /wp-includes/ms-files.php?file=$1 last;
        expires 30d;
        break;
    }
    
  7. Press the “login again” button on the install (or just login again :P).

  8. Install my plugin, Remove Domain Part (Direct download). All it does is to remove .wp. from the domains so that site1.wp.example.com becomes site1.example.com on blog installation (when you choose “New site”).

    1. If you use something else than .wp., you need to change it in the REMOVE_DOMAIN_PART definition in the plugin.

    2. Network Activate the plugin (if you don’t use fontend signups, you may choose to only activate it on the main site).

  9. Install WordPress MU Domain Mapping, follow the install instructions. Short version:

    1. Link sunrise.php (or merge if you’ve got it from before) to the wp-content folder. > ln -s plugins/wordpress-mu-domain-mapping/sunrise.php wp-content/
    2. Add define( 'SUNRISE', 'on' ); to wp-config.php.
    3. Network Activate it…
  10. And now for the small hack that will make domain mapping work again with our setup. Open up your wp-content/sunrise.php, and add this elseif to the last if-block:

    elseif ( isset($cookie_domain) )
        define( 'COOKIE_DOMAIN', $cookie_domain );
    
  11. Log in, go into Network Admin and set up Domain Mapping. The domains themselves you can map from the site admin pages, under Tools.


And now everything should work.

No related posts.

Written by Odin Omdal Hørthe

April 3rd, 2011 at 2:11 pm

Posted in Tips/techinques

Tagged with , , , ,

26 Responses to 'Howto use subdomain WordPress Multisite 3.x (3.0 and 3.1) without dashboard site?'

Subscribe to comments with RSS or TrackBack to 'Howto use subdomain WordPress Multisite 3.x (3.0 and 3.1) without dashboard site?'.

  1. Hei Odin

    Great post!. Your setup is quite like mine. I am interested in having subdomains, and having custom domains pointing to some of them. (Wheter the main site is WP or static pages doesn’t matter to me)

    In step 4, you say “Ignore Wildcard DNS error”. Does that mean that this will work, even if the server is not configured to accept DNS wildcards?

    Kjetil

    12 Apr 11 at 8:23

  2. Kjetil: Thanks!

    Yes, it will work without DNS wildcard. I will put in a wildcard later, but right now I do this to add a new domain:

    1. Add a DNS CNAME mypage.example.com to the server
    2. Register «mypage.wp.example.com» in WordPress (autofixed to mypage.example.com)
    3. (optional) DNS CNAME on mypage.com, and add that in Custom Domain

    Odin Omdal Hørthe

    12 Apr 11 at 8:46

  3. i followed the tutorials, downloaded the plugin, replaced “.wp.” in the script to “mysubdomain” and “example.com” to my “domain.com”

    everything seems to work fine, except when i try to create a new site, i get this error: Warning: Missing argument 2 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 3 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 4 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 5 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Missing argument 6 for remove_domain_part() in /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php on line 17

    Warning: Cannot modify header information – headers already sent by (output started at /home8/donmedpo/public_html/multisite/wpm/wp-content/plugins/removedomainpart.php:17) in /home8/donmedpo/public_html/multisite/wpm/wp-includes/pluggable.php on line 897

    Pierre

    26 Jun 11 at 14:46

  4. Pierre: Hey!

    You’re not supposed to change anything in the plugin. REMOVE_DOMAIN_PART is supposed to be .wp. if your “main site” is named wp.domain.com.

    If you actually installed your first site to mysubdomain.domain.com then you could change .wp. to .mysubdomain., but that is only if that is your “main site”.

    Did you catch that? It’s a bit mind-bending :-)


    But the rest of the errors seem like your version of WordPress expects something else being sent from wpmu-function. Can you tell me the WordPress-version you are running? I’ll try to look into it.

    Odin Omdal Hørthe

    26 Jun 11 at 15:11

  5. my version is 3.1.3

    Pierre

    26 Jun 11 at 15:47

  6. Hmm. OK, I’ll try to provoke and try finding the same error. But I have the same version. :-)

    Odin Omdal Hørthe

    26 Jun 11 at 15:58

  7. pls do try to help me, i will be very grateful.

    Pierre

    26 Jun 11 at 16:07

  8. Pierre: OK, I made a version 1.1, I think I’ve fixed the problem! :D

    I found out that you have to tell WP how many arguments you need. And, well, I only really use one of the arguments, so I just changed to that.

    Odin Omdal Hørthe

    26 Jun 11 at 16:39

  9. that is great news. how can i download the version 1.1?

    Pierre

    26 Jun 11 at 17:02

  10. Pierre: All the links are updated; you can just find it as you found the old one. :-) It’s linked here.

    Odin Omdal Hørthe

    26 Jun 11 at 17:09

  11. checked the script from the site thrice to confirm, compared it with the old one. 100% identical.

    http://tech.velmont.net/wp-content/plugins/remove_domain_part.txt

    even still has version 1.0

    Pierre

    26 Jun 11 at 17:16

  12. Pierre: It’s there allright, your browser has just cached it for 30 days. You need to press CTRL+F5 or something like it.

    Anyway, I’ll send it to your email as well.

    Odin Omdal Hørthe

    26 Jun 11 at 17:23

  13. well.. i cant even begin to thank you for your support. it works perfectly. Good work man. keep it up

    Pierre

    26 Jun 11 at 17:34

  14. Odin, allow me to bug u some more… plugin works great, but it seems its conditional.

    when superadmin creates a site in the dashboard, the x.wp.domain.com becomes x.domain.com just as the plugin is supposed to make it.

    it gets bad when a user signs up for a site at the front end (/wp-signup.php). the plugin does not strip the “.wp.” part of the url. typing “x.domain.com” redirects you to “domain.com”

    any work around for that?

    Pierre

    26 Jun 11 at 18:41

  15. Pierre: Hey. I never use that feature, but I tried it now.

    However, I didn’t find what you were saying to hold when I tested it; this happened;

    New site signup (for user): write new site (your x), click enter. “Hooray, you’re new site is ok”, and it gives me the wrong addresses x.wp.domain.com, but that is impossible for me to fix through the API for WordPress. So I can’t fix that with a plugin, have to change core to do that.

    Anyway, that’s a similar fault as the other one. Unfixable. But when I actually go to x.domain.com, everything works as it should.

    Have I misunderstood the problem? Are things different at your place? Maybe I can test directly at your site if the registrations are open?

    Odin Omdal Hørthe

    26 Jun 11 at 22:37

  16. perhaps you can try it urself and see… signup link: http://multisite.donmedpost.com/wp-signup.php

    after signup, x.donmedpost.com doesnt work but x.multisite.donmedpost.com works. (where x is the subdomain domain u choose)

    I will like to state that the plugin works super without any glitch as far as i can tell when the subdomain is created from the superadmin panel.

    One more thing in the superadmin dashbord, under sites, it is possible to edit the site info of sites created through the front end and strip the “.multisite.” part of the url (“.wp.” in your tutorial). perhaps there could be a script to automate that job…?? just hoping it will be a piece of cake for someone with your extensive knowledge.. ;)

    Pierre

    27 Jun 11 at 6:28

  17. any luck with the test so far?

    Pierre

    28 Jun 11 at 6:45

  18. Pierre: OK. Remove Domain Part 1.2 now rewrites emails to take away the “.wp.” (or in your case “.multisite.”).

    It should also properly activate the blogs registered from the frontend.

    HOWEVER; a new requirement for such frontend signups; you must Network Activate the plugin for that to work.

    Odin Omdal Hørthe

    28 Jun 11 at 8:35

  19. Done that and it works! great work.

    one teeny tiny problem. when someone sign up for a site, after the the whole process, the person is given a link. the link has x.wp.domain.com. the link will not work. because of the “.wp.” part in the link. Surely when the the person types x.domain.com, the blog appears. but wordpress still provides the automated “x.wp.domain.com” is there anyway to edit that? and secondly on sign up page, wordpress writes beside the subdomain box “.wp.domain.com” – it misleads the person to think the url of the blog will be “x.wp.domain.com” a Remove Domain Part 1.3 will be lovely. :)

    Pierre

    28 Jun 11 at 10:41

  20. Pierre: The parts of the signup:

    1. Signup, it says you will get an adress + wp.domain.com (BUG)
    2. Signup, when finished a page says “you have to activate”, on this page the link to your site is x.wp.domain.com (BUG)
    3. Activation email, the first link goes to wp.domain.com/activate (CORRECT) the second link go to x.domain.com (CORRECT)
    4. When activated, the two links to your site and login are x.domain.com (CORRECT)
    5. You get an email saying the site is set up, and it has x.domain.com as URLs (CORRECT)

    I tested it on your installation, and it works the same there. Am I correct, you are talking about the bugs 1. and 2., the rest is working right?

    I’ll look at that later, need to do some other stuff now :-)

    Odin Omdal Hørthe

    28 Jun 11 at 10:48

  21. all true…

    the rest are all working. one more bug. after activation, it gives you a page ” Your account is now active! Your site at x.wp.donmedpost.com is active. You may now log in to your site using your chosen username of “x” ….. “

    that link is a bug too.

    In general your plugin is SUPER. good work man. when u get time, u can take a look at the minor bugs. thanks a lot for your help. If you got any new plugins, feel free to drop the link in my inbox so i can try it out. will check ur blog regularly too… :-)

    Pierre

    28 Jun 11 at 11:13

  22. Hi Odin.

    Thanks a lot for your post, that’s a lot of help indeed and saved me a huge amount of time.

    I’m left with only one problem… when I try to access “test.mysite.com/wp-admin” I get a 404 error.

    “test.mysite.com” works perfectly, but I can’t get to the dashboard of the site.

    Here is my .htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    uploaded files
    
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]

    Thanks again for your help!

    Cassio

    1 Dec 11 at 13:45

  23. Hmm. I wonder how many that actually read this tutorial/howto, since it’s only the ones who have problems who post here as a comment. Would be nice if it is actually helping many :-)

    Cassio: Hey :-) Can you either send me the address by email (odin.omdal at google’s email service), or put it here?

    Maybe your server isn’t set up correctly? test.mysite.com/wp-admin/index.php <= does that work?

    Odin Omdal Hørthe

    5 Dec 11 at 0:01

  24. How to open wordpress subdomain dashboard? I already add subdomain (Ex) http://www.subdomain.domain.com in wordpress,but when I open dashboard of it.They said the page not found.how can I do? (I used wordpress version 3.2.1)

    Benjamin.vcj

    22 Dec 11 at 12:24

  25. Benjamin: As always, it’s really hard to say without looking at the real site and seeing what it does.

    You’re saying that the normal site works (subdomain.example.com), but not the admin panel there (subdomain.example.com/wp-admin/)?

    Or do you mean that the dashboard SITE doesn’t work, that is wp.example.com?

    It’d be easier to look at the site itself. And www.subdomain.example.com is something you’d have to put in extra code to handle. You need to redirect it to subdomain.example.com from nginx or apache. Or you need to do major trickery to get the www to work.

    If I were you, I’d skip the www, it’s just irritating anyway (obviously you should always redirect them to the real domain).

    Odin Omdal Hørthe

    23 Dec 11 at 11:29

  26. Upgrading WP Domain Mapping will now kill the sunrise. Or maybe not for everyone, but I’ve actually symlinked my sunrise.php to the plugin’s.

    Maybe I should try to get some way to specify cookie_domain upstreamed…

    Odin Omdal Hørthe

    16 Feb 12 at 12:26

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.