1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Moving hosts - PHP\MySQL

Discussion in 'Site & Server Administration' started by JoeO, Jun 16, 2005.

  1. #1
    For one of my sites (using PHP and MySQL) I am looking to move hosts. I am trying to do it with very little down time. Users need to be able to read/write to the database the whole time. I am wandering if my plan is feasable:

    - Upload the entire site to the new host well still using the old host for the live site.
    - Point the site on the new host to still use the MySQL database on the old host.
    - Change the DNS on the domain to the new host. So during propegation whether people are going to the site on the old or new host it will be updating the same database.
    - After 48 hours (during nonpeak hours) change it so the new host uses the new database first (so no one updates the old one well restoring). Then download from the old host and restore it on the new host.

    So maybe a total of 5-10 minutes of down time.


    Thanks in advance for any advice :)
     
    JoeO, Jun 16, 2005 IP
  2. debunked

    debunked Prominent Member

    Messages:
    7,298
    Likes Received:
    416
    Best Answers:
    0
    Trophy Points:
    310
    #2
    Just switch to a new host and wait about 1 week to make sure things are fully switched before cancelling the old host.

    Maybe switch the mysql database to a different site during this time that way both are using the same database until the switch is complete. If you own another site put the database there for now. (I know very little about databases, but that is my thoughts.)
     
    debunked, Jun 16, 2005 IP
    JoeO likes this.
  3. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ya, I guess a week would be a little safer.

    As for the database my plan was to leave it on the old host during the switch so they both use that one.

    Cheers
     
    JoeO, Jun 16, 2005 IP
  4. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JoeO,

    Your plan sounds fine and one I've used many times before. Copy all of the files over to the new server and change the scripts on the new server to point to the database on the old server. Update your DNS. Wait until you are certain propagation has completed. (Refer to server logs on the old server to see when requests stop hitting the old site.)

    Then take down the site on the new server just long enough to copy the database over to the new site and change the scripts so they are pointing to the database on the new site. Bring the site back up and delete all of the files and database from the old server after you've made a last backup.

    Another trick if your DNS provider allows is to set the 'Refresh', 'Retry'. 'Expire', and 'Minimum' times to very low values. This will speed up the propagation time.

    Good luck, let me know if you have further questions as I do this all the time.
     
    tflight, Jun 16, 2005 IP
    JoeO likes this.
  5. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the tips, espeacily about the server logs. I never thought of that.
     
    JoeO, Jun 16, 2005 IP
  6. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Joe, your plan sounds fine except for a potential problem. On most hosts, your SQL server is going to be on another machine (not on the webserver) and will not be accessable from anywhere else other than the webserver. You can check this by trying to connect to the mysql server from home or another server. If this is the case, you may be able to get your host to allow your new webserver's IP to connect.
     
    exam, Jun 16, 2005 IP
    JoeO likes this.
  7. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ya exam, I had briefly thought about that. I was just going to test it once it got to the new server. But maybe I'll try to connect to my live database from my test enviroment at home tonight.
     
    JoeO, Jun 16, 2005 IP
  8. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If it is the case that you can only connect to your DBS from your webserver and your host won't change this, you could write an intermediary script (with a good password) that will execute any SQL statement and return the results (using serialize() or something). That way you could access your database from your new webserver. That would only be for a worse-case situation. (because it would be a pain)
     
    exam, Jun 17, 2005 IP
  9. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ya exam, thats possible, but the way my site is done that would be a huge pain.

    I tried yesterday and connect connect to the database from a different host. So when I'm ready I'll ask them about it, if they say no I will then try and move the database to my new host first and have both sites access it from there if possible.
     
    JoeO, Jun 17, 2005 IP
  10. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Your plan sounds good, but it depends on your old host alowing remote connections to mysql.

    Your new host may be more helpfull in order to get your bussiness.
    I would
    1. copy the whole thing to the new host
    2. test it
    3. shut down site for mantaince
    3a. do fresh back-up and alter old host to use new host's db
    3b. restore back-up on new host.
    4. bring old site back on line.
    5. do dns changes
    6. wait a week or two.
    7. delete old site.
    8. have the new host remove remote access to db.

    Note: if you are using phpMyAdmin for moving your data base, you may save your data (only) with "Use ignore inserts" which will only write missing entries.
     
    mushroom, Jun 18, 2005 IP
    JoeO likes this.
  11. NeoGen

    NeoGen Writer

    Messages:
    2,303
    Likes Received:
    301
    Best Answers:
    0
    Trophy Points:
    230
    #11
    Hi JoeO,

    Do have a shared hosting account or reseller account. Also, where is the domain registered.

    If its reseller account, then its very easy, copy your entire site to new server and in old site just point the A Record to new server. Otherwise you might have to request your old host to do that, I am not sure how open they would be in doing so.

    If at domain registration, you have access to DNS manager, you can simply point your A record to new server.

    In both the cases you would be having zero downtime!
     
    NeoGen, Jun 18, 2005 IP
    JoeO likes this.
  12. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #12
    The only problem, mushroom, is what do you do with the database changes during the DNS regeneration time?
     
    exam, Jun 18, 2005 IP
  13. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks guys. I think I have all the information I need to make this go pretty smooth. I will probably be doing it in about 12 days or so.

    Thanks again.
     
    JoeO, Jun 18, 2005 IP
  14. mushroom

    mushroom Peon

    Messages:
    369
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Item 3a. and alter old host to use new host's db
     
    mushroom, Jun 18, 2005 IP
  15. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Ok, sorry you're right. :) Although, to be pertectly honest, if the host allows access to the db server from any other IP other than the webhost, I would walk away pretty fast ;)
     
    exam, Jun 19, 2005 IP
  16. JoeO

    JoeO Peon

    Messages:
    431
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Well depends on the host. I have 1 account with dreamhost that allows you to specify which ip addresses can access the db through the control panel.

    Not that I would host anything of much importance there though for other reasons ;)

     
    JoeO, Jun 19, 2005 IP
  17. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #17
    That would be the best solution... :) .. I guess I was referring to a db server that allowed connections from any IP. over & out.
     
    exam, Jun 20, 2005 IP