Can I run a second wordpress site as a subdomain without using multisite?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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 ..wampbinapacheapache2.4.9confhttpd.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:wampwwwwp_installation_folder
    ServerName localhost
    ServerAlias subdomain.localhost
    ServerAdmin <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="423527202f233136273002273a232f322e276c212d2f">[email protected]</a>
    DocumentRoot "C:wampwwwwp_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:Windowssystem32driversetchosts, like:127.0.0.1 myexample.org`

Restart WampServer and that’s all


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x