• Hi everybody,

    I’ve been reading several posts about creating a staging site using a secondary WordPress installation. I already did everything needed (in my opinion) to make it work, as all the posts suggests. My main guide is this one http://www.wpbeginner.com/wp-tutorials/how-to-create-staging-environment-for-a-wordpress-site/

    However for some reason the staging site is accessing the production database even though I specified a different set of parameters in wp-config.php.

    Here is my setup:

    Main WordPress root is in the /public_html/cms folder of the hosting account.
    Staging site in the /public_html/staging folder, that is a subdirectory of the main site.
    A subdomain configured in the hosting account pointing to the /public_html/staging subdirectory.

    When I access the staging site I can see it is using the wp-config.php file of the main site, not its own. I can tell this because I dumped the constants and all parameters are the main ones, no the staging ones.

    WordPress version is 4.2.5. Hosting is GoDaddy. I thought that could be some sort of database cache in GoDaddy hosting services, but I saw updated data, so I discarded the idea.

    I believe the .htaccess in the staging site may be causing the staging installation to read the main wp-config.php file, but I don’t understand why.

    Any suggestions?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @mariodlg

    Thanks for providing all these details, to help you troubleshoot the issue.

    You checked using a different db_prefix in wp-config.php
    But it’s not using wp_db prefix
    I think .htaccess redirect all calls (urls, php, db) to main site and it will take time to troubleshoot issue without knowing your server full setup
    Suggestion:

    For example, open a new staging account on a different host, a decent free stuff like hostinger.com (I’m not in any way affiliated with them – but it’s ok to make tests done it a few times) or rent a simple VPS on good folks like linode.com, digitalocean.com, ovh.com, openshift so on..).

    It’s all around 5$ for one month and you can resign at any time (some like digital ocean now have a one-push wordpress setup button and it’s done in a matter of 3 clickys). So just rent for one month and drop it, only to make tests.

    Hope it helps,

    Thread Starter mariodlg

    (@mariodlg)

    Thank you Digico for your prompt response.

    I’m not using different prefix, and the databases are exactly the same. I cloned the production one and replaced all urls and content with the new staging urls.

    Also I haven’t changed the .htaccess, that means both .htaccess are equal since the staging site is also a clone of the production one.

    Something is telling me right now that this is wrong. So I’m going to read about the .htaccess rules WordPress uses and see if I can find the culprit.

    About your suggestion on using other sites to test, I think I can replicate the problem in my local environment. The only thing I cannot replicate may be the subdomain, but I don’t see how that can be part of or causing the problem.

    Thanks again!

    @mariodlg

    You’re welcome,

    As a quick reply, what I can tell for sure is that .htaccess will spread to subfolders as in the tutorial you showed (depending apache config or nginx config). So to eliminate that potential issue, it’s not best but faster to move to another server to debug issues.

    My idea (and from quite long experience with subdomains or subfolders to test), is that it will exclude .htacess issues – for the test period. Once your staging site is working, you will move it back to like subdomain.mysite.com and probably find bugs, but already filtered.

    I already told last week here, sharing same database for 2 WP sites is not a problem, done it a dozen of times (even with one site at subdomain.digi.fr and the other at http://www.digi.fr fictional sites). What is the regular problem is: .htaccess file, DNS misconfiguration, WP-config.php with same settings, so on.

    If you still have this issue, feel free to share, I like complex issues,

    Good luck & hope it helps!

    Thread Starter mariodlg

    (@mariodlg)

    Thank you @digico

    I was able to reproduce the issue in my local environment. If I test the staging site alone in other server, everything works fine, since it is a clone of the production one. I haven’t made any changes yet.

    However, when I deploy the staging copy into a subfolder of the production one, the issue appear, even in my local environment. So here is what I’ve tried so far:

    Main site ( a few pages ) is in the root folder /
    Main WordPress root is under /cms
    Staging site (a few pages) is at /staging
    Staging WordPress root is under /staging/cms

    Main site /cms/.htaccess file content:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /cms/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/staging/
    RewriteRule . /cms/index.php [L]
    </IfModule>
    
    # END WordPress

    Staging site /staging/cms/.htaccess file content:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /staging/cms/
    RewriteRule ^staging/index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /staging/cms/index.php [L]
    </IfModule>
    
    # END WordPress

    apache.conf section for the document root:

    <Directory /home/vagrant/mysite>
    	Options Indexes FollowSymLinks
    	AllowOverride FileInfo
    	Require all granted
    </Directory>

    If looking at these files makes you realize my problem, I will be completely grateful!

    Regards!

    UPDATE:

    Forgot to mention that the issue is that the Staging site is using the wp-config.php of the main site. I’m sure of this because I set wrong parameters in the wp-config.php and the Staging site says “Database error: Error establishing a database connection”, so it is not using its own wp-config.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Staging site in a subdomain/subdirectory conflicts wp-config.php’ is closed to new replies.