1

I have an two wordpress sites that I would like to host on the same domain. One is already up and running, the other is sitting in waiting.

Can I get the second as a subdomain, or simple within a folder, to run on the same domain (different DB) without converting to multisite?

7

Point the subdomain to the same directory as the main site, and define different settings in your wp-config.php per $_SERVER['HTTP_HOST']:

Example from my local setup:

switch ( $_SERVER['HTTP_HOST'] )
{
    case 'zzl.dev':
        $table_prefix = 'zzl_';
        $table_name   = 'zzl';
        break;

    case 'wpbuch.dev':
        $table_prefix = 'wpbuch_';
        $table_name   = 'wpbuch';
        break;

    default:
        $table_prefix  = 'wp_';
        $table_name   = 'wpdev';
        break;
}

$sub                 = '/wp-content/' . $_SERVER['HTTP_HOST'];
const WP_CONTENT_DIR = __DIR__ . $sub;
const WP_CONTENT_URL = 'http://' . $_SERVER['HTTP_HOST'] . $sub;
const DB_NAME        = $table_name;

You can change much more variables in the switch: all DB_* definitions, WP_PLUGIN_DIR and WP_PLUGIN_URL (to share the plugin list between different sites), WPLANG and so on.

  • Is this all I have to do to add a subdomain? – Mild Fuzz May 11 '11 at 10:27
  • @Mild Fuzz: Yes, I’m running several live sites with this setting, even some multisites. – fuxia May 11 '11 at 10:33
  • so this is just a case of having all themes and plugins in the same install, and just calling the different databases? Ultimately it is one install? – Mild Fuzz May 11 '11 at 10:35
  • 1
    @Mild Fuzz Yes, it is. If you update one site, the other sites are up to date too. Try it in your local setup, it’s a matter of minutes. – fuxia May 11 '11 at 10:50
  • 1
    @T.Todua Just add them in the switch statement. Albeit separate salts aren't needed locally. – fuxia Jan 10 '17 at 14:29
0

As addition to @toscho's excellent answer, I will add several things...

======== Safety ========

Always be careful with safety. If you try to use any test site in this manner (with many sites paralelly) and on that test site you'll install any crappy/suspicious plugin, which might infect whole WP-Core, then all your other sites will be under risk (although,that risk similarly exists even while you use completely separated installations). This is just a small thing, however, dont worry much about it (because worrying wont help at all).

======== Needed steps to setup on Localhost =======

To point subdomain to main WP-INSTALLATION (while just using special wp-config.php), you need to set-up Alias commands in webserver.

1) Go to ..wamp\bin\apache\apache2.4.9\conf\httpd.conf and uncomment this line: Include conf/extra/httpd-vhosts.conf

2) in extra/httpd-vhosts.conf add (just modify to your specifics. In the below example, I use already setup domain name localhost... however, you can add anything)

<VirtualHost *:80>
                    #UNCOMMENT_THIS_LINE_ONLY_WHEN_YOU_NEED_SUBFOLDER_TOO#  Alias /subdirectory_name    C:\wamp\www\wp_installation_folder
    ServerName localhost
    ServerAlias subdomain.localhost
    ServerAdmin webmaster@example.com
    DocumentRoot "C:\wamp\www\wp_installation_folder"
    ErrorLog "logs/4-error.log"
    CustomLog "logs/4-access.log" common
</VirtualHost>

3) [You dont need to do this step if you use localhost name] In case you with to use you anything other than localhost, then you should point that name in C:\Windows\system32\drivers\etc\hosts, like:127.0.0.1 myexample.org`

Restart WampServer and that's all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.