9

I'm creating an installation profile for my current company internal project.

During the installation process, one of the custom modules crashes during init(), since it tries to use one global variable defined on settings.php (that's current default behavior of the module)

Using system_form_install_settings_form_alter() I changed the settings form, by adding one input textfield for user's input, and on submit the value is appended to settings.php, but settings.php is rewrited before profile installation starts.

There is any way to prevent cleanup of settings.php by the installation process?

4
  • 1
    Maybe it would be easier to patch the module that is crashing, and submit your change to the issue queue for that project. Before your change is accepted, you can add a reference to your patch in the makefile for your installation profile. Commented Sep 1, 2012 at 0:03
  • Hi, thanks for your answer. It's an custom internal module (not a contrib one), but yes, I patched it and problem solved. Commented Sep 3, 2012 at 9:00
  • Is it something where using a settings.local.php file that overrides the settings.php file could also help?
    – beth
    Commented Jan 28, 2013 at 22:53
  • This link was big help for me previousnext.com.au/blog/…
    – Vic
    Commented Aug 8, 2013 at 6:20

2 Answers 2

3

You may find it easier to use a settings.common.php

Often during team projects, we have local settings.php with db credentials etc.. and a settings.common.php with settings common to the install and deployment environments.

You can add settings.common.php with an include / require line in settings.php

require 'settings.common.php'; // same directory, e.g sites/default/settings.common.php

and then write to it as needed during install.

3

My answer depends on the server using Apache, but I assume any of the other web servers can accomplish this too.

In your virtualhost config, you can set all of the variables for your environment:

SetEnv DBUSER datbase_user
SetEnv DBPASS database_pass
SetEnv DBNAME database_name
SetEnv DBHOST localhost

And in your settings.php file:

$databases = array (
   'default' => 
   array (
     'default' => 
     array (
       'database' => $_SERVER["DBNAME"],
       'username' => $_SERVER["DBUSER"],
       'password' => $_SERVER["DBPASS"],
       'host' => $_SERVER["DBHOST"],
       'port' => '',
       'driver' => 'mysql',
       'prefix' => '',
    ),
   ),
 );

You can set any other variables this way as well.

If you are worried about the $_SERVER array getting into the wrong hands, you can unset all of the important variables at the bottom of settings.php:

unset($_SERVER["DBUSER"]);
unset($_SERVER["DBPASS"]);
unset($_SERVER["DBNAME"]);
unset($_SERVER["DBHOST"]);

This is how we do it at my office to move sites between our dev environments, staging and even production.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.