Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to maintain a "version for the server" - with only config files changed, in Git?

I sometimes work with Codeigniter, and after I'm done developing on the local site, I need to migrate the files to the server. All the files in the /config/ folder need to be changed to match the Server settings. It's not right to make an entire commit for these changes, do I simply make Git ignore these files altogether, or is there a way to track these changes and apply them with Git at the right moment?

like image 743
Aditya M P Avatar asked May 13 '12 11:05

Aditya M P


3 Answers

You could keep versioned:

  • two "value config files", with the right values for each environment
  • a template config file, with value placeholder in it (for instance, @@PORT_NUMBER@@)
  • a script able to generate the actual config file depending on the current environment
  • a content filter driver which, on checkout, will trigger the script in order to generate the right config file.

content filter driver

Note: that supposes your template config file has a recognizable content (the filter doesn't have a name or path of the file). See "Git equivalent of subversion's $URL$ keyword expansion" for more on the limitation of git content filter driver).

like image 76
VonC Avatar answered Oct 05 '22 04:10

VonC


It depends on Your needs. In my company we use other approach. We've created several environments (where the asterix is internal project name):

  • devel - site runs on domain **.local.com*
  • test - site run on domain test.*.company.com
  • beta - beta.*.company.com
  • production - every other domain.

Based on the domain name we switch automatically configurations. Basicly config file looks like:

<?php
return array(
  '_env' => array(
    'devel' => array(
      // config for devel
    ),
    'production' => array(
      // config for production
    )
  )
);
?>

Some frameworks (AFAIR Zend) set the environment name in Virtual Host config (or .htaccess). You should look at: zend framework auto switch production staging test .. etc

Have You looked at CI documentation? There's a section about it.

like image 34
radmen Avatar answered Oct 05 '22 03:10

radmen


Create two folders in the config folder. One is called development and the other is production. Now copy config.php, database.php etc to each of these folders. Now when you are on production server, CodeIgniter will first check the production folder for the files. If it is not there, then it uses the default file in the config folder. And if you are on development environment, CodeIgniter will first check the development folder.

If you want to keep any config file identical to the production and development environment, keep it in config folder.

If you want to set the environment then add the following code in .htaccess file:

#This code for Development Environment
SetEnv CI_ENV development

and

#This code for Production Environment
SetEnv CI_ENV production
like image 36
Usman Ahmed Avatar answered Oct 05 '22 05:10

Usman Ahmed