wordpress staging enviroment

wordpress staging enviroment  using -'php,wordpress,staging'

I work for a company that does sites for the pharma industry and we often need to get legal approval before we push any changes live. So, i'd like to migrate alot of our work to a CMS enviroment, specifically wordpress but we need the ability to have a staging enviroment. Is it possible to instead of publishing a page have it publish to a staging enviroment that someone can browse as with a link as a site. so basically have 2 sites, one staging one live? any Ideas?

asked Oct 7, 2015 by pradip.bhoge
0 votes

6 Answers

0 votes

Generally speaking the above "answers" are correct, there are alternatives to wordpress that have better built-in support for staging environments and build migrations. However the suggested alternatives aren't exactly equal substitutes to the wordpress platform, so I think it's best to answer the question at hand instead.

Wordpress does not natively support hosting the same site from two different hosts. The core relies on absolute urls stored inside the database and are used in just about every aspect of the core logic. This results in a number of superfluous bugs like the 500 or so related to SSL access because they try to dynamically alter all http:// schemes to https:// on the fly.

As a result when you host on dev.example.com and migrate to staging.example.com and again to www.example.com you have to do very careful search & replace manipulations on the database export each time you switch hosts. And this causes additional problems when you find out that many popular wordpress plugins serialize the url into values in the database. So when you search & replace dev.example.com with staging.example.com the serialized data which contained the character length of the original value no longer deserializes with the new longer format. Some core contributers believe the solution to this later problem is to only ever setup staging sites with the same number of characters as the production account...

In a similar vein they also suggest swapping host mappings and only ever using the production.com url on all hosting environments. Depending on your particular use-case requirements this is probably not a valid solution if you need to provide access to off-site clients, tech-illiterate users (versus tech-literate users of course.)

But wordpress itself has a number of great features otherwise and is a very adaptive and powerful rapid development platform. As a result you can extend the core framework to do much of what you need from it. When I was presented with this situation, I had to develop a solution that was viable for all circumstances. Traditionally this problem is solved with root-relative urls, they work in cross-hosting environments, and they don't suffer from scheme changes, port changes or subdomain swapping practices that are common with staging migrations.

With this plugin: http://wordpress.org/extend/plugins/root-relative-urls/ (biased? yes, I wrote this plugin.) you get root-relative urls where it's important and dynamic hosts where root-relative urls don't work (like rss feeds.) All that remains from migrating the site to different hosts is to move the wp-config.php file outside of the www root (one level up is supported natively by wordpress.) so you can maintain different copies on different servers. Or alternatively you can use basic if-statements to distinguish hosts by server name and define key wordpress constants based on the server. In the end your content, code & data will transition seamlessly.

As a note of concern, the referenced plugins require setting write access to the wp-config.php file, a very bad practice from a security perspective for production or publicly accessible servers. Perhaps you can comfortably implement this in a restricted staging environment but then you'd need to disable and remove the plugin in production transitions.

Long story short, yes you can host wordpress in multiple host environments. The long-touted solutions are very case-specific and option-restricted because of the core architecture. But the framework is flexible enough to overcome the core deficit. This core design decision will probably change at some point in the future given the amount of effort the core developers continually spend on overcoming the cascading issues. But there are also devout defenders of the absolute url religion that will keep the practice in place for the time being. Maybe a different platform that supports server migrations natively (pick just about any of them because most do) would be a better option for you now.

answered Oct 7, 2015 by bhavin
0 votes

It's possible: Take a look at this Github Gist to see an example on how to switch environments with your wp-config.php file. Furthermore, take a look at wordpress.stackexchange to see some other Qs about this that give you a more in-depth look at the stuff you should consider.

answered Oct 7, 2015 by patilkiran.101
0 votes

Greg, An even better CMS with staging environment would be Silverstripe (silverstripe.org). This cms allows for you to browse an entire staging site.

answered Oct 7, 2015 by rajnipancholi
0 votes

I think that you can try to use some plugins. For example (fast search on official wordpress plugin repo) wp-deploy or Dev and Staging Environment Plugin (maybe outdated).

Or as alternative you can try to use different wp-config.php files - one for production and one for dev environment and switch them by checking requested url.

answered Oct 7, 2015 by param.oncemore
0 votes

If you need to use WP, and need to publish only one or several pages from staging to live site, why not implement kind of tag on pages that needed to be published (seen by live site visitors)? Simple tune up your templates to display tagged or not pages and you're done! Then you can use only one site and maintain both public-available and not-approved pages on the it.

You can as well maintain local copy of your site (stage) and have some script to upload it (at whole) to your hosting - easy to automate task. In such a case, you may want to consider render the whole site into HTML pages and upload (simple rsync) this HTMLs to hosting - the live site will be hard to break as no dynamic script will be there!

But maybe you really should not choose the WP? There are a lot of CMS that support write-approve-publish scheme.

answered Oct 7, 2015 by rolvyrf
0 votes

You can create a WordPress Staging environment with just two click with the help of this plugin: https://de.wordpress.org/plugins/wp-staging/

Disclosure: I am the author of this plugin. So ask me anything about it.

answered Oct 7, 2015 by balvant maurya