0

This is probably a fairly elementary question, but I am not 100% familiar with the best Git practices. I am developing a web application which will regularly push updates. I have files on my local machine, which is where I do most of my editing/developing. I have a remove test server which I push files to during development.

I then have a live remote production server which houses the live application. All of the files are the same (expect new features on the test server) with one exception. I have a config.php file which has various settings such as DB connection settings, paths, API keys, etc.

I have added a .gitignore file on both remote servers telling Git to ignore the config.php file. If I make any additions to it, I can manually override it later.

I upload files to the test server as needed, and once everything is good, I pull the files from github (where everything is stored) to the live server to launch files.

Does this sound about right? Am I missing something or doing something incorrectly. Appreciate the assistance.

Chris
  • 4,762
  • 3
  • 44
  • 79

1 Answers1

0

For your config.php file problem take a look at this method instead of excluding it from your VCS.

if ($_SERVER['SERVER_ADDR'] === 'test-machine-ip') {
    // config here
    $config = array(); 
} else {
    // production or other config, you get the idea 
    $config = array(); 
}

Regarding the updating of the test/live server; If you have a standalone server the method you mentioned should do fine, otherwise you should implement git hooks to have automatic updating based on the specific branch you push to such as testing and production.

The hooks will allow you to have a process similar to this:

  1. Push to remote origin (BitBucket etc)
  2. BitBucket has a hook setup, POST the commit data to the servers (branch name etc)
  3. Your script will read the commit and act accordingly, based on the commit data.

This method is great for just the production server(s) whilst still using the other method for the test server which is usually only one box. Most of the small scripts you find online wont have the branch detection capability.

Here are a few resources to get you started

Be aware the methods vary in how the automatic deployment is done.

This method is useful if you have a few production servers etc and also removes the hassle of SSH'ing in to the server to perform the pull (although you could write a script for that).

Community
  • 1
  • 1
SamV
  • 7,548
  • 4
  • 39
  • 50