Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Changes a Live Site (Codeigniter, but not specific to it)

I'm using Codeigniter if this makes it easier. I'm wondering if a website is live with populated database and users accessing, and I have a new idea to implement into the website, how should I do it? Do you work directly on the live site?

Or do you copy the database and the files to a local server (MAMP/WAMP/XAMMP) and work on it there then if it works update the live site with the changes. For this second method, is there anyway to check which are the files that have been changed and only upload those? What if it works on local sever, but after updating the live site it does not work?

Codeigniter configuration also has the option of default database and other database. I wonder how these can be used for testing?

like image 307
Nyxynyx Avatar asked Jun 07 '11 17:06

Nyxynyx


3 Answers

Don't work directly on the live site. Instead, have a development environment (using, say, vmware or virtualbox on your machine) and clone the live environment. Get you code in version control (I'll say it again: GET YOUR CODE IN VERSION CONTROL), do your development on the development machine, against a dev branch in version control. After you're done testing and happy with the changes, commit them to a 'deployments' or 'live' branch, and deploy on the live site from there. Be sure to do a backup of the database before you roll out the new code.

Edit: use symlinks to stage your new code base on the live site. If it doesn't work, just switch it back to the old directory. Saves you a lot of greif!

like image 197
user151841 Avatar answered Oct 21 '22 13:10

user151841


  1. Read up on version control (svn, git, et al.).
  2. Never work on a live site, preferably on another server (to prevent while(1){..} crashes etc.), but on the same server at least on another documentroot/domain, preferably with limited access to your IP only.
  3. Normally I only copy the table-definitions (mysqldump -t is nice for that) and have another database altogether, if you need the latest & greatest data, you could replicate your main database to a test-database, which also gives you the advantage of a cheap backup if you haven't got one already.
  4. I usually set a switch in Apache/Vhost configuration (SetEnv DEV=1), so that in code I can use if(getenv('DEV')==1) to check whether I can just dump variables on error conditions, and which limit the possibility of accidentaly committing/uploading code with a 'development switch' still on by accident.
like image 25
Wrikken Avatar answered Oct 21 '22 12:10

Wrikken


The typical answer to this question is going to be do your work in the test environment, not the production environment. And I agree that that is often the best way to handle changes. If you have the luxury of a test environment, then take full advantage of it. After all, that's what it's there for--to test.

However, that doesn't mean that working in the production environment is completely off-limits. Your decision should be based on a few factors:

  • Is the operation of your website critical to your business needs?

If so, do all your work in a test environment and deploy it to your live environment when you've fully tested your changes.

  • Are the changes you're about to make going to have a large impact on the rest of the website?

For example, are you about to change the Database schema? Are you about to change the way users log in or out of your website? If so, do your work in the test environment. If you're changing the behavior of a page that doesn't have any effect elsewhere, you could get away with making the change in the production environment.

  • How long will your changes take to implement?

If you can't guarantee that your changes won't take longer than 15-20 minutes, do your work in a test environment.

like image 25
villecoder Avatar answered Oct 21 '22 13:10

villecoder