Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent file differences between live and staging websites AND system scripts (PHP)
    primarykey
    data
    text
    <p>I'm trying to find a good way to maintain PHP configuration differences between a dev and live environment. I know how to handle differences when scripts are run by Apache (<em>see below</em>), but not when they are run <strong>on the command line</strong>, e.g. via cron.</p> <p><em>Background info:</em></p> <p><strong><em>What do I mean by "configuration differences"?</em></strong> Like most code shops, we run a non-public 'staging' version of our website where we test code before it goes to the live website. We use Subversion and have the live website as 'Trunk' and 'Staging' as a branch. It makes life easier when code goes from staging to live if the repository version of the files have minimal differences. But obviously, some details need to be different, e.g. the DB connection details.</p> <p><strong><em>How configuration differences are solved with Apache</em></strong></p> <p>In PHP, we set branch specific variables as follows:</p> <pre><code>switch ($_SERVER['HTTP_HOST']) { case 'ourstagingurl.com': $dbPassword = "blahblah"; break; default: $dbPassword = "blahblah"; } </code></pre> <p>or we put the following in the .htaccess file relevant to the specific site:</p> <pre><code>php_value dbPassword "blahblah" </code></pre> <p><strong><em>Why I can't resolve configuration differences using the CLI?</em></strong></p> <p>When a script is run on the CLI, there's no super globals such as <code>$_SERVER</code>. I could <code>include</code> a config file using a absolute path but how can I know whether the script is from live or staging? I could pass in a command line argument that specifies the environment but I was hoping there was a better way?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload