A Guided Tour of Drupal’s Settings.php

setting

The most important file on your Drupal site is the settings.php file.

The settings.php is unique to every site and contains all of the important information that Drupal needs to run.

Inside settings.php you’ll find everything from your database type and login details to your URL and multisite options.

This tutorial is your guided tour of settings.php. If you run a Drupal site, here’s what you need to know about this vital file.

The settings.php file is what makes your site run. It’s the glue that connects your code to the database and various other things such as:

  1. Configuration directory
  2. Database settings
  3. Access control for update.php script
  4. Salt for one-time login links and cancel links, form tokens, etc.
  5. Base URL (optional)
  6. PHP Settings such as: garbage collection, session cookie settings, large text output.
  7. Variable overrides
  8. Reverse proxy configuration. This applies when Drupal is behind a reverse proxy.
  9. Page caching. In this instance, you have the option to omit the Vary cookie. If you do this “authenticated users would also be served the anonymous page from the cache.”
  10. CSS/JS aggregated file gzip compression
  11. String overrides
  12. IP blocking
  13. Fast 404 pages
  14. External access proxy settings
  15. Authorized file system operations

The settings.php file does a nice job explaining most of these but we will explore a few of the options that you are likely to need.

Where is the settings.php file?

media_1365416352690.png

If you manually installed your Drupal site, you will already know where this file is. Recall that you were asked to make a copy of default.settings.php and call it settings.php. For those who are working with a Drupal site that was setup for them (such as the case with Acquia’s Dev Desktop), then the following is of interest to you.

Each Drupal site has a directory called sites. Search/find the directories and files that make up your Drupal site (as shown in the image above).

  1. Open the sites directory and see a directory called default.
  2. Open the default directory and see the settings.php file.
  3. Open the settings.php file using a tool such as Notepad++ (it’s free for PC and Mac). Or if you have Dreamweaver or some other webdev application, of course that would work as well.

Domains and Paths in Drupal

media_1365418158521.png

Every site has a domain. Okay, that’s stating the obvious but did you know that sometimes you need to tell Drupal which domain it should use? The first set of comments you see when you open the settings.php file talks about the sites.php file and multisite configuration. Multisite configuration is beyond the scope of this tutorial but if you have a need, now you know where to start. For now, let’s keep things simple.

When you followed the steps above to locate the settings.php file, the path you followed was sites/default/settings.php. If you scroll down a bit in the file, you will see a list of sample paths denoting the various directories Drupal will look for when trying to find the settings.php file for the site whose URL is http://www.drupal.org:8080/mysite/test. In the end, Drupal doesn’t find a directory it can relate the URL to, it will seek out the default directory.

Why does this matter? Well, for most installations, it doesn’t. But one day you might want to install a new Drupal site but use the same code-base. That’s when knowing this comes in handy. Also, if you are using Acquia Dev Desktop and you use its control panel to create multiple practice sites, the feature that creates the new sites for you is actually creating multiple site directories in sites.

Base URL

media_1365424633457.png

Since we are on the topic of URL’s, scroll down until you find the section entitled, Base URL. As the comment suggests, assigning a base URL is optional but in the event you are having issues with your base URL being detected correctly by Drupal, this is one option for trying to rectify the issue.

Default Database in Drupal

media_1365418825369.png

Okay, now that we have URL’s out of the way, scroll back up until you find the section on Database settings.

As you know, Drupal relies on a database to store all the configuration information as well as your content. When you download Drupal, you aren’t downloading the database that goes with it. You are downloading code that will populate an empty database with all the tables Drupal needs. This means, when you manual install Drupal, you are expected to create an empty database that Drupal can use.

Typically, all you need to know is the name of the database (let’s say you call it widget for your site widget.mydomain.com). The process by which you create your database will vary depending on your hosting environment but someplace in the process, your empty database will need to be assigned to a user and given a password as well. It’s these three pieces of data you will need when completing the installation form Drupal presents in the browser.

If Drupal is going to take care of updating the settings.php file for you, why do you need to know about this? As you can see there are other settings in the database array and if your environment expects something different, then you might need to make a change. BUT, the most common reason I can think of is when you migrate from your local installation to an installation on a live server.

