[wp-hackers] Wordpress in Multiple Environments

Andrew Nacin wp at andrewnacin.com
Mon Jan 17 01:07:01 UTC 2011

On Sun, Jan 16, 2011 at 4:05 PM, Eddie O'Leary <eddie at teamcolab.com> wrote:

> So I am fairly sure I am bringing up an old discussion here.  Sorry if I
> am.
> I have several high traffic WordPress websites that have local, staging,
> and production environments all tied together with a git repository on
> github.
> Ideally, any changes I make locally are tested and then pushed to staging
> which will show up at staging.mysite.com.  Once the changes have been
> evaluated on staging they are pushed to the live environment.
> I am running into the traditional problem of the absolute links created by
> the WordPress media library.  I would like to be able to pull the production
> database down to staging for testing and not have to search and replace the
> database for links.
> My first thought it to create a media.mysite.com and force all my
> environments to put files there.
> Another solution I am considering is using the W3 Total Cache plugin to put
> all the media files on the Rackspace Cloud CDN.  All of our media files
> would be located in one spot, theoretically, eliminating my permalink issues
> for images and PDFs uploaded via the media library.
> I would appreciate any feedback you all have on this.

The simplest solution is to run an output buffer in staging that rewrites
any live links. Works extremely well and doesn't put any additional burden
onto the production site. It also helps in a number of other areas outside
the media library. You might want to conditionally filter the uploads stuff
anyway the same way you're filtering home and siteurl.

It could literally be as simple as this in wp-config.php:

ob_start( 'mysite_staging_links' );
function mysite_staging_links( $content ) {
   return str_replace( 'http://mysite.com/', 'http://staging.mysite.com',
$content );


More information about the wp-hackers mailing list