Last updated 22 September 2016. Created on 7 November 2005.
Edited by kajalkiran, Michael-IDA, krina.addweb, LeeHunter. Log in to edit this page.

These are some simple guidelines for setting up Drupal on a classic Linux-Apache-MySQL-PHP (LAMP) stack that provides a fair amount of security for the rest of your system.

PHP Configuration

To start, some common PHP configuration options can be optimized. On some systems, these settings may already be set, but it never hurts to add them yourself just in case.

PHP settings can be controlled in a number of ways. If you have access to the php.ini configuration file (usually found at /etc/php.ini), you can simply edit this file to cause system-wide changes. If you'd prefer to make these changes just for your Drupal installation, however, the best place to do so is in your Drupal installation's settings.php file.

  1. First, increase PHP's memory limit to avoid getting out-of-memory errors when you begin to add a few modules. These errors may look something like this:

    Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 30720 bytes) in /path/to/drupal/modules/system/system.module on line 1022

  2. In your php.ini file, include a line that reads: memory_limit = 256M. Or…
  3. …in your settings.php file, include a line that reads: ini_set('memory_limit', '256M');
  4. Apache Virtual Host Configuration

    If you have access to your system's Apache configuration files (typically /etc/httpd/httpd.conf or /etc/apache2/httpd.conf), you can also make some simple changes to simplify Drupal's multisite configuration for subdomains.

    # Including a wildcard ServerAlias will direct all traffic to your end
    # users site and simplifies using Drupal's multisite configuration for
    # subdomains.
    ServerAlias *
    # This path will vary depending on your system. If you are using debian
    # make sure you drop the default images alias. Leaving it can be very
    # annoying to users on shared servers.
    DocumentRoot /var/www/
    # Place the log where your end users can see them, and make sure they
    # are at the least readable to an end user.
    # Performance option:
    # You can move the Apache logs to another partition or drive to
    # get some small increases in disk i/o on heavily loaded servers.
    # You can symlink the log files to /var/www/
    # to keep the persistent user interface, however it doesn't work in
    # chroot environments.
    ErrorLog /srv/www/
    CustomLog /srv/www/ combined
    # Allow end users to manipulate their virtual hosts to their
    # hearts' content by enabling .htaccess files for them.
    AllowOverride All
    # Since mod_php doesn't like you to respect su_exec, and safe_mode is just
    # too paranoid to be usable, restrict php to the proper vhost but to a level
    # above the DocumentRoot so users have some private file space for
    # .htpasswd, Drupal files, backups, etc.
    php_admin_value open_basedir /var/www/
    # Move PHP's temporary files into the open_basedir restricted space.
    php_admin_value upload_tmp_dir /var/www/
    # path isn't really necessary for drupal since it
    # stores sessions in the database, but for general php enabled
    #vhosts it keeps session data tied to each vhost.
    php_admin_value session.save_path /var/www/

    MySQL Performance Optimization

    Tweaking the configurations for your MySQL database server can give you a boost in performance. The MySQL configuration file is typically /etc/my.cnf.

    # big ol mysql.querycache(128M) (be aware of your systems memory limitations)
    query_cache_size = 134217728
    # boost mysql max connections (min = (20*number of drupal sites))

Looking for support? Visit the forums, or join #drupal-support in IRC.


mbohner’s picture

A visual 'aid' in identifying an out-of-memory error can be that one might encounter an empty/blank Modules page. This happened to me directly after copying a new module into sites\all\modules and following browser refresh.

cvdenzen’s picture

At least, not for me. I set it to 32M after getting empty pages at various actions (manage modules, manage users etc.).
I use Drupal 6.12 and a few modules (quiz, wishlist, views, advanced_help, comment_upload, private_upload, comment_upload).

tomcatuk’s picture

...I ended up setting to 96MB (my site has to process large .csv files)

kenorb’s picture

Related topic: (Increase PHP memory limit)