Imagine if you will, you’ve built your site using Acquia’s Dev Destop and you the name of the database turns out to be a name you don’t want to use on the live server. The steps you would need to follow in migrating your site would be:

  1. Copy all the files to the server (this means all the files shown in the first screen shot of this tutorial).
  2. Use phpmyadmin to export the database from your practice site.
  3. Create an empty database on the server with the name, username, and password you prefer (or what your IT guy told you it needed to be).
  4. Using phpmyadmin on the live server, import your sql file from your localhost site.
  5. Edit your sites/default/settings.php file and change the databasename, username, password so that Drupal can find all your data.

Here’s a detailed guide to changing the database connection in your settings.php.

Shared Databases in Drupal

media_1365419971151.png

If you have a situation where you need multiple sites but instead of just sharing the code-base (as we discussed earlier) you need to share the database, the settings.php file is where you tell Drupal what to do. The key to sharing one Drupal database with multiple sites is the prefix. The prefix allows you to have multiple users tables, menus tables, etc. such that site1.com and site2.com will each have it’s own users but can share the content.

There are alot of tables in a Drupal database so before you decide this is the way to go, you should spend some time understanding what each table stores so that you can ensure all the tables that need to be unique from site to site are indeed that.

As you scroll down, you will also seem other options available to advanced users but this tutorial will not dig that deep.

Controlling Access to update.php

media_1365420752326.png

In order to update your site’s code, your userid needs permission to run the update.php script. In the event something goes wrong and you need to log in as a user who does not have these permissions, you can temporarily turn off this access control and run the update. I would try to avoid disabling this security feature as much as possible.

Additional Security

media_1365422620603.png

You need to be aware of this next setting option if your site is deployed on a cluster of web servers or if you want to enhance security by contents from a file outside your document root. As the comments state, “you must ensure that this variable has the same value on each server” if your site is deployed on a cluster of web servers.

As you can imagine, this security feature is not something you need to worry about for most sites but if you are involved in building a large, busy site or one requiring additional security options, this will be one of your stops.

String Overrides

Before you go crazy changing strings via the settings.php file, just know that there are modules that can help you do that as well. Such as http://drupal.org/project/stringoverrides.

404 Pages

Similar to string overrides, before you try to customize $conf[‘404_fast_html’] within the settings.php file, consider utilizing the option to use a node to hold the message you desire. Visit your configuration>site information page and insert the node ID for the page that contains your desired message.

Summary

As you can see, the settings.php file has a lot going on. Depending on the site you are building and the anticipated traffic expected, most of the settings will remain as is. If you find you need to make a change, please read the instructions carefully. If they are unclear, try Googling the topic to see if others are experiencing the same issues you are to determine if the changes you want to make will be accommodated by the setting in this file.

Author

0 0 votes
Article Rating
Subscribe
Notify of
9 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Abhay
Abhay
10 years ago

Hi Everyone,

I want to start my carrier in Php, but I am really confused fro where to start as I do not have any knowledge of php. Is it necessary to learn php with My SQL? I really need some books and other stuff to learn php apart from training. I am still confused with which books to follow. I will really appreciate if you can guide me with some good books or some notes if I can get to learn php.

Cheers

Abby

krishna kanth
krishna kanth
8 years ago
Reply to  Abhay

[url=https://www.youtube.com/watch?v=iCUV3iv9xOs&list=PL442FA2C127377F07]https://www.youtube.com/wat…[/url]

steve
10 years ago

Hi Abhay

I can recommend some good PHP training right here 🙂

[url=http://www.ostraining.com/courses/class/coding/php]http://www.ostraining.com/c…[/url]

daveinLA2
daveinLA2
10 years ago

This is stuff I definitely want to learn but I get confused with file structures. I heard pro programmers use the c prompt to move and manage files – do you have any tutorials on c prompts??

mate670
mate670
10 years ago

Very nice information given in this post…extremely thanks

for sharing……very appreciable in fact very helpful…

mate670
mate670
10 years ago

Very nice post…

Cluemate
Cluemate
9 years ago

Thanks, Its very useful for me…

Ann
Ann
7 years ago

I am trying to move a website created in Dreamweaver to Drupal. I would like to know how to do this(just copy the files to where in Drupal). Is there a website that talk you through this.

steve
steve
7 years ago
Reply to  Ann

Hi Ann. Yes, this website. We help our members with problems exactly like this.

9
0
Would love your thoughts, please comment.x
()
x