WordPress.org

Ready to get started?Download WordPress

Forums

Using WordPress for a commercial site - no staging options? (6 posts)

  1. jentorme
    Member
    Posted 4 years ago #

    I like WP and am considering it for a commercial site. In order to do this I enabled a hack and I want to get the opinion of WP pros on here as to whether this is the right way to do it and whether there's a better way.

    My concern was about maintaining both a live production server and a staging server for tests, using the same database. Most CMS-backed sites I've worked on have had the live production server plus a development and/or staging server, which is run locally, so you can test plugins, mods, themes, and everything else that you don't want to do on the live production server.

    I was surprised to see that information on how to do this really isn't in the Codex. I did a search and found a few recent (within the past year) questions that were entirely unanswered, and then this: http://codex.wordpress.org/Running_a_Development_Copy_of_WordPress

    But that answer only works for old versions of WP!

    The answer I found was to add the following to wp-config.php:

    $currenthost = $_SERVER['HTTP_HOST'];
    $mypos = strpos($currenthost, 'localhost');
    if ($mypos === false) {
    define('WP_HOME','LIVEURL');
    define('WP_SITEURL','LIVEURL');
    } else {
    define('WP_HOME','STAGINGURL');
    define('WP_SITEURL','STAGINGURL');

    When I do that, everything is fabulous. I have copies of the site locally and on the live server, and both of them work. We can change the themes, plugins, php code and everything on the staging server, test it out, and when we're ready just upload it to live.

    My question for all you WP experts here: any problems with how I'm doing it? Is this the right way? Is there a better way?

    Thanks!

  2. Samuel B
    moderator
    Posted 4 years ago #

    works well for me

  3. jentorme
    Member
    Posted 4 years ago #

    samboll,

    Thanks for the assurance. As far as I know, that code above just comes from some WP blog out there. It's not in the docs. But it works great, and the ability to have a prod/devel server is pretty important for a commercial site. So if this is indeed the right way to do it, then, shouldn't we:

    1) add this info to the Codex

    2) add the code to wp-config.php in the actual distribution, with an option to turn it on

    I think this should really be a feature included in WP itself. If the user selects "Use a staging / development / production server" option, then the values for STAGINGURL and LIVEURL are plugged into the above.

    jen

  4. Samuel B
    moderator
    Posted 4 years ago #

    1) add this info to the Codex

    log in to the codex and do it

  5. jentorme
    Member
    Posted 4 years ago #

    Wait, you mean like *me* show other people how to do it and add something to the Codex?

    Ok, done!

    Interestingly enough, when I followed the link on that first post, this issue was addressed. But the longer code sample put in the Codex didn't work for me, so I added my solution as an alternate.

    I love this trick! Actually, I can't imagine how anyone runs a commercial site without it. So I hope this stops being a "hack" and becomes a feature pretty soon...

  6. Wildo
    Member
    Posted 4 years ago #

    Thanks so much for this. I have been having no luck with XAMPP.

    Question: could someone provide the point by point steps for implementing this solution? eg,

    • where in the wp-config.php file?
    • is it in the wp-config.php of a currently live site or in an unzipped wordpress installation on my computer?
    • do I add exactly as above without change?
    • what do I enter in my browser to find my development site.
    • anything else I'm missing that may help?

    Many thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic