dotkfcr226217
2017-06-07 11:30
浏览 62

如何正确使用Git。 使用带有DEVELOPMENT,TESTING和PRODUCTION服务器的CodeIgniter

Basically, I have a file index.php which should be different in each server. The file indicates which server it is on.

It has something like this:

On the DEVELOPMENT environment:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

On the TESTING environment:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'testing');

On the PRODUCTION environment:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');

What's the proper way to maintain these files on each server without Git touching it?

I've added the file to .gitignore now, and I've untracked it using git rm --cached index.php then git push origin master for TESTING server and stable for PRODUCTION server.

图片转代码服务由CSDN问答提供 功能建议

基本上,我有一个文件 index.php ,每个服务器应该不同。 该文件指示它所在的服务器。

它具有以下内容:

开发 环境:

  define('ENVIRONMENT',isset($ _ SERVER ['CI_ENV'])?$ _SERVER ['CI_ENV']:'development');  
   
 
 

TESTING 环境中:

  define('ENVIRONMENT',isset  ($ _SERVER ['CI_ENV'])?$ _SERVER ['CI_ENV']:'testing'); 
   
 
 

PRODUCTION 上 环境:

  define('ENVIRONMENT',isset($ _ SERVER ['CI_ENV'])?$ _SERVER ['CI_ENV']:'production'); 
   
 
 

在没有Git触摸的情况下,在每台服务器上维护这些文件的正确方法是什么?

我现在已将文件添加到 .gitignore ,并且我使用 git rm --cached index.php 然后 git push origin master 用于TESTING服务器, stable 用于PRODUCTION服务器。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanfu1945 2017-06-07 11:57
    已采纳

    fyi,

    if you use apache you don't really have to change the index.php file because you can use your htaccess file to define your environment

    for example :

    SetEnvIf Host yourdevdomain$ CI_ENV=development
    SetEnvIf Host yourtestdomain$ CI_ENV=testing
    SetEnvIf Host example.com$ CI_ENV=production
    

    In this case, you can set your needed Environments in your htaccess file, and you don't have to worry about overwriting some stuff with different files from different environments.

    i think there is an option on nginx too

    Take a look here

    You can get more information from the official CI Documentation here.

    已采纳该答案
    打赏 评论
  • douwen4401 2017-06-07 12:31

    With Apache you can set CI_ENV like @sintakonte's answer. With nginx and php-fpm you can set CI_ENV like this:

    location ~ \.php {
        ....
        fastcgi_param CI_ENV production;
    }
    

    And leave the index.php file as default.

    Cheers.

    打赏 评论

相关推荐 更多相似问题