[wp-hackers] WP Development & Production Sites
Ankur Oberoi
aoberoi at gmail.com
Fri Dec 17 15:03:45 UTC 2010
lol no i know it needs to be on the internet, that wasn't the issue at all. in fact, all the steps i took should be the same (i think) for the setup in which the stage is on the same machine as the live site. im not specifying any IP addresses, the subdomain gets resolved by the DNS, so it doesn't matter what machine the stage is on, the buffering just needs to put that subdomain in there. i just had 127.0.0.1 in the hosts because i wanted to test (on my machine) what a request going to stage would look like. i guess i didn't phrase that clearly, but i was trying to mimic the staging machine on my own dev machine before touching the server we use for live.
i actually figured out why i couldn't get to wp-admin after digging into the code myself, i was just hoping someone was up that had done this before and gave me a quick answer. the problem was that output buffering doesn't apply to response headers which get sent immediately. therefore by the time the callback is fired, a redirect in the header has already taken place. the fix i found to work so far is to add this somewhere (i put it in my theme for now, but i'm thinking ill put it in a plugin later):
// Redirect Plug for Development
function redirect_to_stage($location, $status) {
$location = str_replace('example.com', 'stage.example.com', $location);
return $location;
}
add_filter('wp_redirect', 'redirect_to_stage');
On Dec 17, 2010, at 7:37 AM, Otto wrote:
> On Fri, Dec 17, 2010 at 1:39 AM, Ankur Oberoi <aoberoi at gmail.com> wrote:
>>> Okay, let's say your production site is live.example.com and your
>>> staging site is stage.example.com.
>>>
>>> On your staging site, you set it up to think it's the live site, with
>>> the live URL. This is to make it identical in content and database and
>>> such with the live site.
>>>
>>> Then, in some file that is not going to the live site (wp-config, any
>>> plugin, etc), you'd do something sorta like this:
>>>
>>> ob_start('my_callback');
>>> function my_callback($out) {
>>> return str_replace('live.example.com', 'stage.example.com', $out);
>>> }
>>>
>>> Output buffering. It's easy.
>>> http://php.net/manual/en/function.ob-start.php
>>
>> I just got around to trying this out. At first I thought this was perfect and I took ur advice on modifying the hosts file to point to my own machine for the live URL. Then I tried to access wp-admin and I have an issue, maybe you've dealt with this so you can help me out.
>>
>> I (will) have a staging server at 'stage.example.com' and the site lives at 'example.com', so I set my output buffering callback function like this:
>>
>> function my_callback($out) {
>> str_replace('example.com', 'stage.example.com', $out);
>> return str_replace('http://example.com', 'http://stage.example.com', $out);
>> }
>>
>> I am trying to be extra cautious about the url, although i don't like the fact that if anywhere in my content i talk about example.com it will automatically be changed to stage.example.com, but in this case that won't happen so lets just ignore that.
>>
>> on my staging machine I added a line to /etc/hosts:
>>
>> 127.0.0.1 stage.example.com
>>
>> the machine also has a vhost running whose ServerName (apache specfic i guess) is set to stage.example.com and points to the directory in which the site lives.
>>
>> I am pretty sure I did all the steps right, but what would it take for my client to be able to visit stage.example.com/wp-admin in order to see the admin section as usual?
>
> If you want your client to see the staging site, then the staging site
> has to be somewhere that they can see it. This means that if you're
> running it on the local machine, then that ain't going to work.
>
> I was kind of assuming that stage.example.com was a live site
> somewhere on the internet. If you're developing locally, then no magic
> in the world will put the local install on the live internet... short
> of actually putting the machine on the live internet as a server with
> a domain name pointing to it.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list