5

I have a PHP website of around 20 pages without a database on shared hosting - it has quite a lot of forms and a significant amount of visits. I have a staging subdomain on the same server wherein I have uploaded a new version of the site.

I want to replace the live site with the staging site, but I am worried if it will cause any errors or inconveniences to the users, for example those who have just clicked the submit button on a form, or any other case in general.

One option I know of is to simple copy everything from the staging site to the live site directory, and replace the old site. But I don't know how it will affect the users currently online, and it may have some consequences I am not aware of.

I think a safer approach would be to block new users from entering the site (I think it can be done using the .htaccess file), and then ensure all of the users have exited, or somehow force them to exit the site, before replacing the live site with the staging site.

Is there a better method than the above? If not, how would I make sure all of the users have exited the site before replacing it with the new one?

  • Take the site offline for maintenance. And redirect everyone to a maintenance page with a message explaining why they're here. – Abu Nooh Aug 4 '15 at 18:45
  • Taking the site offline just like that will cause the same errors/uncertainties that I'm trying to avoid. I want a way to ensure there is no one at the site at the time of taking it down. – Hassaan Aug 4 '15 at 19:42
  • Well you could have planned maintenance time. Leave a message that site will be offline on x day for x amount of hours. That is the norm. – Abu Nooh Aug 4 '15 at 23:37
  • What about the users online at the time the site is taken down? Don't they experience any error messages or breaking functionality? – Hassaan Aug 5 '15 at 1:46
  • 1
    They will see the maintenance page when they try to navigate away to another page in your site. If they remain on the same page then there won't be any interruption. – Abu Nooh Aug 5 '15 at 7:16
1

Copying the site from one folder to the next is a good start.

Next if you use a content management system, check any configuration files that contain path names (or folder names) and update them to match the correct path names for the new domain you move your site to.

If you written code manually, after copying it over check all links in the code itself to make sure they point to the correct URLs on the new domain.

For example, if you have code that contained:

<a href="http://old.com/123">

You would change it to something like:

<a href="http://new.com/123">

Except you replace old.com and new.com with the correct old domain name and new domain name respectively.

Then clear the cache in your browser and test everything on the new URL and watch the address bar of your browser as you test to make sure the old domain does not reappear again.

When that's all done, then on the old domain, set up .htaccess so that any request to any old URL is redirected to the new URL.

These lines places in .htaccess should help provided your server is apache with mod_rewrite module installed and active.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
  • My question is related to the problem of users currently logged into the site - how can I ensure no one is logged in at the time I make that move from one folder to the other? – Hassaan Aug 5 '15 at 1:48
  • It would be automatic provided that cookies are used to identify users when logged in (which 99+% sites should have) if the new domain is different and not a subdomain of the old one, and the domain name is specified at the time of cookie creation. This is because cookie values don't get transferred between domains. – Mike Aug 5 '15 at 2:26
  • Where do you get this fact that 99% of sites use cookie to identify logged in users. Besides, your method above will break for files yet to be transferred. It'll only work if all files are present in both directories. I wouldn't recommend this method, not industry norm. Nor is it best practice. – Abu Nooh Aug 5 '15 at 7:19
  • How so? I'm suggesting having two copies of the site running, making sure the second copy works 100% before making the first copy redirect to the second via HTTP 301 statuses. I'm not sure how that would break the site. – Mike Aug 5 '15 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.