Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Installing Moodle/Creating custom php.ini files.

Installing Moodle/Creating custom php.ini files

From MoodleDocs

Critical to any installation using php is your php.ini file, which contains directives for you usage of php. This is especially true with respect to a number of moodle settings such as max upload and max post sizes with file upload

How php.ini is used


PHP searches for php.ini in a specific order in php5 (in php4 you were required to place a copy of php.ini in every directory from which you wished to run a php script which would be impacted by php.ini - looking at phpinfo.php if you are running php4 will only tell you the location of the php.ini files in one directory....)

For information on sourcing see:

Apache configuration versus php.ini

Remember, you can effect the behavior of php via php.ini or via htaccess or apache conf files. You should NOT do both. As noted here: In some types of installations there are apache configuration files that set php values, such as max upload file size. Editing php.ini will not have the desired result if apache configuration files provide php directives.


PHP can be run via mod_php or as a cgi program. If the latter is used there are some security considerations to address /need section on php cgi security?/ An artifact of running php as CGI is that since php is invoked everytime a php script is called, you need not restart apache to force a rereading of the php.ini file.

Manipulating php.ini

Editing the php.ini file generally

A general listing of core directives that can be placed in php.ini can be found here. Remember that various versions of php have changed what are allowable directives in php.ini.

Make sure you use a real text editor and make sure you back up any file before editing it.

php.ini with shared hosts

wrappers etc

Moodle specific php.ini settings

Common php.ini settings

Please see PHP settings by Moodle version for additional details.

In the discussion below you can substitute Off for 0 and On for 1.

register_globals = 0  ;(necessary) safe_mode = 0  ;(necessary) memory_limit = 40M  ;(varies: minimum 16M, 32M Moodle v1.7, 40M Moodle v1.8, 128M large sites) session.save_handler = files ;(unless you are using another handler, e.g. mm) magic_quotes_gpc = 0  ;(preferred but not necessary, necessary from 2.0 onwards) magic_quotes_runtime = 0  ;(necessary) file_uploads = 1 session.auto_start = 0  ;(necessary) session.bug_compat_warn = 0

Max file size settings

You may also want to set other, optional php.ini file settings while you are already editing it. For instance, you may want to reset the maximum upload size of file attachments, which usually defaults to 2M(egabytes). For instance, to set these to 16 Megabytes:

post_max_size = 16M upload_max_filesize = 16M

If you are running PHP4, you may need to copy the php.ini file into various folders for it to work:

  1. public_html
  2. moodle/admin
  3. moodle/course
  4. moodle/files
  5. root of your moodledata directory

See Also

PHP settings by Moodle version

See PHP settings by Moodle version for more information on different settings by Moodle version.