<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="sv">
	<id>https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Brendanheywood</id>
	<title>MoodleDocs - Användarbidrag [sv]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Brendanheywood"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/Special:Bidrag/Brendanheywood"/>
	<updated>2026-05-30T05:00:09Z</updated>
	<subtitle>Användarbidrag</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143949</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143949"/>
		<updated>2022-08-03T07:24:37Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Read only sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
==Timeout==&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
==Cookie path==&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_auth = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_retry = 100; // Optional, default is 100ms (from 3.9)&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
$CFG-&amp;gt;session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Notes:&lt;br /&gt;
* Be careful on changing the default serializer: it requires &amp;lt;code php&amp;gt;--enable-redis-igbinary&amp;lt;/code&amp;gt; at &#039;&#039;phpredis&#039;&#039; extension compile time &#039;&#039;&#039;and&#039;&#039;&#039; you need to remove &#039;&#039;&#039;the previous session data&#039;&#039;&#039; before using Moodle again.&lt;br /&gt;
== Read only sessions ==&lt;br /&gt;
There was an experimental feature introduced in Moodle 3.9 and is now stable since 3.11. It allows certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
==== 1) Using a compliant session store ====&lt;br /&gt;
In order to use readonly sessions you need to be using a session store which supports it, which includes database and redis.&lt;br /&gt;
==== 2) Mapping session caches ====&lt;br /&gt;
By default all MUC &#039;session caches&#039; are stored in the $SESSION which is a subtle distinction that is easily misunderstood. MUC caches can be read and written at any time and are independent of the $SESSION being locked. So all cache definitions which have a mode of session need to be mapped to a store which is not in the session such as in redis. If this isn&#039;t done errors will be raised highlighting the configuration issue.&lt;br /&gt;
==== 3) Turning it on in config.php ====&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions = true;&lt;br /&gt;
If you have concerns about rolling this out, there is a soft rollout mode which report on any issues and you could leave this on for say a month or two and then turn it on fully:&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions_debug = true;&lt;br /&gt;
==== 4) Adding support for it to core and plugins ====&lt;br /&gt;
Various critical pages and web services in core have been declared and implemented as readonly, if you want to support readonly sessions please read:&lt;br /&gt;
https://docs.moodle.org/dev/Session_locks&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143948</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143948"/>
		<updated>2022-08-03T07:23:41Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Read only sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_auth = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_retry = 100; // Optional, default is 100ms (from 3.9)&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
$CFG-&amp;gt;session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Be careful on changing the default serializer: it requires &amp;lt;code php&amp;gt;--enable-redis-igbinary&amp;lt;/code&amp;gt; at &#039;&#039;phpredis&#039;&#039; extension compile time &#039;&#039;&#039;and&#039;&#039;&#039; you need to remove &#039;&#039;&#039;the previous session data&#039;&#039;&#039; before using Moodle again.&lt;br /&gt;
&lt;br /&gt;
== Read only sessions ==&lt;br /&gt;
There is an experimental feature introduced in Moodle 3.9 and stable in 3.11. It allows certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
==== 1) Using a compliant session store ====&lt;br /&gt;
In order to use readonly sessions you need to be using a session store which supports it, which includes database and redis.&lt;br /&gt;
==== 2) Mapping session caches ====&lt;br /&gt;
By default all MUC &#039;session caches&#039; are stored in the $SESSION which is a subtle distinction that is easily misunderstood. MUC caches can be read and written at any time and are independent of the $SESSION being locked. So all cache definitions which have a mode of session need to be mapped to a store which is not in the session such as in redis. If this isn&#039;t done errors will be raised highlighting the configuration issue.&lt;br /&gt;
==== 3) Turning it on in config.php ====&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions = true;&lt;br /&gt;
If you have concerns about rolling this out, there is a soft rollout mode which report on any issues and you could leave this on for say a month or two and then turn it on fully:&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions_debug = true;&lt;br /&gt;
&lt;br /&gt;
==== 4) Adding support for it to core and plugins ====&lt;br /&gt;
Various critical pages and web services in core have been declared and implemented as readonly, if you want to support readonly sessions please read:&lt;br /&gt;
https://docs.moodle.org/dev/Session_locks&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143947</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143947"/>
		<updated>2022-08-03T07:23:21Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Read only sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_auth = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_retry = 100; // Optional, default is 100ms (from 3.9)&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
$CFG-&amp;gt;session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Be careful on changing the default serializer: it requires &amp;lt;code php&amp;gt;--enable-redis-igbinary&amp;lt;/code&amp;gt; at &#039;&#039;phpredis&#039;&#039; extension compile time &#039;&#039;&#039;and&#039;&#039;&#039; you need to remove &#039;&#039;&#039;the previous session data&#039;&#039;&#039; before using Moodle again.&lt;br /&gt;
&lt;br /&gt;
== Read only sessions ==&lt;br /&gt;
There is an experimental feature introduced in Moodle 3.9 and stable in 3.11. It allows certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
==== 1) Using a compliant session store ====&lt;br /&gt;
In order to use readonly sessions you need to be using a session store which supports it, which includes database and redis.&lt;br /&gt;
==== 2) Mapping session caches ===&lt;br /&gt;
By default all MUC &#039;session caches&#039; are stored in the $SESSION which is a subtle distinction that is easily misunderstood. MUC caches can be read and written at any time and are independent of the $SESSION being locked. So all cache definitions which have a mode of session need to be mapped to a store which is not in the session such as in redis. If this isn&#039;t done errors will be raised highlighting the configuration issue.&lt;br /&gt;
==== 3) Turning it on in config.php ===&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions = true;&lt;br /&gt;
If you have concerns about rolling this out, there is a soft rollout mode which report on any issues and you could leave this on for say a month or two and then turn it on fully:&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions_debug = true;&lt;br /&gt;
&lt;br /&gt;
==== 4) Adding support for it to core and plugins ====&lt;br /&gt;
Various critical pages and web services in core have been declared and implemented as readonly, if you want to support readonly sessions please read:&lt;br /&gt;
https://docs.moodle.org/dev/Session_locks&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143946</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=143946"/>
		<updated>2022-08-03T07:23:02Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Read only sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_auth = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_retry = 100; // Optional, default is 100ms (from 3.9)&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
$CFG-&amp;gt;session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Be careful on changing the default serializer: it requires &amp;lt;code php&amp;gt;--enable-redis-igbinary&amp;lt;/code&amp;gt; at &#039;&#039;phpredis&#039;&#039; extension compile time &#039;&#039;&#039;and&#039;&#039;&#039; you need to remove &#039;&#039;&#039;the previous session data&#039;&#039;&#039; before using Moodle again.&lt;br /&gt;
&lt;br /&gt;
== Read only sessions ==&lt;br /&gt;
There is an experimental feature introduced in Moodle 3.9 and stable in 3.11. It allows certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
==== 1) Using a compliant session store ====&lt;br /&gt;
In order to use readonly sessions you need to be using a session store which supports it, which includes database and redis.&lt;br /&gt;
=== 2) Mapping session caches ===&lt;br /&gt;
By default all MUC &#039;session caches&#039; are stored in the $SESSION which is a subtle distinction that is easily misunderstood. MUC caches can be read and written at any time and are independent of the $SESSION being locked. So all cache definitions which have a mode of session need to be mapped to a store which is not in the session such as in redis. If this isn&#039;t done errors will be raised highlighting the configuration issue.&lt;br /&gt;
=== 3) Turning it on in config.php ===&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions = true;&lt;br /&gt;
If you have concerns about rolling this out, there is a soft rollout mode which report on any issues and you could leave this on for say a month or two and then turn it on fully:&lt;br /&gt;
 $CFG-&amp;gt;enable_read_only_sessions_debug = true;&lt;br /&gt;
&lt;br /&gt;
==== 4) Adding support for it to core and plugins ====&lt;br /&gt;
Various critical pages and web services in core have been declared and implemented as readonly, if you want to support readonly sessions please read:&lt;br /&gt;
https://docs.moodle.org/dev/Session_locks&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=140716</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=140716"/>
		<updated>2021-06-23T12:08:38Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: $CFG-&amp;gt;alternative_component_cache&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;alternative_file_system_class===&lt;br /&gt;
&lt;br /&gt;
By default all uploaded content files are de-duplicated are stored inside [$CFG-&amp;gt;dataroot]/filedir. But you can replace this is an alternative file store, like a cloud store such as AWS S3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;alternative_file_system_class = &#039;\tool_objectfs\s3_file_system&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/catalyst/moodle-tool_objectfs/&lt;br /&gt;
&lt;br /&gt;
NOTE: Even if you use an alternate filesystem you &#039;&#039;&#039;MUST&#039;&#039;&#039; still have a shared $CFG-&amp;gt;dataroot.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;backuptempdir===&lt;br /&gt;
&lt;br /&gt;
Server clusters MUST use shared filesystem for backuptempdir! This directory gets very large and fast bursts of IO but files do not generally live here for any length of time. They are write heavy and do not have much contention.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;alternative_component_cache===&lt;br /&gt;
&lt;br /&gt;
This is used to cache a very low level representation of the components which Moodle uses. Because it is so low level it is before other higher level API&#039;s are available. It is always loaded on every request so putting this onto local disk is much better.&lt;br /&gt;
&lt;br /&gt;
Typically the $CFG-&amp;gt;alternative_component_cache = &#039;/local/cache/dir/core_component.php&#039; would point to local node cache directory.&lt;br /&gt;
&lt;br /&gt;
NOTE: Before upgrade the administrator MUST have to manually execute following on each node:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ php admin/cli/alternative_component_cache.php --rebuild&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively you could put the cache file directly into dirroot and distribute it together with new PHP source files. Yet another possibility would be to purge all local caches on all nodes before upgrade or simply change the script name in config.php on all nodes before upgrade. Or this could be built into new containers as part of your CI / CD deployment.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Implemented in Moodle 2.6, see MDL-40475.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared server eg Redis. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Mail_configuration&amp;diff=140665</id>
		<title>Mail configuration</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Mail_configuration&amp;diff=140665"/>
		<updated>2021-06-14T12:11:17Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* The most common setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
==Outgoing mail configuration==&lt;br /&gt;
&lt;br /&gt;
Settings related to mail sent by Moodle can be found in &#039;Outgoing mail configuration&#039; in Site administration -&amp;gt; Server -&amp;gt; Email.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Allowed email domains&#039; (allowedemaildomains) allows you to enter domains allowed by your mail server so that forum post notification emails can be sent from users&#039; real addresses. It accepts a wildcard for conveniently adding a lot of domains (*.example.com - tim@first.example.com), or a strict match (example.com - tim@example.com). &lt;br /&gt;
&lt;br /&gt;
If allowed domains are set then the user&#039;s email address will be used in the &amp;quot;From&amp;quot; and &amp;quot;Reply to&amp;quot; field only in the following situations:&lt;br /&gt;
&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email address to everyone.&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email only to course members, and the email is to be delivered to a course member.&lt;br /&gt;
&lt;br /&gt;
All other situations use the no-reply address.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Email via information&#039; (emailfromvia) adds via information in the From section of outgoing email to inform the recipient where the email came from:&lt;br /&gt;
 Name (via shortname) &amp;lt;noreplyaddress&amp;gt;&lt;br /&gt;
&#039;shortname&#039; is the short name for the site as set in the front page settings.&lt;br /&gt;
&lt;br /&gt;
NOTE: You can also use [[Email_setup_gmail|Google gMail]] servers or AMAZON [https://docs.bitnami.com/aws/how-to/use-ses/ AWS SES] Simple Email Services to setup SMTP relay for your outbound emails. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DKIM ===&lt;br /&gt;
&lt;br /&gt;
For advanced DKIM setup this is usually done at the MTA such as postfix eg using a &#039;milter&#039; like opendkim.&lt;br /&gt;
&lt;br /&gt;
However there are advantages to doing this in Moodle directly such as when you have limited control over the way your email is being sent. Also by having it in Moodle it can be easier to manage.&lt;br /&gt;
&lt;br /&gt;
In 3.10 / 4.0 a new setting was added that makes it possible to sign emails at the Moodle level and it requires setting up the private certificates and putting them in a known location where Moodle can find them. Because emails could be sent from a variety of From email addresses the location contains the domain in it&#039;s path and you can provide as many certificates as needed but this is an uncommon use case.&lt;br /&gt;
&lt;br /&gt;
==== The most common setup ====&lt;br /&gt;
&lt;br /&gt;
The simplest and fairly typical setup is where all emails are sent from the noreply email. In this setup we will give instructions on a linux setup such as debian or ubuntu.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;noreplyaddress = &#039;noreply@moodle.myschool.edu.au&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case you need to choose a DKIM selector which is arbitrary but is often based on a date as the best practice is to rotate them on a periodic basis.&lt;br /&gt;
&lt;br /&gt;
Lets say we have chosen a selector of &#039;2020sep&#039;.&lt;br /&gt;
&lt;br /&gt;
Now in sitedata we need to create a folder to hold the DKIM certificate with a subdirectory matching the domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
mkdir -p /path/to/sitedata/dkim/moodle.myschool.edu.au&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next in this directory generate the private key and public key DNS record using the opendkim-genkey tool:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
opendkim-genkey -b 2048 -r -s 2020sep -d moodle.myschool.edu.au -v&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should result in two files like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.txt&lt;br /&gt;
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.private&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Only the .private file is used by Moodle, the .txt file is the TXT record which you need to add to your DNS. To confirm that it is all correct there is a great public tool where you can enter the domain and DKIM selector and it will confirm the record looks like it is in the correct shape.&lt;br /&gt;
&lt;br /&gt;
https://mxtoolbox.com/dkim.aspx&lt;br /&gt;
&lt;br /&gt;
Once this is in place then use the email testing tool in moodle to send a test email, it can be useful to turn on the debugsmtp setting.&lt;br /&gt;
&lt;br /&gt;
/admin/testoutgoingmailconf.php&lt;br /&gt;
&lt;br /&gt;
You should see the DKIM signature in the email headers. The email server receiving the email should also have validated this signature as well and added another header with the results of this validation.&lt;br /&gt;
&lt;br /&gt;
ie in Gmail open the email, click the &#039;...&#039; on the right, then &#039;Show original&#039; and in the headers it should say:&lt;br /&gt;
&lt;br /&gt;
DKIM: &#039;PASS&#039; with domain moodle.myschool.edu.au&lt;br /&gt;
&lt;br /&gt;
===Test outgoing mail configuration===&lt;br /&gt;
&lt;br /&gt;
A link is available to send yourself a test email to check everything is working correctly.&lt;br /&gt;
&lt;br /&gt;
==Incoming mail configuration==&lt;br /&gt;
If incoming mail processing is enabled in &#039;Incoming mail configuration&#039; in Site administration, then users are able to reply to forum posts via email and send files to their private files as email attachments.&lt;br /&gt;
&lt;br /&gt;
===Mailbox configuration===&lt;br /&gt;
It is important to have a dedicated email address here. Don&#039;t use one you normally use for your personal emails. You do not need to add the @ sign. If you have set up the email mountorangeschool @ besteveremail.com then it would be entered as in the following screenshot:&lt;br /&gt;
[[File:emailexampleincoming.png|thumb|center|400px]]&lt;br /&gt;
&lt;br /&gt;
===Incoming mail server settings===&lt;br /&gt;
As an example, if you are using gmail you would use &#039;&#039;&#039;IMAP.gmail.com&#039;&#039;&#039; in the Incoming mail server (messageinbound_host) field. (If using gmail you also need to make sure that you&#039;ve enabled IMAP for yor gmail account - see https://support.google.com/mail/troubleshooter/1668960?hl=en )&lt;br /&gt;
&lt;br /&gt;
Note1: The SMTP server hosting the mailbox you&#039;ve configured above must support &#039;&#039;plus addressing&#039;&#039; i.e. any email sent to mountorangeschool+blahblahblah@besteveremail.com is still delivered to mountorangeschool@besteveremail.com.&lt;br /&gt;
&lt;br /&gt;
Note2 : The username and password  here must relate to the settings you entered earlier in Mailbox configuration. So if your address was mountorangeschool @ besteveremail.com and your username is &#039;&#039;mountorangeschool&#039;&#039;, then enter your username in this section along with the password you use to get into this email account.&lt;br /&gt;
&lt;br /&gt;
Note 3: You may also need to make sure that your host does not block outbound connections to the IMAP ports (some do by default).&lt;br /&gt;
&lt;br /&gt;
Note 4: If using gmail, you may find that IMAP does not work with Google&#039;s higher security setting.  If IMAP is not working with gmail, check out https://support.google.com/accounts/answer/6010255?hl=en-GB&lt;br /&gt;
&lt;br /&gt;
==Message handlers==&lt;br /&gt;
&lt;br /&gt;
===Email to Private files===&lt;br /&gt;
*If you enable this, then users will be able to send attachments via email directly to their private files. See [[Private files]] for details of how the feature works.&lt;br /&gt;
*Each user will be provided with  an address in their Private files to which they send the email and attached files. You can set the default expiry period for this address here.&lt;br /&gt;
*Checking the &#039;Validate sender address&#039; box will mean that if an email is sent to a user&#039;s private files from a different account from that registered with  user in Moodle, then Moodle will check first before allowing the file to be stored in the user&#039;s Private files.&lt;br /&gt;
&lt;br /&gt;
===Invalid recipient handler===&lt;br /&gt;
If a valid message is received but the sender cannot be authenticated, the message is stored on the email server and the user is contacted using the email address in their user profile. The user is given the chance to reply to confirm the authenticity of the original message.This handler processes those replies.&lt;br /&gt;
&lt;br /&gt;
It is not possible to disable sender verification of this handler because the user may reply from an incorrect email address if their email client configuration is incorrect.&lt;br /&gt;
&lt;br /&gt;
===Reply to forum posts===&lt;br /&gt;
*If you enable this, then users will be able to reply to forum posts directly from their email inbox. See the section on &#039;Reply to posts via email&#039; in [[Using Forum]] for details of how the feature works.&lt;br /&gt;
*You must leave empty the &#039;&#039;Site administration &amp;gt; Server &amp;gt; Email &amp;gt; Outgoing mail configuration &amp;gt; Allowed email domains&#039;&#039; setting; otherwise users will see the email of the forum poster instead.&lt;br /&gt;
*Each user will be provided with  reply-to address when they click to reply to a forum post via  email. You can set the default expiry period for this address here.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=277594 Need help configuring forum&#039;s &amp;quot;Reply to post&amp;quot; feature] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[es:Configuración del correo]]&lt;br /&gt;
[[de:Einstellungen für E-Mails]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Forum]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Mail_configuration&amp;diff=140664</id>
		<title>Mail configuration</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Mail_configuration&amp;diff=140664"/>
		<updated>2021-06-14T12:11:02Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
==Outgoing mail configuration==&lt;br /&gt;
&lt;br /&gt;
Settings related to mail sent by Moodle can be found in &#039;Outgoing mail configuration&#039; in Site administration -&amp;gt; Server -&amp;gt; Email.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Allowed email domains&#039; (allowedemaildomains) allows you to enter domains allowed by your mail server so that forum post notification emails can be sent from users&#039; real addresses. It accepts a wildcard for conveniently adding a lot of domains (*.example.com - tim@first.example.com), or a strict match (example.com - tim@example.com). &lt;br /&gt;
&lt;br /&gt;
If allowed domains are set then the user&#039;s email address will be used in the &amp;quot;From&amp;quot; and &amp;quot;Reply to&amp;quot; field only in the following situations:&lt;br /&gt;
&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email address to everyone.&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email only to course members, and the email is to be delivered to a course member.&lt;br /&gt;
&lt;br /&gt;
All other situations use the no-reply address.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Email via information&#039; (emailfromvia) adds via information in the From section of outgoing email to inform the recipient where the email came from:&lt;br /&gt;
 Name (via shortname) &amp;lt;noreplyaddress&amp;gt;&lt;br /&gt;
&#039;shortname&#039; is the short name for the site as set in the front page settings.&lt;br /&gt;
&lt;br /&gt;
NOTE: You can also use [[Email_setup_gmail|Google gMail]] servers or AMAZON [https://docs.bitnami.com/aws/how-to/use-ses/ AWS SES] Simple Email Services to setup SMTP relay for your outbound emails. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DKIM ===&lt;br /&gt;
&lt;br /&gt;
For advanced DKIM setup this is usually done at the MTA such as postfix eg using a &#039;milter&#039; like opendkim.&lt;br /&gt;
&lt;br /&gt;
However there are advantages to doing this in Moodle directly such as when you have limited control over the way your email is being sent. Also by having it in Moodle it can be easier to manage.&lt;br /&gt;
&lt;br /&gt;
In 3.10 / 4.0 a new setting was added that makes it possible to sign emails at the Moodle level and it requires setting up the private certificates and putting them in a known location where Moodle can find them. Because emails could be sent from a variety of From email addresses the location contains the domain in it&#039;s path and you can provide as many certificates as needed but this is an uncommon use case.&lt;br /&gt;
&lt;br /&gt;
=== The most common setup ===&lt;br /&gt;
&lt;br /&gt;
The simplest and fairly typical setup is where all emails are sent from the noreply email. In this setup we will give instructions on a linux setup such as debian or ubuntu.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;noreplyaddress = &#039;noreply@moodle.myschool.edu.au&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case you need to choose a DKIM selector which is arbitrary but is often based on a date as the best practice is to rotate them on a periodic basis.&lt;br /&gt;
&lt;br /&gt;
Lets say we have chosen a selector of &#039;2020sep&#039;.&lt;br /&gt;
&lt;br /&gt;
Now in sitedata we need to create a folder to hold the DKIM certificate with a subdirectory matching the domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
mkdir -p /path/to/sitedata/dkim/moodle.myschool.edu.au&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next in this directory generate the private key and public key DNS record using the opendkim-genkey tool:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
opendkim-genkey -b 2048 -r -s 2020sep -d moodle.myschool.edu.au -v&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should result in two files like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.txt&lt;br /&gt;
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.private&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Only the .private file is used by Moodle, the .txt file is the TXT record which you need to add to your DNS. To confirm that it is all correct there is a great public tool where you can enter the domain and DKIM selector and it will confirm the record looks like it is in the correct shape.&lt;br /&gt;
&lt;br /&gt;
https://mxtoolbox.com/dkim.aspx&lt;br /&gt;
&lt;br /&gt;
Once this is in place then use the email testing tool in moodle to send a test email, it can be useful to turn on the debugsmtp setting.&lt;br /&gt;
&lt;br /&gt;
/admin/testoutgoingmailconf.php&lt;br /&gt;
&lt;br /&gt;
You should see the DKIM signature in the email headers. The email server receiving the email should also have validated this signature as well and added another header with the results of this validation.&lt;br /&gt;
&lt;br /&gt;
ie in Gmail open the email, click the &#039;...&#039; on the right, then &#039;Show original&#039; and in the headers it should say:&lt;br /&gt;
&lt;br /&gt;
DKIM: &#039;PASS&#039; with domain moodle.myschool.edu.au&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test outgoing mail configuration===&lt;br /&gt;
&lt;br /&gt;
A link is available to send yourself a test email to check everything is working correctly.&lt;br /&gt;
&lt;br /&gt;
==Incoming mail configuration==&lt;br /&gt;
If incoming mail processing is enabled in &#039;Incoming mail configuration&#039; in Site administration, then users are able to reply to forum posts via email and send files to their private files as email attachments.&lt;br /&gt;
&lt;br /&gt;
===Mailbox configuration===&lt;br /&gt;
It is important to have a dedicated email address here. Don&#039;t use one you normally use for your personal emails. You do not need to add the @ sign. If you have set up the email mountorangeschool @ besteveremail.com then it would be entered as in the following screenshot:&lt;br /&gt;
[[File:emailexampleincoming.png|thumb|center|400px]]&lt;br /&gt;
&lt;br /&gt;
===Incoming mail server settings===&lt;br /&gt;
As an example, if you are using gmail you would use &#039;&#039;&#039;IMAP.gmail.com&#039;&#039;&#039; in the Incoming mail server (messageinbound_host) field. (If using gmail you also need to make sure that you&#039;ve enabled IMAP for yor gmail account - see https://support.google.com/mail/troubleshooter/1668960?hl=en )&lt;br /&gt;
&lt;br /&gt;
Note1: The SMTP server hosting the mailbox you&#039;ve configured above must support &#039;&#039;plus addressing&#039;&#039; i.e. any email sent to mountorangeschool+blahblahblah@besteveremail.com is still delivered to mountorangeschool@besteveremail.com.&lt;br /&gt;
&lt;br /&gt;
Note2 : The username and password  here must relate to the settings you entered earlier in Mailbox configuration. So if your address was mountorangeschool @ besteveremail.com and your username is &#039;&#039;mountorangeschool&#039;&#039;, then enter your username in this section along with the password you use to get into this email account.&lt;br /&gt;
&lt;br /&gt;
Note 3: You may also need to make sure that your host does not block outbound connections to the IMAP ports (some do by default).&lt;br /&gt;
&lt;br /&gt;
Note 4: If using gmail, you may find that IMAP does not work with Google&#039;s higher security setting.  If IMAP is not working with gmail, check out https://support.google.com/accounts/answer/6010255?hl=en-GB&lt;br /&gt;
&lt;br /&gt;
==Message handlers==&lt;br /&gt;
&lt;br /&gt;
===Email to Private files===&lt;br /&gt;
*If you enable this, then users will be able to send attachments via email directly to their private files. See [[Private files]] for details of how the feature works.&lt;br /&gt;
*Each user will be provided with  an address in their Private files to which they send the email and attached files. You can set the default expiry period for this address here.&lt;br /&gt;
*Checking the &#039;Validate sender address&#039; box will mean that if an email is sent to a user&#039;s private files from a different account from that registered with  user in Moodle, then Moodle will check first before allowing the file to be stored in the user&#039;s Private files.&lt;br /&gt;
&lt;br /&gt;
===Invalid recipient handler===&lt;br /&gt;
If a valid message is received but the sender cannot be authenticated, the message is stored on the email server and the user is contacted using the email address in their user profile. The user is given the chance to reply to confirm the authenticity of the original message.This handler processes those replies.&lt;br /&gt;
&lt;br /&gt;
It is not possible to disable sender verification of this handler because the user may reply from an incorrect email address if their email client configuration is incorrect.&lt;br /&gt;
&lt;br /&gt;
===Reply to forum posts===&lt;br /&gt;
*If you enable this, then users will be able to reply to forum posts directly from their email inbox. See the section on &#039;Reply to posts via email&#039; in [[Using Forum]] for details of how the feature works.&lt;br /&gt;
*You must leave empty the &#039;&#039;Site administration &amp;gt; Server &amp;gt; Email &amp;gt; Outgoing mail configuration &amp;gt; Allowed email domains&#039;&#039; setting; otherwise users will see the email of the forum poster instead.&lt;br /&gt;
*Each user will be provided with  reply-to address when they click to reply to a forum post via  email. You can set the default expiry period for this address here.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=277594 Need help configuring forum&#039;s &amp;quot;Reply to post&amp;quot; feature] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[es:Configuración del correo]]&lt;br /&gt;
[[de:Einstellungen für E-Mails]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Forum]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Mail_configuration&amp;diff=140663</id>
		<title>Mail configuration</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Mail_configuration&amp;diff=140663"/>
		<updated>2021-06-14T12:10:40Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: Added DKIM section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
==Outgoing mail configuration==&lt;br /&gt;
&lt;br /&gt;
Settings related to mail sent by Moodle can be found in &#039;Outgoing mail configuration&#039; in Site administration -&amp;gt; Server -&amp;gt; Email.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Allowed email domains&#039; (allowedemaildomains) allows you to enter domains allowed by your mail server so that forum post notification emails can be sent from users&#039; real addresses. It accepts a wildcard for conveniently adding a lot of domains (*.example.com - tim@first.example.com), or a strict match (example.com - tim@example.com). &lt;br /&gt;
&lt;br /&gt;
If allowed domains are set then the user&#039;s email address will be used in the &amp;quot;From&amp;quot; and &amp;quot;Reply to&amp;quot; field only in the following situations:&lt;br /&gt;
&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email address to everyone.&lt;br /&gt;
* The email matches the allowed domains, and the user&#039;s setting is to display their email only to course members, and the email is to be delivered to a course member.&lt;br /&gt;
&lt;br /&gt;
All other situations use the no-reply address.&lt;br /&gt;
&lt;br /&gt;
The setting &#039;Email via information&#039; (emailfromvia) adds via information in the From section of outgoing email to inform the recipient where the email came from:&lt;br /&gt;
 Name (via shortname) &amp;lt;noreplyaddress&amp;gt;&lt;br /&gt;
&#039;shortname&#039; is the short name for the site as set in the front page settings.&lt;br /&gt;
&lt;br /&gt;
NOTE: You can also use [[Email_setup_gmail|Google gMail]] servers or AMAZON [https://docs.bitnami.com/aws/how-to/use-ses/ AWS SES] Simple Email Services to setup SMTP relay for your outbound emails. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== DKIM ==&lt;br /&gt;
&lt;br /&gt;
For advanced DKIM setup this is usually done at the MTA such as postfix eg using a &#039;milter&#039; like opendkim.&lt;br /&gt;
&lt;br /&gt;
However there are advantages to doing this in Moodle directly such as when you have limited control over the way your email is being sent. Also by having it in Moodle it can be easier to manage.&lt;br /&gt;
&lt;br /&gt;
In 3.10 / 4.0 a new setting was added that makes it possible to sign emails at the Moodle level and it requires setting up the private certificates and putting them in a known location where Moodle can find them. Because emails could be sent from a variety of From email addresses the location contains the domain in it&#039;s path and you can provide as many certificates as needed but this is an uncommon use case.&lt;br /&gt;
&lt;br /&gt;
== The most common setup ==&lt;br /&gt;
&lt;br /&gt;
The simplest and fairly typical setup is where all emails are sent from the noreply email. In this setup we will give instructions on a linux setup such as debian or ubuntu.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;noreplyaddress = &#039;noreply@moodle.myschool.edu.au&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case you need to choose a DKIM selector which is arbitrary but is often based on a date as the best practice is to rotate them on a periodic basis.&lt;br /&gt;
&lt;br /&gt;
Lets say we have chosen a selector of &#039;2020sep&#039;.&lt;br /&gt;
&lt;br /&gt;
Now in sitedata we need to create a folder to hold the DKIM certificate with a subdirectory matching the domain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
mkdir -p /path/to/sitedata/dkim/moodle.myschool.edu.au&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next in this directory generate the private key and public key DNS record using the opendkim-genkey tool:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
opendkim-genkey -b 2048 -r -s 2020sep -d moodle.myschool.edu.au -v&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should result in two files like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.txt&lt;br /&gt;
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.private&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Only the .private file is used by Moodle, the .txt file is the TXT record which you need to add to your DNS. To confirm that it is all correct there is a great public tool where you can enter the domain and DKIM selector and it will confirm the record looks like it is in the correct shape.&lt;br /&gt;
&lt;br /&gt;
https://mxtoolbox.com/dkim.aspx&lt;br /&gt;
&lt;br /&gt;
Once this is in place then use the email testing tool in moodle to send a test email, it can be useful to turn on the debugsmtp setting.&lt;br /&gt;
&lt;br /&gt;
/admin/testoutgoingmailconf.php&lt;br /&gt;
&lt;br /&gt;
You should see the DKIM signature in the email headers. The email server receiving the email should also have validated this signature as well and added another header with the results of this validation.&lt;br /&gt;
&lt;br /&gt;
ie in Gmail open the email, click the &#039;...&#039; on the right, then &#039;Show original&#039; and in the headers it should say:&lt;br /&gt;
&lt;br /&gt;
DKIM: &#039;PASS&#039; with domain moodle.myschool.edu.au&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test outgoing mail configuration===&lt;br /&gt;
&lt;br /&gt;
A link is available to send yourself a test email to check everything is working correctly.&lt;br /&gt;
&lt;br /&gt;
==Incoming mail configuration==&lt;br /&gt;
If incoming mail processing is enabled in &#039;Incoming mail configuration&#039; in Site administration, then users are able to reply to forum posts via email and send files to their private files as email attachments.&lt;br /&gt;
&lt;br /&gt;
===Mailbox configuration===&lt;br /&gt;
It is important to have a dedicated email address here. Don&#039;t use one you normally use for your personal emails. You do not need to add the @ sign. If you have set up the email mountorangeschool @ besteveremail.com then it would be entered as in the following screenshot:&lt;br /&gt;
[[File:emailexampleincoming.png|thumb|center|400px]]&lt;br /&gt;
&lt;br /&gt;
===Incoming mail server settings===&lt;br /&gt;
As an example, if you are using gmail you would use &#039;&#039;&#039;IMAP.gmail.com&#039;&#039;&#039; in the Incoming mail server (messageinbound_host) field. (If using gmail you also need to make sure that you&#039;ve enabled IMAP for yor gmail account - see https://support.google.com/mail/troubleshooter/1668960?hl=en )&lt;br /&gt;
&lt;br /&gt;
Note1: The SMTP server hosting the mailbox you&#039;ve configured above must support &#039;&#039;plus addressing&#039;&#039; i.e. any email sent to mountorangeschool+blahblahblah@besteveremail.com is still delivered to mountorangeschool@besteveremail.com.&lt;br /&gt;
&lt;br /&gt;
Note2 : The username and password  here must relate to the settings you entered earlier in Mailbox configuration. So if your address was mountorangeschool @ besteveremail.com and your username is &#039;&#039;mountorangeschool&#039;&#039;, then enter your username in this section along with the password you use to get into this email account.&lt;br /&gt;
&lt;br /&gt;
Note 3: You may also need to make sure that your host does not block outbound connections to the IMAP ports (some do by default).&lt;br /&gt;
&lt;br /&gt;
Note 4: If using gmail, you may find that IMAP does not work with Google&#039;s higher security setting.  If IMAP is not working with gmail, check out https://support.google.com/accounts/answer/6010255?hl=en-GB&lt;br /&gt;
&lt;br /&gt;
==Message handlers==&lt;br /&gt;
&lt;br /&gt;
===Email to Private files===&lt;br /&gt;
*If you enable this, then users will be able to send attachments via email directly to their private files. See [[Private files]] for details of how the feature works.&lt;br /&gt;
*Each user will be provided with  an address in their Private files to which they send the email and attached files. You can set the default expiry period for this address here.&lt;br /&gt;
*Checking the &#039;Validate sender address&#039; box will mean that if an email is sent to a user&#039;s private files from a different account from that registered with  user in Moodle, then Moodle will check first before allowing the file to be stored in the user&#039;s Private files.&lt;br /&gt;
&lt;br /&gt;
===Invalid recipient handler===&lt;br /&gt;
If a valid message is received but the sender cannot be authenticated, the message is stored on the email server and the user is contacted using the email address in their user profile. The user is given the chance to reply to confirm the authenticity of the original message.This handler processes those replies.&lt;br /&gt;
&lt;br /&gt;
It is not possible to disable sender verification of this handler because the user may reply from an incorrect email address if their email client configuration is incorrect.&lt;br /&gt;
&lt;br /&gt;
===Reply to forum posts===&lt;br /&gt;
*If you enable this, then users will be able to reply to forum posts directly from their email inbox. See the section on &#039;Reply to posts via email&#039; in [[Using Forum]] for details of how the feature works.&lt;br /&gt;
*You must leave empty the &#039;&#039;Site administration &amp;gt; Server &amp;gt; Email &amp;gt; Outgoing mail configuration &amp;gt; Allowed email domains&#039;&#039; setting; otherwise users will see the email of the forum poster instead.&lt;br /&gt;
*Each user will be provided with  reply-to address when they click to reply to a forum post via  email. You can set the default expiry period for this address here.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=277594 Need help configuring forum&#039;s &amp;quot;Reply to post&amp;quot; feature] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[es:Configuración del correo]]&lt;br /&gt;
[[de:Einstellungen für E-Mails]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Forum]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Installing_Moodle&amp;diff=140552</id>
		<title>Installing Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Installing_Moodle&amp;diff=140552"/>
		<updated>2021-05-31T23:34:10Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: Add link to apache&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:Installing Moodle}}&lt;br /&gt;
&#039;&#039;This page explains how to install Moodle. If you are an expert and/or in a hurry try [[Installation Quickstart]].&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you just want to try Moodle on a standalone machine there are &#039;one-click&#039; installers for Windows (see [[Complete install packages for Windows]]) and for OSX (see [[Complete Install Packages for Mac OS X]]) or [[ install on OS X]]. These are unsuitable for production servers.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid installing Moodle yourself completely, consider https://moodle.com/moodlecloud/&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Moodle is primarily developed in Linux using [[Apache]], [[PostgreSQL]]/[[MySQL]]/[[MariaDB]] and [[PHP]] (sometimes known as the LAMP platform). Typically this is also how Moodle is run, although there are other options as long as the software requirements of the  [{{Release notes}} release] are met.&lt;br /&gt;
&lt;br /&gt;
If you are installing Moodle in a Windows server, note that from php5.5 onwards, you will also need to have  the Visual C++ Redistributable for Visual Studio 2012 installed from:&lt;br /&gt;
http://www.microsoft.com/en-us/download/details.aspx?id=30679 Visual C++] ( x86 or x64)  &lt;br /&gt;
&lt;br /&gt;
The basic requirements for Moodle are as follows:&lt;br /&gt;
&lt;br /&gt;
=== Hardware === &lt;br /&gt;
* Disk space: 200MB for the Moodle code, plus as much as you need to store content. 5GB is probably a realistic minimum. &lt;br /&gt;
* Processor: 1GHz (min), 2GHz dual core or more recommended.&lt;br /&gt;
* Memory: 512MB (min), 1GB or more is recommended. 8GB plus is likely on a large production server&lt;br /&gt;
* Consider separate servers for the web &amp;quot;front ends&amp;quot; and the database. It is much easier to &amp;quot;tune&amp;quot;&lt;br /&gt;
&lt;br /&gt;
All the above requirements will vary depending on specific hardware and software combinations as well as the type of use and load; busy sites may well require additional resources. Further guidance can be found under [[Performance_recommendations|performance recommendations]]. Moodle scales easily by increasing hardware.&lt;br /&gt;
&lt;br /&gt;
For very large sites, you are much better starting with a small pilot and gaining some experience and insight. A &amp;quot;what hardware do I need for 50,000 user?&amp;quot; style post in the forums is highly unlikely to get a useful answer.&lt;br /&gt;
&lt;br /&gt;
=== Software ===&lt;br /&gt;
&lt;br /&gt;
See the [{{Release notes}} release notes] in the dev docs for software requirements.&lt;br /&gt;
&lt;br /&gt;
== Set up your server ==&lt;br /&gt;
&lt;br /&gt;
Depending on the use case a Moodle server may be anything from a Desktop PC (e.g. for testing and evaluating) to a rackmounted or  [[Server cluster|clustered]] solution to cloud VMs or other hosted solutions. As mentioned above there are lots of possibilities for installing the basic server software, for details see:&lt;br /&gt;
&lt;br /&gt;
* [[Installing AMP]]&lt;br /&gt;
* [[Internet_Information_Services|IIS]]&lt;br /&gt;
* [[Nginx]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
&lt;br /&gt;
It will help hugely, regardless of your deployment choices, if time is taken to understand how to configure the different parts of your software stack (HTTP daemon, database,  PHP etc). Do not expect the standard server configuration to be optimal for Moodle. For example, the web server and database servers will almost certainly require tuning to get the best out of Moodle.&lt;br /&gt;
&lt;br /&gt;
If a hosting provider is being used  ensure that all Moodle [{{Release notes}}#Server_requirements requirements] (such as PHP version) are met by the hosting platform before attempting the installation. It will help to become familiar with changing settings within the hosting provider&#039;s platform (e.g. PHP file upload maximums) as the options and tools provided vary.&lt;br /&gt;
&lt;br /&gt;
== Download and copy files into place ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: While there are now a number of places you can get the Moodle code (including host provided Moodle installers), you are strongly advised to only obtain Moodle from moodle.org. If you run into problems it will be a great deal easier to support you.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You have two options:&lt;br /&gt;
* Download your required version from http://moodle.org/downloads and unzip/unpack...&lt;br /&gt;
* &#039;&#039;&#039;OR&#039;&#039;&#039; Pull the code from the Git repository (recommended for developers and also makes upgrading very simple):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ git clone -b MOODLE_{{Version3}}_STABLE git://git.moodle.org/moodle.git  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a fuller discussion see [[Git for Administrators]]. &lt;br /&gt;
&lt;br /&gt;
Either of the above should result in a directory called &#039;&#039;&#039;moodle&#039;&#039;&#039;, containing a number of files and folders. &lt;br /&gt;
&lt;br /&gt;
You can typically place the whole folder in your web server documents directory, in which case the site will be located at &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com/moodle&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;, or you can copy all the contents straight into the main web server documents directory, in which case the site will be simply &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;http://yourwebserver.com&amp;lt;/nowiki&amp;gt;&#039;&#039;&#039;. See the documentation for your system and/or web server if you are unsure. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tip:&#039;&#039; If you are downloading Moodle to your local computer and then uploading it to your hosted web site, it is usually better to upload the compressed Moodle file and then decompress on your hosted web site.  If you decompress Moodle on your local computer, because Moodle is comprised of over 25,000 files, trying to upload over 25,000 files using an FTP client or your host&#039;s &amp;quot;file manager&amp;quot; can sometimes miss a file and cause errors. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Secure the Moodle files:&#039;&#039;&#039; It is vital that the files are not writeable by the web server user. For example, on Unix/Linux (as root):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chown -R root /path/to/moodle&lt;br /&gt;
chmod -R 0755 /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(files are owned by the administrator/superuser and are only writeable by them - readable by everyone else)&lt;br /&gt;
&lt;br /&gt;
On test/dev sites you &#039;&#039;may&#039;&#039; want to make the files writeable in order to use the built-in plugin installer. This is discouraged for live sites (at least, revert to more secure settings if you do).&lt;br /&gt;
&lt;br /&gt;
== Create an empty database ==&lt;br /&gt;
&lt;br /&gt;
Next create a new, empty database for your installation. You need to find and make a note of following information for use during the final installation stage:&lt;br /&gt;
* &#039;&#039;&#039;dbhost&#039;&#039;&#039; - the database server hostname. Probably &#039;&#039;localhost&#039;&#039; if the database and web server are the same machine, otherwise the name of the database server&lt;br /&gt;
* &#039;&#039;&#039;dbname&#039;&#039;&#039; - the database name. Whatever you called it, e.g. &#039;&#039;moodle&#039;&#039; &lt;br /&gt;
* &#039;&#039;&#039;dbuser&#039;&#039;&#039; - the username for the database. Whatever you assigned, e.g. &#039;&#039;moodleuser&#039;&#039; - do not use the root/superuser account. Create a proper account with the minimum permissions needed.&lt;br /&gt;
* &#039;&#039;&#039;dbpass&#039;&#039;&#039; - the password for the above user&lt;br /&gt;
&lt;br /&gt;
If your site is hosted you should find a web-based administration page for databases as part of the control panel (or ask your administrator). For everyone else or for detailed instructions, see the page for your chosen database server:&lt;br /&gt;
* [[PostgreSQL]]&lt;br /&gt;
* [[MariaDB]]&lt;br /&gt;
* [[MySQL]]&lt;br /&gt;
* [[MSSQL]]&lt;br /&gt;
* [[Oracle]] (not recommended)&lt;br /&gt;
&lt;br /&gt;
== Create the (&#039;&#039;moodledata&#039;&#039;) data directory  ==&lt;br /&gt;
&lt;br /&gt;
Moodle requires a directory to store all of its files (all your site&#039;s uploaded files, temporary data, cache, session data etc.). The web server needs to be able to write to this directory. On larger systems consider how much free space you are going to use when allocating this directory. &lt;br /&gt;
&lt;br /&gt;
Due to the default way Moodle caches data you may have serious performance issues if you use relatively slow storage (e.g. NFS) for this directory. Read the [[Performance_recommendations]] carefully and consider using (e.g.) redis or memcached for [[Caching]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This directory must &#039;&#039;&#039;NOT&#039;&#039;&#039; be accessible directly via the web. This would be a serious security hole. Do not try to place it inside your web root or inside your Moodle program files directory. Moodle will not install. It can go anywhere else convenient. &lt;br /&gt;
&lt;br /&gt;
Here is an example (Unix/Linux) of creating the directory and setting the permissions for &#039;&#039;&#039;anyone&#039;&#039;&#039; on the server to write here. This is only appropriate for Moodle servers that are not shared. Discuss this with your server administrator for better permissions that just allow the web server user to access these files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# mkdir /path/to/moodledata&lt;br /&gt;
# chmod 0777 /path/to/moodledata&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Securing moodledata in a web directory ====&lt;br /&gt;
&lt;br /&gt;
If you are using a hosted site and you have no option but to place &#039;moodledata&#039; in a web accessible directory. You may be able to secure it by creating an .htaccess file in the &#039;moodledata&#039; directory. This does not work on all systems - see your host/administrator. Create a file called .htaccess containing only the following lines:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Apache 2.2&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
order deny,allow&lt;br /&gt;
deny from all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Apache 2.4&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Require all denied&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start Moodle install ==&lt;br /&gt;
It&#039;s now time to run the installer to create the database tables and configure your new site. The recommended method is to use the command line installer. If you cannot do this for any reason (e.g. on a Windows server) the web-based installer is still available.&lt;br /&gt;
&lt;br /&gt;
=== Command line installer ===&lt;br /&gt;
&lt;br /&gt;
It&#039;s best to run the command line as your system&#039;s web user. You need to know what that is - see your system&#039;s documentation (e.g. Ubuntu/Debian is &#039;www-data&#039;, Centos is &#039;apache&#039;)&lt;br /&gt;
&lt;br /&gt;
* Example of using the command-line  (as root - substitute &#039;www-data&#039; for your web user):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# chown www-data /path/to/moodle&lt;br /&gt;
# cd /path/to/moodle/admin/cli&lt;br /&gt;
# sudo -u www-data /usr/bin/php install.php&lt;br /&gt;
# chown -R root /path/to/moodle&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The chowns allow the script to write a new config.php file. More information about the options can be found using &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# php install.php --help&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be asked for other settings that have not been discussed on this page - if unsure just accept the defaults. For a full discussion see [[Administration via command line]]&lt;br /&gt;
&lt;br /&gt;
=== Web based installer ===&lt;br /&gt;
&lt;br /&gt;
For ease of use you can install Moodle via the web. We recommend configuring your web server so that the page is not publicly accessible until the installation is complete.&lt;br /&gt;
&lt;br /&gt;
To run the web installer script, just go to your Moodle&#039;s main URL using a web browser.&lt;br /&gt;
&lt;br /&gt;
The installation process will take you through a number of pages. You should be asked to confirm the copyright, see the database tables being created, supply administrator account details and supply the site details. The database creation can take some time - please be patient. You should eventually end up at the Moodle front page with an invitation to create a new course. &lt;br /&gt;
&lt;br /&gt;
It is very likely that you will be asked to download the new config.php file and upload it to your Moodle installation - just follow the on-screen instructions.&lt;br /&gt;
&lt;br /&gt;
==Final configuration==&lt;br /&gt;
&lt;br /&gt;
=== Settings within Moodle ===&lt;br /&gt;
There are a number of options within the Moodle Site Administration screens (accessible from the &#039;Site administration&#039; tab in the &#039;Administration&#039; block (Classic theme) or the Site administration button in the navigation bar (Boost). Here are a few of the more important ones that you will probably want to check:&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; Email &amp;gt; [[Mail_configuration#Outgoing_mail_configuration|Outgoing mail configuration]]&#039;&#039;: Set your smtp server and authentication if required (so your Moodle site can send emails). You can also set a norepy email on this page.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; Server &amp;gt; Support contact&#039;&#039;. Set your support contact email. &lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; System paths&#039;&#039;: Set the paths to du, dot and aspell binaries.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Server &amp;gt; HTTP&#039;&#039;: If you are behind a firewall you may need to set your proxy credentials in the &#039;Web proxy&#039; section.&lt;br /&gt;
* &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Location &amp;gt; Update timezones&#039;&#039;: Run this to make sure your timezone information is up to date. (more info [[Location]])&lt;br /&gt;
** [http://php.net/manual/en/timezones.php Set server&#039;s local timezone] inside &amp;lt;tt&amp;gt;php.ini&amp;lt;/tt&amp;gt; (should probably be inside &amp;lt;tt&amp;gt;/etc/php.ini&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;/etc/php.d/date.ini&amp;lt;/tt&amp;gt;, depending on the underlying OS):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
[Date] &lt;br /&gt;
; Defines the default timezone used by the date functions &lt;br /&gt;
date.timezone = &amp;quot;YOUR LOCAL TIMEZONE&amp;quot;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remaining tasks ===&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Configure Cron&#039;&#039;&#039;: Moodle&#039;s background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day. This is known as a cron script. Please refer to the [[Cron|Cron instructions]].&lt;br /&gt;
* &#039;&#039;&#039;Set up backups&#039;&#039;&#039;: See [[Site backup]] and [[Automated course backup]].&lt;br /&gt;
* &#039;&#039;&#039;Secure your Moodle site&#039;&#039;&#039;: Read the [[Security recommendations]].&lt;br /&gt;
*&#039;&#039;&#039;Increasing the maximum upload size&#039;&#039;&#039;  See [[Installation FAQ]] Maximum upload file size - how to change it?&lt;br /&gt;
* &#039;&#039;&#039;Check mail works&#039;&#039;&#039; : From Site administration &amp;gt; Server &amp;gt; Test outgoing mail configuration, use the  link to send yourself a test email. Don&#039;t be tempted to skip this step.&lt;br /&gt;
&lt;br /&gt;
=== Installation is complete :) ===&lt;br /&gt;
&lt;br /&gt;
* Create a new course: You can now access Moodle through your web browser (using the same URL as you set during the install process), log in as your admin user and creatse a new course. See  [[Adding a new course|create a new course]].&lt;br /&gt;
&lt;br /&gt;
=== If something goes wrong... ===&lt;br /&gt;
&lt;br /&gt;
Here are some things you should try...&lt;br /&gt;
&lt;br /&gt;
* Check the [[Installation FAQ]]&lt;br /&gt;
* Check your file permissions carefully. Can your web server read (but not write) the Moodle program files? Can your web server read and write your Moodle data directory? If you don&#039;t fully understand how file ownership and permissions work on your operating system it would be time very well spent to find out.&lt;br /&gt;
* Check your database permissions. Have you set up your database user with the correct rights and permissions for your configuration (especially if the web server and database server are different machines)?&lt;br /&gt;
* Create your [[Configuration file]] (config.php) by hand. Copy config-dist.php (in the root of the Moodle program directory) to config.php, edit it and set your database/site options there. Installation will continue from the right place. &lt;br /&gt;
* Once you have a config.php (see previous tip) you can edit it to turn on debugging (in section 8). This may give you extra information to help track down a problem. If you have access, check your web server error log(s).&lt;br /&gt;
* Re-check your php.ini / .htaccess settings. Are they appropriate (e.g. memory_limit), did you edit the correct php.ini / .htaccess file and (if required) did you re-start the web server after making changes?&lt;br /&gt;
* Did you include any non-core (optional) plugins, themes or other code before starting the installation script? If so, remove it and try again (it may be broken or incompatible).&lt;br /&gt;
* Explain your problem in the [http://moodle.org/mod/forum/view.php?id=28 Installation problems forum]. &#039;&#039;&#039;PLEASE&#039;&#039;&#039; list your software versions; explain what you did, what happened and what error messages you saw (if any); explain what you tried. There is no such thing as &#039;nothing&#039;, even a blank page is something!&lt;br /&gt;
&lt;br /&gt;
== Platform specific instructions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; Much of this information is provided by the community. It may not have been checked and may be out of date. Please read in conjunction with the above installation instructions.&lt;br /&gt;
&lt;br /&gt;
* [[Windows installation]]&lt;br /&gt;
** [[Installing Moodle on SmarterASP.NET]]&lt;br /&gt;
* [[Unix or Linux Installation]]&lt;br /&gt;
* [[Mac Installation]]&lt;br /&gt;
* [[Amazon EC2 Cloud Services Installation]]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [http://www.slideshare.net/gb2048/my-own-moodle Slideshare presentation by Gareth Barnard on installing a local installation of Moodle] and accompanying [https://drive.google.com/folderview?id=0B17B0rYH2zERU21sQnVweUZCUFk&amp;amp;usp=sharing  help guides]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=182086 New Video Tutorial- How to Install Moodle on Shared Hosting via cPanel (Not Fantastico)]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=401983 Another one for cPanel using videos]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=199542 Video Tutorial - Install Moodle on a Virtual Box from scratch] &lt;br /&gt;
&lt;br /&gt;
[[es:Instalaci%C3%B3n_de_moodle]]&lt;br /&gt;
[[de:Installation von Moodle]]&lt;br /&gt;
[[fr:Installation de Moodle]]&lt;br /&gt;
[[ja:Moodleのインストール]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Performance_recommendations&amp;diff=140551</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Performance_recommendations&amp;diff=140551"/>
		<updated>2021-05-31T12:13:30Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Read replicas */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
On very large, load-balanced, systems the performance of the shared components become critical. It&#039;s important that your shared file areas are properly tuned and that you use an effective cache (Redis is highly recommended). A good understanding of these areas of system administration should be considered a minimum requirement. &lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will  have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and choose an alternative. Redis is recommended. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* PHP contains a built-in accelerator. Make sure it is enabled. &lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini. The default value for the memory_limit directive is 128M. On some sites, it may need to be larger - especially for some backup operations. &lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
==== APC ====&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
==== eAccelerator ====&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
==== MemCached ====&lt;br /&gt;
Memcached server (daemon)&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcached on CentOS 7.x (linux)] (as of php 7.x, only memcached is available)&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-memcached-on-centos-7 How To Install and Secure Memcached on CentOS 7]&lt;br /&gt;
* [https://wiki.zimbra.com/wiki/Blocking_Memcached_Attack#Iptables_rules_for_Redhat_based_servers Iptables rules for Redhat based servers]&lt;br /&gt;
Memcached PHP 7.1 extension &lt;br /&gt;
* [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-memcached.html php71u-pecl-memcached] from IUS CentOS 7.x repository.&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature if available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cron performance ==&lt;br /&gt;
&lt;br /&gt;
Cron is a very important part of the overall performance of moodle as many asynchronous processes are offloaded to cron, so it needs to be running and have enough through put to handle the work being given to it by the front ends.&lt;br /&gt;
&lt;br /&gt;
See [[Cron_with_Unix_or_Linux#High_performance_cron_tasks]]&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;number one thing&#039;&#039;&#039; you can do to improve MySQL performance is to read, understand and implement the recommendations in the [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool.html Innodb Buffer Pool] article.&lt;br /&gt;
&lt;br /&gt;
The [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html buffer pool size] can safely be changed while your server is running, as long as your server has enough memory (RAM) to accommodate the value you set.  On a machine that is dedicated to MySQL, you can safely set this value to 80% of available memory.&lt;br /&gt;
&lt;br /&gt;
Consider setting [https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_buffer_pool_instances innodb_buffer_pool_instances] to the number of cores, vCPUs, or chips you have available.  Adjust this value in accordance with the recommendations in the [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.pl/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
=== Read replicas ===&lt;br /&gt;
&lt;br /&gt;
Since Moodle 3.9 you can configure read replica&#039;s to be used where possible. For very large systems as much as 80-90% of the DB load can be moved away from the primary. For configuration see config-dist:&lt;br /&gt;
&lt;br /&gt;
https://github.com/moodle/moodle/blob/master/config-dist.php#L84-L117&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
*[https://enovation.ie/moodle-performance-investigation-using-performance-info/ Moodle performance investigation – using performance info ]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Recommandations_de_performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Performance_recommendations&amp;diff=140550</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Performance_recommendations&amp;diff=140550"/>
		<updated>2021-05-31T12:13:16Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: Add section on read replicas&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Performance}}&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
It can be interesting to install and use the [https://moodle.org/plugins/report_benchmark Benchmark plugin] in order to find the bottlenecks of your system that specifically affect Moodle.&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore and cache areas (see [[Caching]]), but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
On very large, load-balanced, systems the performance of the shared components become critical. It&#039;s important that your shared file areas are properly tuned and that you use an effective cache (Redis is highly recommended). A good understanding of these areas of system administration should be considered a minimum requirement. &lt;br /&gt;
&lt;br /&gt;
===Server cluster===&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=88214 Installation for 3000 simultaneous users]&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (e.g. 4GB or more). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* If your &#039;moodledata&#039; area is going to be on relatively slow storage (e.g. NFS mount on to a NAS device) you will  have performance issues with the default cache configuration (which writes to this storage). See the page on [[Caching]] and choose an alternative. Redis is recommended. Using [https://en.wikipedia.org/wiki/GlusterFS GlusterFS] / [https://en.wikipedia.org/wiki/OCFS2 OCFS2] / [https://en.wikipedia.org/wiki/GFS2 GFS2] on a [https://en.wikipedia.org/wiki/Storage_Area_Network SAN] device and [https://en.wikipedia.org/wiki/Fibre_Channel Fiber Channel] could improve performance (See more info on the Moodle [https://moodle.org/mod/forum/discuss.php?d=214680#p1123124 forum thread], [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 NFS performance tuing] )&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the [https://moodle.org/mod/forum/discuss.php?d=310501#p1242382 &amp;quot;async&amp;quot; and &amp;quot;noatime&amp;quot;] options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* PHP contains a built-in accelerator. Make sure it is enabled. &lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS6 ISAPI module&#039;&#039;&#039; (rather than a CGI). IIS 7.0/7.5 (Windows Server 2008/R2) users should choose a FastCGI installation for best performance.&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini. The default value for the memory_limit directive is 128M. On some sites, it may need to be larger - especially for some backup operations. &lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
* Use [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html PHP-FPM] (with apache).&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
==== APC ====&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
==== eAccelerator ====&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
==== MemCached ====&lt;br /&gt;
Memcached server (daemon)&lt;br /&gt;
* [https://www.tecmint.com/install-memcached-on-centos-7/ Installing Memcached on CentOS 7.x (linux)] (as of php 7.x, only memcached is available)&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-memcached-on-centos-7 How To Install and Secure Memcached on CentOS 7]&lt;br /&gt;
* [https://wiki.zimbra.com/wiki/Blocking_Memcached_Attack#Iptables_rules_for_Redhat_based_servers Iptables rules for Redhat based servers]&lt;br /&gt;
Memcached PHP 7.1 extension &lt;br /&gt;
* [https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/repoview/php71u-pecl-memcached.html php71u-pecl-memcached] from IUS CentOS 7.x repository.&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; directive correctly (&#039;&#039;&#039;MaxClients&#039;&#039;&#039; before Apache 2.4). Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxRequestWorkers = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB but Moodle can easily use up to 100MB per process, so a general rule of thumb is to divide your available memory in megabytes by 100 to get a conservative setting for MaxClients. You are quite likely to find yourself lowering the MaxRequestWorkers from its default of 150 on a Moodle server. To get a more accurate estimate read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxRequestWorkers&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxRequestWorkers higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxConnectionsPerChild&#039;&#039;&#039; (&#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; before Apache 2.4) in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml text/x-js text/javascript text/css application/javascript&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
* Use Apache [http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html event] [http://httpd.apache.org/docs/current/mpm.html MPM] (and not the default Prefork or Worker)&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
===X-Sendfile===&lt;br /&gt;
&lt;br /&gt;
X-Sendfile modules improve performance when sending large files from Moodle. It is recommended to configure your web server and Moodle to use this feature if available.&lt;br /&gt;
&lt;br /&gt;
Configure web server:&lt;br /&gt;
* Apache - https://tn123.org/mod_xsendfile/&lt;br /&gt;
* Lighttpd - http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file&lt;br /&gt;
* Nginx - http://wiki.nginx.org/XSendfile&lt;br /&gt;
&lt;br /&gt;
Enable support in config.php (see config-dist.php):&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Sendfile&#039;;           // Apache {@see https://tn123.org/mod_xsendfile/}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-LIGHTTPD-send-file&#039;; // Lighttpd {@see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file}&lt;br /&gt;
//     $CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;     // Nginx {@see http://wiki.nginx.org/XSendfile}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure file location prefixes if your server implementation requires it:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
//     $CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
//         &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot,&lt;br /&gt;
//         &#039;/cachedir/&#039; =&amp;gt; &#039;/var/www/moodle/cache&#039;,    // for custom $CFG-&amp;gt;cachedir locations&lt;br /&gt;
//         &#039;/localcachedir/&#039; =&amp;gt; &#039;/var/local/cache&#039;,    // for custom $CFG-&amp;gt;localcachedir locations&lt;br /&gt;
//         &#039;/tempdir/&#039;  =&amp;gt; &#039;/var/www/moodle/temp&#039;,     // for custom $CFG-&amp;gt;tempdir locations&lt;br /&gt;
//         &#039;/filedir&#039;   =&amp;gt; &#039;/var/www/moodle/filedir&#039;,  // for custom $CFG-&amp;gt;filedir locations&lt;br /&gt;
//     );&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cron performance ==&lt;br /&gt;
&lt;br /&gt;
Cron is a very important part of the overall performance of moodle as many asynchronous processes are offloaded to cron, so it needs to be running and have enough through put to handle the work being given to it by the front ends.&lt;br /&gt;
&lt;br /&gt;
See [[Cron_with_Unix_or_Linux#High_performance_cron_tasks]]&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;number one thing&#039;&#039;&#039; you can do to improve MySQL performance is to read, understand and implement the recommendations in the [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool.html Innodb Buffer Pool] article.&lt;br /&gt;
&lt;br /&gt;
The [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html buffer pool size] can safely be changed while your server is running, as long as your server has enough memory (RAM) to accommodate the value you set.  On a machine that is dedicated to MySQL, you can safely set this value to 80% of available memory.&lt;br /&gt;
&lt;br /&gt;
Consider setting [https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_buffer_pool_instances innodb_buffer_pool_instances] to the number of cores, vCPUs, or chips you have available.  Adjust this value in accordance with the recommendations in the [https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool-resize.html MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.pl/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL (like [http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server this one]), and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Splitting &#039;&#039;&#039;mdl_log&#039;&#039;&#039; to several tables and using a VIEW with UNION to read them as one. (See Tim Hunt [https://moodle.org/mod/forum/discuss.php?d=243531#p1104165 explanation] on the Moodle forums)&lt;br /&gt;
&lt;br /&gt;
=== Read replicas ===&lt;br /&gt;
&lt;br /&gt;
{{Moodle 3.9}}&lt;br /&gt;
&lt;br /&gt;
Since Moodle 3.9 you can configure read replica&#039;s to be used where possible. For very large systems as much as 80-90% of the DB load can be moved away from the primary. For configuration see config-dist:&lt;br /&gt;
&lt;br /&gt;
https://github.com/moodle/moodle/blob/master/config-dist.php#L84-L117&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cli/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming too many resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. This is being tested to optimize the SQL query.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. However, it has been getting better in recent versions, and we don&#039;t know of any good, up-to-date performance measurements. (Here is a [http://moodle.org/mod/forum/discuss.php?d=68579 case study from 2007 with 300 quiz users].). The following suggestions were described by [https://moodle.org/user/view.php?id=94615&amp;amp;course=5 Al Rachels] in [https://moodle.org/mod/forum/discuss.php?d=347126 this forum thread]:&lt;br /&gt;
** make sure both Moodle, and the operating system, are installed on a [https://en.wikipedia.org/wiki/Solid-state_drive solid state drive]&lt;br /&gt;
** upgrade to and use [https://docs.moodle.org/dev/Moodle_and_PHP7 PHP 7]&lt;br /&gt;
** run MySQLTuner and implement its recommendations&lt;br /&gt;
&lt;br /&gt;
See [[Performance settings]] for more information on performance-related Moodle settings.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
*[http://opensourceelearning.blogspot.be/2012/10/why-your-moodle-site-is-slow-five.html Why Your Moodle Site is Slow: Five Simple Settings] blog post from Jonathan Moore &lt;br /&gt;
*I teach with Moodle perfomance testing: http://www.iteachwithmoodle.com/2012/11/17/moodle-2-4-beta-performance-test-comparison-with-moodle-2-3/&lt;br /&gt;
*[http://jfilip.ca/2013/08/20/moodle-2-4-5-vs-2-5-1-performance-and-muc-apc-cache-store/ Moodle 2.4.5 vs 2.5.2 performance and MUC APC cahe store]&lt;br /&gt;
*[http://jfilip.ca/2013/09/25/moodle-performance-testing-2-4-6-vs-2-5-2-vs-2-6dev/ Moodle performance testing 2.4.6 vs 2.5.2 vs 2.6dev]&lt;br /&gt;
*[http://jfilip.ca/2013/09/24/moodle-performance-analysis-revisted-now-with-mariadb/ Moodle performance analysis revisited (now with MariaDB)]&lt;br /&gt;
*[http://tjhunt.blogspot.ca/2013/05/performance-testing-moodle.html Tim Hunt&#039;s blog (May 2, 2013) on performance testing Moodle]&lt;br /&gt;
*[http://newrelic.com/ New Relic, Application Performance Monitoring]&lt;br /&gt;
*[http://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html Performance enhacements for Apache and PHP (Apache Event MPM and PHP-FPM)]&lt;br /&gt;
*[https://scholarlms.net/performance-recommendations/ Performance recommendations]&lt;br /&gt;
*[https://enovation.ie/moodle-performance-investigation-using-performance-info/ Moodle performance investigation – using performance info ]&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=240391#unread Advice on optimising php/db code in moodle2+]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=243531 Moodle 2.5 performance testing at the OU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=273602 100 active users limit with 4vCPU]&lt;br /&gt;
* [https://moodle.org/mod/forum/discuss.php?d=336603#p1356423 Performance Tip ... shared...]&lt;br /&gt;
&lt;br /&gt;
[[es:Recomendaciones sobre desempeño]]&lt;br /&gt;
[[fr:Recommandations_de_performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[de:Geschwindigkeitsempfehlungen]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Apache&amp;diff=140526</id>
		<title>Apache</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Apache&amp;diff=140526"/>
		<updated>2021-05-24T23:08:26Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
&#039;&#039;&#039;This article refers to the &#039;Apache HTTP server&#039;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The Apache HTTP server is the software that (along with the PHP scripting language) &#039;runs&#039; Moodle. Note that there are alternatives (e.g. IIS on Windows, Nginx on Linux, MacOS) but the Apache HTTP Server is very popular on all platforms. &lt;br /&gt;
&lt;br /&gt;
== Installing Apache ==&lt;br /&gt;
Installers are available for most platforms from http://httpd.apache.org/download.cgi. The official installation instructions are here: http://httpd.apache.org/docs/2.0/install.html. If you are running Linux then you are recommended to use the packaged version if you can. For example, in Debian/Ubuntu it is simply:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install apache2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the documentation for your particular platform for the instructions. Apache is straightforward to build from source if you have to and the PHP documentation contains an article on building both Apache and PHP together - although you should rarely need to do that.&lt;br /&gt;
&lt;br /&gt;
==Performance==&lt;br /&gt;
&lt;br /&gt;
See [[Performance recommendations]]&lt;br /&gt;
&lt;br /&gt;
==Slasharguments==&lt;br /&gt;
&lt;br /&gt;
The function &#039;&#039;slash arguments&#039;&#039; is required for various features in Moodle to work correctly, as described in [[Using slash arguments]].&lt;br /&gt;
&lt;br /&gt;
To turn it on, add this line to your &#039;&#039;httpd.conf&#039;&#039;, or to a &#039;&#039;.htaccess&#039;&#039; file in your local directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
AcceptPathInfo On&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note:&#039;&#039; When using &amp;quot;.htaccess&amp;quot; in your local Moodle install folder, you may need to include/enable &amp;quot;AllowOverride Directive&amp;quot; in &amp;quot;httpd.conf&amp;quot;, first.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note:&#039;&#039; Using .htaccess file will cause performance hit on your server!&lt;br /&gt;
&lt;br /&gt;
If you are using Ionos (formerly 1&amp;amp;1) shared webhosting, the above does not work, there is a known bug when using PHP as CGI.  The solution is to create a php.ini file in the moodle directory with this content:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
cgi.fix_pathinfo = 0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also Ionos requires that this php.ini be in every directory that a script executes.  Use the procedure below to link a php.ini in every subdirectory back to your original php.ini file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
cd your_moodle_directory&lt;br /&gt;
find -type d -exec ln -s $PWD/php.ini {}/php.ini \;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: [https://www.ionos.com/help/hosting/using-php-for-web-projects/applying-php-settings-to-all-subdirectories/ Ionos php.ini Help] &lt;br /&gt;
&lt;br /&gt;
This may affect other shared hosting providers as well.&lt;br /&gt;
&lt;br /&gt;
== Handling 40x errors  ==&lt;br /&gt;
&lt;br /&gt;
This enables missing files to be themed by Moodle&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ErrorDocument 404 /error/index.php&lt;br /&gt;
 &lt;br /&gt;
# This sends any 403 from apache through to the same page, but also&lt;br /&gt;
# overrides the http status with 404 instead for better security.&lt;br /&gt;
ErrorDocument 403 /error/index.php?code=404&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Hiding internal paths ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
RewriteEngine On&lt;br /&gt;
 &lt;br /&gt;
# RewriteRule &amp;quot;(\/vendor\/)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/node_modules\/)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(^|/)\.(?!well-known\/)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(composer\.json)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\.lock)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/environment.xml)&amp;quot; - [F]&lt;br /&gt;
# Options -Indexes&lt;br /&gt;
# RewriteRule &amp;quot;(\/install.xml)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/README)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/readme)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/moodle_readme)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/upgrade\.txt)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(phpunit\.xml\.dist)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/tests\/behat\/)&amp;quot; - [F]&lt;br /&gt;
# RewriteRule &amp;quot;(\/fixtures\/)&amp;quot; - [F]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==SSL==&lt;br /&gt;
&lt;br /&gt;
Moodle has an option to enable HTTPS for the whole site or for just the login pages; either option requires that your web server is configured for SSL.&lt;br /&gt;
&lt;br /&gt;
* Whole site HTTPS is enabled by changing http://&amp;lt;url&amp;gt; to https:// &amp;lt;url&amp;gt; in your config.php &#039;wwwroot&#039; parameter.&lt;br /&gt;
* Login only HTTPS is enabled by setting the &#039;loginhttps&#039; parameter, where the wwwroot schema should remain as http://&lt;br /&gt;
&lt;br /&gt;
NOTE: Login only https was deprecated and removed from Moodle 3.4: https://tracker.moodle.org/browse/MDL-42834&lt;br /&gt;
&lt;br /&gt;
Login only https is available in Moodle 3.3 and earlier in the admin interface via Administration&amp;gt;Security&amp;gt;HTTP Security and checking the button. (Note the warning and see ssl section below)&lt;br /&gt;
&lt;br /&gt;
Prior to Moodle 2.3 It was not advised to run the whole site over HTTPS due to legacy restrictions with client-side caching. This is no longer the case assuming client browsers support the &#039;Cache-Control: public&#039; method, which all supported browsers for this version of Moodle do.&lt;br /&gt;
&lt;br /&gt;
To use HTTPS you will need to obtain an SSL certificate, you have two options:&lt;br /&gt;
&lt;br /&gt;
* Generate a self-signed certificate. This is fine on (say) an Intranet but unsuitable for the public internet, but users will we warned the certificated is untrusted when used publicly.&lt;br /&gt;
* Purchase a certificate from a vendor. There is a surprising range of prices and value-added services available. Some hosting companies even provide free certificates. &lt;br /&gt;
&lt;br /&gt;
Debian provides instructions for installing a self-signed certificate [https://wiki.debian.org/Self-Signed_Certificate on their wiki] and includes general information on configuring Apache for SSL.&lt;br /&gt;
If you purchase a vendor certificate you will normally receive instructions for installing it.&lt;br /&gt;
&lt;br /&gt;
A basic Apache SSL configuration can be summarised as:&lt;br /&gt;
&lt;br /&gt;
 Listen 443&lt;br /&gt;
 NameVirtualHost *:443&lt;br /&gt;
 &amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
     SSLEngine On&lt;br /&gt;
     SSLCertificateFile /path/to/your/certificate.crt&lt;br /&gt;
     SSLCertificateKeyFile /path/to/your/certificate.key&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://httpd.apache.org/ The Apache HTTP Server Project homepage]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Apache_HTTP_Server Wikipedia article on the Apache HTTP Server]&lt;br /&gt;
* [http://httpd.apache.org/docs/2.0/misc/perf-tuning.html Apache Performance Tuning article at the official homepage]&lt;br /&gt;
* [https://els.earlham.edu/cayaraa/weblog/1468.html Making Moodle work with SSL]&lt;br /&gt;
* [http://www.krufix.de/ Using the same Moodle twice in local network and Internet via SSL-Proxy] (in German)&lt;br /&gt;
&lt;br /&gt;
[[pl:Apache]]&lt;br /&gt;
[[ja:Apache]]&lt;br /&gt;
[[de:Apache]]&lt;br /&gt;
[[es:Apache]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Mall:Installing_Moodle&amp;diff=140520</id>
		<title>Mall:Installing Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Mall:Installing_Moodle&amp;diff=140520"/>
		<updated>2021-05-24T09:33:52Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div class=&amp;quot;navtrail&amp;quot;&amp;gt;[[Main page]] ► [[Installation]] ► [[{{PAGENAME}}]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;sideblock right&amp;quot; style=&amp;quot;width: 16em;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;header&amp;quot;&amp;gt;[[Installation]]&amp;lt;/div&amp;gt;	&lt;br /&gt;
&amp;lt;div class=&amp;quot;content&amp;quot;&amp;gt;&lt;br /&gt;
*[[Installing Moodle]]&lt;br /&gt;
*[[Installation quick guide]]&lt;br /&gt;
*[[Cron]]&lt;br /&gt;
*[[Nginx]]&lt;br /&gt;
*[[Apache]]&lt;br /&gt;
*[[Internet_Information_Services]]&lt;br /&gt;
*[[Installing plugins]]&lt;br /&gt;
*[[Installation FAQ]]&lt;br /&gt;
*[[Upgrading]]&lt;br /&gt;
*[[Upgrade overview]]&lt;br /&gt;
*[[Automatic updates deployment]]&lt;br /&gt;
*[[Git for Administrators|Git guide]]&lt;br /&gt;
*[[Administration via command line]]&lt;br /&gt;
*[[Upgrading FAQ]]&lt;br /&gt;
*[[Moodle migration]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;[[Category:Installation]]&amp;lt;/includeonly&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;This template will categorise articles that include it into [[:Category:Installation]].&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=140519</id>
		<title>Nginx</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=140519"/>
		<updated>2021-05-24T09:27:09Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* XSendfile aka X-Accel-Redirect */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}[[Nginx]] [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavours. It also has a proof of concept port for Microsoft Windows.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following is community-contributed documentation on Nginx configuration. Amendments and additions are welcome.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Nginx configuration ==&lt;br /&gt;
&lt;br /&gt;
=== PHP-FPM ===&lt;br /&gt;
&lt;br /&gt;
Nginx is usually configured to interface with PHP via [http://php.net/manual/en/install.fpm.php php-fpm]. This is both fast and robust.&lt;br /&gt;
&lt;br /&gt;
PHP-FPM&#039;s default behaviour for pools is usually to restrict the execution of scripts to a specific extension, i.e. .php. You should ensure that this behaviour is configured within your particular package/distribution, e.g. for debian,&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/etc/php5/fpm/pool.d/www.conf&#039;&#039;&#039;&lt;br /&gt;
 security.limit_extensions = .php&lt;br /&gt;
&lt;br /&gt;
=== Nginx ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following &#039;slash arguments&#039; compatible &#039;location&#039; block to your vhosts &#039;server&#039; in your nginx configuration (further explanation at &#039;[[Using slash arguments]]&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;nginx.conf location:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ [^/]\.php(/|$) {&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000 (or your php-fpm socket);&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work try the following:&lt;br /&gt;
Note: This was for CentOS 7.6 (1804), MariaDB 10.3, Nginx 1.15 and PHP 7.3.5&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ ^(.+\.php)(.*)$ {&lt;br /&gt;
    root /usr/share/nginx/html/moodle/;&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(.*)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000;&lt;br /&gt;
    include /etc/nginx/mime.types;&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you find that this does not work (scripts, styles, and images not loading) &#039;&#039;&#039;and&#039;&#039;&#039; that there are &amp;lt;code&amp;gt;open() &amp;quot;...&amp;quot; failed (20: Not a directory)&amp;lt;/code&amp;gt; lines appearing in your logs: Check whether there are any directives related to static content &#039;&#039;&#039;before&#039;&#039;&#039; this block and try moving them &#039;&#039;&#039;after&#039;&#039;&#039; this block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another potential pitfall is the use of &#039;&#039;&#039;try_files&#039;&#039;&#039;. Many guides recommend configurations like &amp;lt;pre&amp;gt;try_files $fastcgi_script_name =404;&amp;lt;/pre&amp;gt;. But if try_files is used, nginx deletes the content of the &#039;&#039;&#039;$fastcgi_path_info&#039;&#039;&#039; variable (this is [https://trac.nginx.org/nginx/ticket/321 intended behavior]). This causes &#039;&#039;&#039;PATH_INFO&#039;&#039;&#039; to also be empty, so slash arguments don&#039;t work.&lt;br /&gt;
An alternative is the use of &amp;lt;pre&amp;gt;if(!-f $document_root$fastcgi_script_name) {return 404;}&amp;lt;/pre&amp;gt; [https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/#connecting-nginx-to-php-fpm as recommended] by the nginx documentation, although the nginx documentation also recommends [https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ not using if].&lt;br /&gt;
&lt;br /&gt;
==== Error pages ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This passes 404 pages to Moodle so they can be themed&lt;br /&gt;
error_page 404 /error/index.php;    error_page 403 =404 /error/index.php;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Hiding internal files ====&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Hide all dot files but allow &amp;quot;Well-Known URIs&amp;quot; as per RFC 5785&lt;br /&gt;
location ~ /\.(?!well-known).* {&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
# This should be after the php fpm rule and very close to the last nginx ruleset.&lt;br /&gt;
# Don&#039;t allow direct access to various internal files. See MDL-69333&lt;br /&gt;
location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|/upgrade\.txt|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml) {&lt;br /&gt;
    deny all;&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== XSendfile aka X-Accel-Redirect ====&lt;br /&gt;
&lt;br /&gt;
Setting Moodle and Nginx to use XSendfile functionality is a big win as it frees PHP from delivering files allowing Nginx to do what it does best, i.e. deliver files. &lt;br /&gt;
&lt;br /&gt;
Enable xsendfile for Nginx in Moodles config.php, this is documented in the config-dist.php, a minimal configuration look like this,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;&lt;br /&gt;
$CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
    &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Accompany this with a matching &#039;location&#039; block in your nginx server configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location /dataroot/ {&lt;br /&gt;
    internal;&lt;br /&gt;
    alias &amp;amp;lt;full_moodledata_path&amp;amp;gt;; # ensure the path ends with /&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The definition of &#039;internal&#039; here is &#039;&#039;&#039;critical&#039;&#039;&#039; as it prevents client access to your dataroot.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* Real &amp;lt;tt&amp;gt;PATH_INFO&amp;lt;/tt&amp;gt; support:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=278916&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=307388&lt;br /&gt;
* &#039;&#039;&#039;[Deprecated]&#039;&#039;&#039; Internal rewriting to the HTTP GET &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=83445&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
&lt;br /&gt;
[[es:Nginx]]&lt;br /&gt;
[[pt-br:Nginx]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=140518</id>
		<title>Nginx</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=140518"/>
		<updated>2021-05-24T09:26:54Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}[[Nginx]] [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavours. It also has a proof of concept port for Microsoft Windows.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following is community-contributed documentation on Nginx configuration. Amendments and additions are welcome.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Nginx configuration ==&lt;br /&gt;
&lt;br /&gt;
=== PHP-FPM ===&lt;br /&gt;
&lt;br /&gt;
Nginx is usually configured to interface with PHP via [http://php.net/manual/en/install.fpm.php php-fpm]. This is both fast and robust.&lt;br /&gt;
&lt;br /&gt;
PHP-FPM&#039;s default behaviour for pools is usually to restrict the execution of scripts to a specific extension, i.e. .php. You should ensure that this behaviour is configured within your particular package/distribution, e.g. for debian,&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/etc/php5/fpm/pool.d/www.conf&#039;&#039;&#039;&lt;br /&gt;
 security.limit_extensions = .php&lt;br /&gt;
&lt;br /&gt;
=== Nginx ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following &#039;slash arguments&#039; compatible &#039;location&#039; block to your vhosts &#039;server&#039; in your nginx configuration (further explanation at &#039;[[Using slash arguments]]&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;nginx.conf location:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ [^/]\.php(/|$) {&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000 (or your php-fpm socket);&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work try the following:&lt;br /&gt;
Note: This was for CentOS 7.6 (1804), MariaDB 10.3, Nginx 1.15 and PHP 7.3.5&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ ^(.+\.php)(.*)$ {&lt;br /&gt;
    root /usr/share/nginx/html/moodle/;&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(.*)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000;&lt;br /&gt;
    include /etc/nginx/mime.types;&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you find that this does not work (scripts, styles, and images not loading) &#039;&#039;&#039;and&#039;&#039;&#039; that there are &amp;lt;code&amp;gt;open() &amp;quot;...&amp;quot; failed (20: Not a directory)&amp;lt;/code&amp;gt; lines appearing in your logs: Check whether there are any directives related to static content &#039;&#039;&#039;before&#039;&#039;&#039; this block and try moving them &#039;&#039;&#039;after&#039;&#039;&#039; this block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another potential pitfall is the use of &#039;&#039;&#039;try_files&#039;&#039;&#039;. Many guides recommend configurations like &amp;lt;pre&amp;gt;try_files $fastcgi_script_name =404;&amp;lt;/pre&amp;gt;. But if try_files is used, nginx deletes the content of the &#039;&#039;&#039;$fastcgi_path_info&#039;&#039;&#039; variable (this is [https://trac.nginx.org/nginx/ticket/321 intended behavior]). This causes &#039;&#039;&#039;PATH_INFO&#039;&#039;&#039; to also be empty, so slash arguments don&#039;t work.&lt;br /&gt;
An alternative is the use of &amp;lt;pre&amp;gt;if(!-f $document_root$fastcgi_script_name) {return 404;}&amp;lt;/pre&amp;gt; [https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/#connecting-nginx-to-php-fpm as recommended] by the nginx documentation, although the nginx documentation also recommends [https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ not using if].&lt;br /&gt;
&lt;br /&gt;
==== Error pages ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This passes 404 pages to Moodle so they can be themed&lt;br /&gt;
error_page 404 /error/index.php;    error_page 403 =404 /error/index.php;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Hiding internal files ====&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Hide all dot files but allow &amp;quot;Well-Known URIs&amp;quot; as per RFC 5785&lt;br /&gt;
location ~ /\.(?!well-known).* {&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
# This should be after the php fpm rule and very close to the last nginx ruleset.&lt;br /&gt;
# Don&#039;t allow direct access to various internal files. See MDL-69333&lt;br /&gt;
location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|/upgrade\.txt|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml) {&lt;br /&gt;
    deny all;&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== XSendfile aka X-Accel-Redirect =====&lt;br /&gt;
&lt;br /&gt;
Setting Moodle and Nginx to use XSendfile functionality is a big win as it frees PHP from delivering files allowing Nginx to do what it does best, i.e. deliver files. &lt;br /&gt;
&lt;br /&gt;
Enable xsendfile for Nginx in Moodles config.php, this is documented in the config-dist.php, a minimal configuration look like this,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;&lt;br /&gt;
$CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
    &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Accompany this with a matching &#039;location&#039; block in your nginx server configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location /dataroot/ {&lt;br /&gt;
    internal;&lt;br /&gt;
    alias &amp;amp;lt;full_moodledata_path&amp;amp;gt;; # ensure the path ends with /&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The definition of &#039;internal&#039; here is &#039;&#039;&#039;critical&#039;&#039;&#039; as it prevents client access to your dataroot.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* Real &amp;lt;tt&amp;gt;PATH_INFO&amp;lt;/tt&amp;gt; support:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=278916&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=307388&lt;br /&gt;
* &#039;&#039;&#039;[Deprecated]&#039;&#039;&#039; Internal rewriting to the HTTP GET &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=83445&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
&lt;br /&gt;
[[es:Nginx]]&lt;br /&gt;
[[pt-br:Nginx]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=140517</id>
		<title>Nginx</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Nginx&amp;diff=140517"/>
		<updated>2021-05-24T09:26:27Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: Add error pages and hiding internal files&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}[[Nginx]] [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. It is licensed under the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, as well as on other *nix flavours. It also has a proof of concept port for Microsoft Windows.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The following is community-contributed documentation on Nginx configuration. Amendments and additions are welcome.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Nginx configuration ==&lt;br /&gt;
&lt;br /&gt;
=== PHP-FPM ===&lt;br /&gt;
&lt;br /&gt;
Nginx is usually configured to interface with PHP via [http://php.net/manual/en/install.fpm.php php-fpm]. This is both fast and robust.&lt;br /&gt;
&lt;br /&gt;
PHP-FPM&#039;s default behaviour for pools is usually to restrict the execution of scripts to a specific extension, i.e. .php. You should ensure that this behaviour is configured within your particular package/distribution, e.g. for debian,&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;/etc/php5/fpm/pool.d/www.conf&#039;&#039;&#039;&lt;br /&gt;
 security.limit_extensions = .php&lt;br /&gt;
&lt;br /&gt;
=== Nginx ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following &#039;slash arguments&#039; compatible &#039;location&#039; block to your vhosts &#039;server&#039; in your nginx configuration (further explanation at &#039;[[Using slash arguments]]&#039;).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;nginx.conf location:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ [^/]\.php(/|$) {&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000 (or your php-fpm socket);&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the above does not work try the following:&lt;br /&gt;
Note: This was for CentOS 7.6 (1804), MariaDB 10.3, Nginx 1.15 and PHP 7.3.5&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location ~ ^(.+\.php)(.*)$ {&lt;br /&gt;
    root /usr/share/nginx/html/moodle/;&lt;br /&gt;
    fastcgi_split_path_info  ^(.+\.php)(.*)$;&lt;br /&gt;
    fastcgi_index            index.php;&lt;br /&gt;
    fastcgi_pass             127.0.0.1:9000;&lt;br /&gt;
    include /etc/nginx/mime.types;&lt;br /&gt;
    include                  fastcgi_params;&lt;br /&gt;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;&lt;br /&gt;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you find that this does not work (scripts, styles, and images not loading) &#039;&#039;&#039;and&#039;&#039;&#039; that there are &amp;lt;code&amp;gt;open() &amp;quot;...&amp;quot; failed (20: Not a directory)&amp;lt;/code&amp;gt; lines appearing in your logs: Check whether there are any directives related to static content &#039;&#039;&#039;before&#039;&#039;&#039; this block and try moving them &#039;&#039;&#039;after&#039;&#039;&#039; this block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another potential pitfall is the use of &#039;&#039;&#039;try_files&#039;&#039;&#039;. Many guides recommend configurations like &amp;lt;pre&amp;gt;try_files $fastcgi_script_name =404;&amp;lt;/pre&amp;gt;. But if try_files is used, nginx deletes the content of the &#039;&#039;&#039;$fastcgi_path_info&#039;&#039;&#039; variable (this is [https://trac.nginx.org/nginx/ticket/321 intended behavior]). This causes &#039;&#039;&#039;PATH_INFO&#039;&#039;&#039; to also be empty, so slash arguments don&#039;t work.&lt;br /&gt;
An alternative is the use of &amp;lt;pre&amp;gt;if(!-f $document_root$fastcgi_script_name) {return 404;}&amp;lt;/pre&amp;gt; [https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/#connecting-nginx-to-php-fpm as recommended] by the nginx documentation, although the nginx documentation also recommends [https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ not using if].&lt;br /&gt;
&lt;br /&gt;
=== Error pages ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# This passes 404 pages to Moodle so they can be themed&lt;br /&gt;
error_page 404 /error/index.php;    error_page 403 =404 /error/index.php;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Hiding internal files ===&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Hide all dot files but allow &amp;quot;Well-Known URIs&amp;quot; as per RFC 5785&lt;br /&gt;
location ~ /\.(?!well-known).* {&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
# This should be after the php fpm rule and very close to the last nginx ruleset.&lt;br /&gt;
# Don&#039;t allow direct access to various internal files. See MDL-69333&lt;br /&gt;
location ~ (/vendor/|/node_modules/|composer\.json|/readme|/README|readme\.txt|/upgrade\.txt|db/install\.xml|/fixtures/|/behat/|phpunit\.xml|\.lock|environment\.xml) {&lt;br /&gt;
    deny all;&lt;br /&gt;
    return 404;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== XSendfile aka X-Accel-Redirect =====&lt;br /&gt;
&lt;br /&gt;
Setting Moodle and Nginx to use XSendfile functionality is a big win as it frees PHP from delivering files allowing Nginx to do what it does best, i.e. deliver files. &lt;br /&gt;
&lt;br /&gt;
Enable xsendfile for Nginx in Moodles config.php, this is documented in the config-dist.php, a minimal configuration look like this,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;xsendfile = &#039;X-Accel-Redirect&#039;;&lt;br /&gt;
$CFG-&amp;gt;xsendfilealiases = array(&lt;br /&gt;
    &#039;/dataroot/&#039; =&amp;gt; $CFG-&amp;gt;dataroot&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Accompany this with a matching &#039;location&#039; block in your nginx server configuration.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
location /dataroot/ {&lt;br /&gt;
    internal;&lt;br /&gt;
    alias &amp;amp;lt;full_moodledata_path&amp;amp;gt;; # ensure the path ends with /&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The definition of &#039;internal&#039; here is &#039;&#039;&#039;critical&#039;&#039;&#039; as it prevents client access to your dataroot.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* Real &amp;lt;tt&amp;gt;PATH_INFO&amp;lt;/tt&amp;gt; support:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=278916&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=307388&lt;br /&gt;
* &#039;&#039;&#039;[Deprecated]&#039;&#039;&#039; Internal rewriting to the HTTP GET &amp;lt;tt&amp;gt;file&amp;lt;/tt&amp;gt; parameter:&lt;br /&gt;
** https://moodle.org/mod/forum/discuss.php?d=83445&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
&lt;br /&gt;
[[es:Nginx]]&lt;br /&gt;
[[pt-br:Nginx]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139877</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139877"/>
		<updated>2021-03-15T22:53:31Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* $CFG-&amp;gt;backuptempdir */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;alternative_file_system_class===&lt;br /&gt;
&lt;br /&gt;
By default all uploaded content files are de-duplicated are stored inside [$CFG-&amp;gt;dataroot]/filedir. But you can replace this is an alternative file store, like a cloud store such as AWS S3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;alternative_file_system_class = &#039;\tool_objectfs\s3_file_system&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/catalyst/moodle-tool_objectfs/&lt;br /&gt;
&lt;br /&gt;
NOTE: Even if you use an alternate filesystem you &#039;&#039;&#039;MUST&#039;&#039;&#039; still have a shared $CFG-&amp;gt;dataroot.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;backuptempdir===&lt;br /&gt;
&lt;br /&gt;
Server clusters MUST use shared filesystem for backuptempdir! This directory gets very large and fast bursts of IO but files do not generally live here for any length of time. They are write heavy and do not have much contention.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared server eg Redis. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139631</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139631"/>
		<updated>2021-02-08T22:58:52Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* $CFG-&amp;gt;alternative_file_system_class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;alternative_file_system_class===&lt;br /&gt;
&lt;br /&gt;
By default all uploaded content files are de-duplicated are stored inside [$CFG-&amp;gt;dataroot]/filedir. But you can replace this is an alternative file store, like a cloud store such as AWS S3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;alternative_file_system_class = &#039;\tool_objectfs\s3_file_system&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/catalyst/moodle-tool_objectfs/&lt;br /&gt;
&lt;br /&gt;
NOTE: Even if you use an alternate filesystem you &#039;&#039;&#039;MUST&#039;&#039;&#039; still have a shared $CFG-&amp;gt;dataroot.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared server eg Redis. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139630</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139630"/>
		<updated>2021-02-08T22:46:26Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* $CFG-&amp;gt;dataroot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;alternative_file_system_class===&lt;br /&gt;
&lt;br /&gt;
By default all uploaded content files are de-duplicated are stored inside [$CFG-&amp;gt;dataroot]/filedir. But you can replace this is an alternative file store, like a cloud store such as AWS S3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;alternative_file_system_class = &#039;\tool_objectfs\s3_file_system&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/catalyst/moodle-tool_objectfs/&lt;br /&gt;
&lt;br /&gt;
NOTE: Even if you use an alternate filesystem you MUST still have a shared $CFG-&amp;gt;dataroot.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared server eg Redis. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139629</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139629"/>
		<updated>2021-02-08T22:46:11Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: $CFG-&amp;gt;alternative_file_system_class&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;alternative_file_system_class===&lt;br /&gt;
&lt;br /&gt;
By default all uploaded content files are de-duplicated are stored inside [$CFG-&amp;gt;dataroot]/filedir. But you can replace this is an alternative file store, like a cloud store such as AWS S3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;alternative_file_system_class = &#039;\tool_objectfs\s3_file_system&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://github.com/catalyst/moodle-tool_objectfs/&lt;br /&gt;
&lt;br /&gt;
NOTE: Even if you use an alternate filesystem you MUST still have a shared $CFG-&amp;gt;dataroot.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared server eg Redis. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139627</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139627"/>
		<updated>2021-02-08T22:22:45Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Performance recommendations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared server eg Redis. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139626</id>
		<title>Server cluster</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Server_cluster&amp;diff=139626"/>
		<updated>2021-02-08T22:21:30Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* $CFG-&amp;gt;localcachedir */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is going to describe some basic information related to server clustering...&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
* database server - ACID compliant, for example PostgreSQL and MariaDB&lt;br /&gt;
* main server that is able to share dataroot - locking support recommended, for example NFS&lt;br /&gt;
* load balancer - for example Nginx&lt;br /&gt;
* cluster nodes - web servers&lt;br /&gt;
* Redis (or Memcached) server for shared MUC caches&lt;br /&gt;
&lt;br /&gt;
Note: this guide is not intended for Windows OS or any other Microsoft technologies.&lt;br /&gt;
&lt;br /&gt;
==Initial installation==&lt;br /&gt;
&lt;br /&gt;
# Perform standard CLI installation on the main server using shared database and dataroot directory.&lt;br /&gt;
# Setup web servers on cluster nodes - use local dirroot and shared database and dataroot.&lt;br /&gt;
# Configure load balancing.&lt;br /&gt;
&lt;br /&gt;
==Related config.php settings==&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;wwwroot===&lt;br /&gt;
It must be the same on all nodes, it must be the public facing URL. It cannot be dynamic.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;sslproxy===&lt;br /&gt;
Enable if you have https:// wwwroot but the SSL is done by load-balancer instead of web server.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
Enable &#039;&#039;Secure cookies only&#039;&#039; to make your site really secure, without it cookie stealing is still trivial.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;reverseproxy===&lt;br /&gt;
Enable if your nodes are accessed via different URL.&lt;br /&gt;
&lt;br /&gt;
Please note that it is not compatible with $CFG-&amp;gt;loginhttps. This is because in order for loginhttps to work, we need to know the original request, and whether it was http or https. This allows us to only provide the login form over ssl. The original request is lost when made through a &amp;quot;reverse&amp;quot; proxy / load balancer, so we cannot determine what protocol the request was made in. So we can&#039;t provide most of moodle over http and the login page over https.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dirroot===&lt;br /&gt;
It is strongly recommended that $CFG-&amp;gt;dirroot (which is automatically set via realpath(config.php)) contains the same path on all nodes. It does not need to point to the same shared directory though. The reason is that some some low level code may use the dirroot value for cache invalidation.&lt;br /&gt;
&lt;br /&gt;
The simplest solution is to have the same directory structure on each cluster node and synchronise these during each upgrade.&lt;br /&gt;
&lt;br /&gt;
The dirroot should be always read only for apache process because otherwise built in plugin installation and uninstallation would get the nodes out of sync.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;dataroot===&lt;br /&gt;
&lt;br /&gt;
This &#039;&#039;&#039;MUST&#039;&#039;&#039; be a shared directory where each cluster node is accessing the files directly. It must be very reliable, administrators cannot manipulate files directly.&lt;br /&gt;
&lt;br /&gt;
Locking support is not required, if any code tries to use file locks in dataroot outside of cachedir or muc directory it is a bug.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;tempdir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;cachedir===&lt;br /&gt;
&lt;br /&gt;
This directory &#039;&#039;&#039;MUST&#039;&#039;&#039; be shared by all cluster nodes. Locking is required.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localcachedir===&lt;br /&gt;
&lt;br /&gt;
The difference from $CFG-&amp;gt;cachedir is that the directory does not have to be shared by all cluster nodes, the file contents do not change. Use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
The nature of this path is very slow moving files that stay for a long time and are written once and never overwritten.&lt;br /&gt;
&lt;br /&gt;
===$CFG-&amp;gt;localrequestdir===&lt;br /&gt;
&lt;br /&gt;
By default this is created inside /tmp or whatever sys_get_temp_dir() returns and is generally already local disk and not shared with other nodes. This directory holds temporary folders and files which only exist for the duration of a single http request. If you do change this use local fast filesystem on each cluster node.&lt;br /&gt;
&lt;br /&gt;
==Performance recommendations==&lt;br /&gt;
&lt;br /&gt;
#Use OPcache extension on all cluster nodes.&lt;br /&gt;
#Set $CFG-&amp;gt;localcachedir to fast local filesystem on each node.&lt;br /&gt;
#Use one big central memcached server for all shared caches that support it.&lt;br /&gt;
#Use local memcached instances on cluster nodes for local caches that support it.&lt;br /&gt;
#Store user sessions in one shared memcached server. (See [[Session_handling]] for details)&lt;br /&gt;
#Use fast local directory for dirroot on each cluster node.&lt;br /&gt;
#Use dynamic cluster node management.&lt;br /&gt;
#Use transparent proxy servers.&lt;br /&gt;
&lt;br /&gt;
==Upgrade procedure==&lt;br /&gt;
&lt;br /&gt;
#Disable load balancer.&lt;br /&gt;
#Upgrade dirroot files on master server.&lt;br /&gt;
#Perform CLI upgrade.&lt;br /&gt;
#Manually reset all caches in cluster nodes - restart web server, delete localcachedir and temp directories, restart memcached, etc. Or delete all cluster nodes and create nodes from a new template.&lt;br /&gt;
#Enable load balancer.&lt;br /&gt;
&lt;br /&gt;
==Step by step guide for server clustering in Moodle 2.6==&lt;br /&gt;
From hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547 https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
&lt;br /&gt;
* 1 Determine your specific need for caches. This involves the concepts of shared cache or local cache, disk based cache or server based cache or protocol specific cache like Memcached or MongoDB. &lt;br /&gt;
** 1.1 If you have a slow shared disk, you might benefit from a local disk cache.&lt;br /&gt;
** 1.2 If you have only a few users on your Moodle site, you might not want to set up a Memcached service, even if the acceleration that Memcached provides, is very significant for the user experience.&lt;br /&gt;
** 1.3 If you want to do anything in your power for accelerating the site, you might consider MongoDB.&lt;br /&gt;
* 2 Configure the caches, test them and verify them. There is room for improvement in the examples for cache configuration. This is probably the most difficult step.&lt;br /&gt;
* 3 Install the cache support on server level. This may involve installing php modules or config for php modules.&lt;br /&gt;
* 4 Create a cache instance in MUC here: example.com/cache/admin.php?action=addstore&amp;amp;plugin=memcached&lt;br /&gt;
** 4.1 Give the cache instance some arbitrary name.&lt;br /&gt;
** 4.2 All other fields have a question mark that can be clicked on for excellent help that tells you what to fill in, and the syntax (very important).&lt;br /&gt;
** 4.3 The result should be a Configured Store Instance, with the name of your choice.&lt;br /&gt;
* 5 The final step is to deploy the created cache instances by Editing Mappings for e.g. Language string cache in the list of Known cache definitions.&lt;br /&gt;
** 5.1  While experimenting with this, I have found it a life saver to open a separate browser window, where the default setting is selected, so I just need to click on the Save button to revert the setting, just in case I lose contact with the site.&lt;br /&gt;
** 5.2 Select the name of your configured store instance from the dropdown list and click on the Save button. &lt;br /&gt;
** 5.3 Test the new cache setting. If you lose contact with the site or it behaves weirdly, try using the trick in step 1. In case of emergency you might remove the cache config file (muc/config.php) in the folder pointed to by $CFG-&amp;gt;dataroot .  It seems that Moodle writes a new default config file if it is missing.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Performance recommendations]]&lt;br /&gt;
*[[Caching]]&lt;br /&gt;
*[[:dev:Server clustering improvements proposal]]&lt;br /&gt;
*Hardware and performance forum thread [https://moodle.org/mod/forum/discuss.php?d=251547https://moodle.org/mod/forum/discuss.php?d=251547]&lt;br /&gt;
*How to Cluster Moodle on Multiple Servers for High Availability and Scalability [http://www.severalnines.com/blog/clustering-moodle-multiple-servers-high-availability-scalability]&lt;br /&gt;
* PHP session cache in a cluster &lt;br /&gt;
** https://www.digitalocean.com/community/tutorials/how-to-set-up-a-redis-server-as-a-session-handler-for-php-on-ubuntu-14-04&lt;br /&gt;
** https://inchoo.net/magento/programming-magento/session-storage-php&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Configuration_file&amp;diff=139625</id>
		<title>Configuration file</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Configuration_file&amp;diff=139625"/>
		<updated>2021-02-08T22:09:49Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Forcing the value of admin settings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
The name for Moodle&#039;s configuration file is config.php. The file is located in the moodle directory. It is not included in the Moodle download packages and is created by the installation process from the template file config-dist.php (which is included in Moodle packages).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==config-dist.php==&lt;br /&gt;
Although the installation process creates the config.php file for you, there may be times when you want to do this yourself. A sample config file, called config-dist.php, is shipped with Moodle.&lt;br /&gt;
&lt;br /&gt;
To get started simply copy config-dist.php to config.php, then edit config.php with you favourite editor. The file is very well commented. The important options (which you must supply) are all nearer the top. Other less common options are further down.&lt;br /&gt;
&lt;br /&gt;
==Setting $CFG-&amp;gt;wwwroot correctly==&lt;br /&gt;
This setting must be a fixed URL (a string constant) that points to your site. Do not try to set this with any PHP code that can generate a variable URL. This is not supported, can cause strange problems and will stop command line scripts working completely. If your site is accessed from different IP addresses this should be done with a split DNS, see [[Masquerading]]&lt;br /&gt;
&lt;br /&gt;
If you change your site from http to https, you &#039;&#039;&#039;MUST&#039;&#039;&#039; update this setting. If you don’t, you will have problems - for example (but not limited to) css scripts won’t load properly and you will also experience problems with logging in to your site. Also see [[Transitioning_to_HTTPS]]&lt;br /&gt;
&lt;br /&gt;
==Enabling password salting==&lt;br /&gt;
&lt;br /&gt;
See [[Password salting]].&lt;br /&gt;
&lt;br /&gt;
==Including passwords in backups==&lt;br /&gt;
&lt;br /&gt;
Hashed user passwords are no longer saved in backup files containing user data.&lt;br /&gt;
&lt;br /&gt;
If you really need passwords to be saved (in the rare case of restoring a [[Backup of user data|backup with user data]] to a different site), the following line may be added to config.php:&lt;br /&gt;
&lt;br /&gt;
 $CFG-&amp;gt;includeuserpasswordsinbackup = true;&lt;br /&gt;
&lt;br /&gt;
Note regarding restoring Moodle 2.5 backups to sites with old PHP versions:&lt;br /&gt;
&lt;br /&gt;
Because bcrypt is not supported in PHP versions below 5.3.7, course backups made using the $CFG-&amp;gt;includeuserpasswordsinbackup setting on a site using PHP version 5.3.7+ that are subsequently restored to a site with PHP version &amp;lt; 5.3.7 will require a password reset.&lt;br /&gt;
&lt;br /&gt;
==Changing default block layout for new courses==&lt;br /&gt;
&lt;br /&gt;
See [[Block layout]].&lt;br /&gt;
&lt;br /&gt;
==Adding extra theme directory location==&lt;br /&gt;
It is possible to add an extra themes directory stored outside of $CFG-&amp;gt;dirroot. This local directory does not have to be accessible from internet. Themes placed in the directory specified by these variables will then be available for selection using the theme selector.&lt;br /&gt;
&lt;br /&gt;
For example, should you wish to place extra themes in a subdirectory called &#039;my_moodle_themes&#039;, your config.php might look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;wwwroot   = &#039;http://my.moodle.site.edu&#039;;&lt;br /&gt;
$CFG-&amp;gt;dirroot   = &#039;/var/www/my.moodle.site.edu/public_html&#039;;&lt;br /&gt;
$CFG-&amp;gt;themedir  = $CFG-&amp;gt;dirroot . &#039;/my_moodle_themes&#039;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Disabling update notifications==&lt;br /&gt;
&lt;br /&gt;
See [[Notifications]].&lt;br /&gt;
&lt;br /&gt;
==Enabling debugging==&lt;br /&gt;
&lt;br /&gt;
See [[Debugging]].&lt;br /&gt;
&lt;br /&gt;
==Forcing the value of admin settings==&lt;br /&gt;
&lt;br /&gt;
As explained in config-dist.php, it is possible to specify normal admin settings here, the point is that they can not be changed through the standard admin settings pages any more. Just set the value in config.php like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;showuseridentity = &#039;email,idnumber,username&#039;;&lt;br /&gt;
$CFG-&amp;gt;preventexecpath = true;&lt;br /&gt;
$CFG-&amp;gt;pathtodu = &amp;quot;/usr/bin/du&amp;quot;;&lt;br /&gt;
$CFG-&amp;gt;pathtodot = &amp;quot;/usr/bin/dot&amp;quot;;&lt;br /&gt;
$CFG-&amp;gt;pathtogs = &amp;quot;/usr/bin/gs&amp;quot;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configuration for plugins can also be forced by the syntax is different, eg continuing the example above for security to always hard coded paths to all executable files:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;forced_plugin_settings[&#039;filter_text&#039;][&#039;pathconvert&#039;] = &#039;/usr/bin/convert&#039;;&lt;br /&gt;
$CFG-&amp;gt;forced_plugin_settings[&#039;filter_text&#039;][&#039;pathdvips&#039;]   = &#039;/usr/bin/dvips&#039;;&lt;br /&gt;
$CFG-&amp;gt;forced_plugin_settings[&#039;filter_text&#039;][&#039;pathdvisvgm&#039;] = &#039;/usr/bin/dvisvgm&#039;;&lt;br /&gt;
$CFG-&amp;gt;forced_plugin_settings[&#039;filter_text&#039;][&#039;pathlatex&#039;]   = &#039;/usr/bin/latex&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=137889 Moodle Salting] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[de:Konfigurationsdatei]]&lt;br /&gt;
[[es:config.php]]&lt;br /&gt;
[[fr:Fichier de configuration]]&lt;br /&gt;
[[ja:設定ファイル]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139504</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139504"/>
		<updated>2021-01-31T22:18:56Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Logging and monitoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five * entries specify the times, followed by the command, to run. This says to run the command as often as possible, ie every minute.&lt;br /&gt;
&lt;br /&gt;
See https://en.wikipedia.org/wiki/Cron#CRON_expression for details on cron expressions.&lt;br /&gt;
&lt;br /&gt;
== Logging and monitoring ==&lt;br /&gt;
&lt;br /&gt;
Ideally you should also be logging the output of cron somewhere and monitoring it for issues. You can monitor the overall status of cron to make sure there are no errors by visiting:&lt;br /&gt;
&lt;br /&gt;
Site administration / Reports / System status (/report/status/index.php)&lt;br /&gt;
&lt;br /&gt;
You can also wire this status report up to tools like Icinga / Nagios using the Check API (https://docs.moodle.org/dev/Check_API) cli commands or with the help of plugins like https://github.com/catalyst/moodle-tool_heartbeat.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code sh&amp;gt;&lt;br /&gt;
/admin/cli/checks.php&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there are errors then you can get more details for recently run tasks from the Logs column on the Scheduled task page, but this won&#039;t show adhoc task failures:&lt;br /&gt;
&lt;br /&gt;
Site administration / Server / Tasks / Scheduled tasks (/admin/tool/task/scheduledtasks.php)&lt;br /&gt;
&lt;br /&gt;
To see adhoc task failures you either need to rerun the task manually yourself and see the errors, or you need to have already collected the logs for review. For a Moodle running on a single box you could log to a simple log file, or for a cluster you might want to use syslogd or similar, eg:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php 2&amp;gt;&amp;amp;1 | /usr/bin/logger ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task processes which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a process frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
Automated backups are the worst known offender, so hypothetically if you are running 50 adhoc task processes concurrently a reasonable restriction might be to cap the backups to consume no more than half of those processes, ie 25 at most:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 25,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 5,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139503</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139503"/>
		<updated>2021-01-31T22:13:48Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Using the crontab program on Unix/Linux */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five * entries specify the times, followed by the command, to run. This says to run the command as often as possible, ie every minute.&lt;br /&gt;
&lt;br /&gt;
See https://en.wikipedia.org/wiki/Cron#CRON_expression for details on cron expressions.&lt;br /&gt;
&lt;br /&gt;
== Logging and monitoring ==&lt;br /&gt;
&lt;br /&gt;
Ideally you should also be logging the output of cron somewhere and monitoring it for issues. You can monitor the overall status of cron to make sure there are no errors by visiting:&lt;br /&gt;
&lt;br /&gt;
Site administration /Reports / System status (/report/status/index.php)&lt;br /&gt;
&lt;br /&gt;
If there are errors then you can get more details for recently run tasks from the Logs column on the Scheduled task page, but this won&#039;t show adhoc task failures:&lt;br /&gt;
&lt;br /&gt;
Site administration / Server / Tasks / Scheduled tasks (/admin/tool/task/scheduledtasks.php)&lt;br /&gt;
&lt;br /&gt;
To see adhoc task failures you either need to rerun the task manually yourself and see the errors, or you need to have already collected the logs for review. For a Moodle running on a single box you could log to a simple log file, or for a cluster you might want to use syslogd or similar, eg:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php 2&amp;gt;&amp;amp;1 | /usr/bin/logger ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task processes which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a process frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
Automated backups are the worst known offender, so hypothetically if you are running 50 adhoc task processes concurrently a reasonable restriction might be to cap the backups to consume no more than half of those processes, ie 25 at most:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 25,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 5,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139468</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139468"/>
		<updated>2021-01-28T13:53:58Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron with multiple processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task processes which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a process frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
Automated backups are the worst known offender, so hypothetically if you are running 50 adhoc task processes concurrently a reasonable restriction might be to cap the backups to consume no more than half of those processes, ie 25 at most:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 25,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 5,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139467</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139467"/>
		<updated>2021-01-28T13:50:28Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron with multiple processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task processes which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a process frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139458</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139458"/>
		<updated>2021-01-28T10:21:04Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: Removed all /dev/null piping&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139457</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139457"/>
		<updated>2021-01-28T10:19:43Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron with multiple processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139456</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139456"/>
		<updated>2021-01-28T10:14:54Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron with multiple processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139455</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139455"/>
		<updated>2021-01-28T10:14:08Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* High performance cron tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== Low latency adhoc tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. While scheduled tasks can run at most once a minute, adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. If you only run the normal admin/cli/cron.php then not only might it have to wait to process all the scheduled tasks first, if it has already finished you will have to wait until the next minute for cron to start again for it to be processed.&lt;br /&gt;
&lt;br /&gt;
Instead you can run one or more dedicated adhoc task processors which run in parallel to the main cron process.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 the --keep-alive option runs like a daemon so when the queue is empty rather then exiting it waits for new tasks to be queued so it can start processing as soon as possible.&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139454</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139454"/>
		<updated>2021-01-28T10:08:18Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron with multiple processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== High performance cron tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. But adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. You can run one or more dedicated adhoc task processors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 you can tell it to stay alive when the queue is empty waiting for new tasks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have a very high low number of adhoc tasks, or scheduled tasks, you can also spawn multiple cron.php and adhoc_task.php processes to get more throughput. By default Moodle will make sure than no more than 3 processes run at any time, you can tune these limits as needed in  Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the scheduled tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139453</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139453"/>
		<updated>2021-01-28T10:06:59Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron with multiple processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== High performance cron tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. But adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. You can run one or more dedicated adhoc task processors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 you can tell it to stay alive when the queue is empty waiting for new tasks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have a very high low number of adhoc tasks, or scheduled tasks, you can also spawn multiple cron.php and adhoc_task.php processes to get more throughput. By default Moodle will make sure than no more than 3 processes run at any time, you can tune these limits as needed in  Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the schedules tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process. Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139452</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139452"/>
		<updated>2021-01-28T10:05:56Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Scaling up cron and task runners */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== High performance cron tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. But adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. You can run one or more dedicated adhoc task processors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 you can tell it to stay alive when the queue is empty waiting for new tasks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have a very high low number of adhoc tasks, or scheduled tasks, you can also spawn multiple cron.php and adhoc_task.php processes to get more throughput. By default Moodle will make sure than no more than 3 processes run at any time, you can tune these limits as needed in  Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron with multiple processes ==&lt;br /&gt;
&lt;br /&gt;
As your site grows many of the schedules tasks will take longer to complete, and also there will be more adhoc tasks queued which need to be processed. The cron system is designed to work in parallel but each individual process can only process one task at a time so you must run multiple cron cli&#039;s. You can generally run a fairly high number of cron processes on a dedicated cron instance before needing to run multiple cron instances. To run more than one process simply spawn multiple cron processes each minute:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It can be especially important to increase the number of adhoc_task.php processes as certain plugins and systems can generate very large numbers of adhoc tasks, or tasks that can take a long time to process.Especially tasks like document conversions and automated backups can build up more quickly than they are processed if they are left on default settings.&lt;br /&gt;
&lt;br /&gt;
By default only 3 scheduled tasks and 3 adhoc tasks can be run concurrently so as you add more processes you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20; // Defaults to 3&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;  // Defaults to 3&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Whatever you set these too make sure the server(s) hosting them can comfortably handle this many processes. Often the bottleneck will be a shared service, usually the database.&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 cli processes, but in the task queue there are 20 adhoc tasks for an automated backup, each of which will take ten minutes to complete, then very quickly all 5 processes will be consumed by backups and nothing else. Other small very fast and light tasks like a document conversion or forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can limit the concurrency of specific types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their own limits then you should still have another few processes standing by on idle waiting for anything else which may be added to the queue.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
config.php:&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139451</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139451"/>
		<updated>2021-01-28T07:59:27Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== High performance cron tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. But adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. You can run one or more dedicated adhoc task processors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 you can tell it to stay alive when the queue is empty waiting for new tasks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have a very high low number of adhoc tasks, or scheduled tasks, you can also spawn multiple cron.php and adhoc_task.php processes to get more throughput. By default Moodle will make sure than no more than 3 processes run at any time, you can tune these limits as needed in  Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron and task runners ==&lt;br /&gt;
&lt;br /&gt;
As you scale up you will want to run more processes, especially to run through the queue of adhoc tasks. Especially tasks like document conversions and automated can build up more quickly than they are processed if they are left on default settings. As you add more runners you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20;&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 processes and each is running a backup which takes ten minutes, then small very fast and light tasks like a document conversion of forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can throttle certain types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their limits then you should still have another few runners standing by on idle waiting for anything else.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139450</id>
		<title>Cron with Unix or Linux</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Cron_with_Unix_or_Linux&amp;diff=139450"/>
		<updated>2021-01-28T07:58:50Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* High performance cron tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Installing Moodle}}&lt;br /&gt;
On Unix and Linux use the built in &#039;&#039;cron&#039;&#039; program which is standard on nearly all systems. You are required to add a command to the &#039;crontab&#039; (the table that holds cron commands) for the web server user. &lt;br /&gt;
&lt;br /&gt;
There are two different methods that can be used to invoke the Moodle cron process:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; The commands shown need to be added to the crontab to function (described in a moment). However, you can - and should - run them on the command line to check they work first. &lt;br /&gt;
&lt;br /&gt;
== Method 1: The command line (cli) cron ==&lt;br /&gt;
&lt;br /&gt;
If you have a choice, this is normally the best way to run Moodle cron. &lt;br /&gt;
&lt;br /&gt;
PHP is also capable of running programs directly from the command line. Your system needs to be set up to do this; specifically you need the &#039;CLI&#039; version of PHP to be installed. Most systems with PHP installed will have this by default. If you have the PHP CLI version installed then this is the recommended method of invoking cron. The correct command will be something like...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/php /path/to/moodle/admin/cli/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(substitute the correct path to moodle and for php as required)&lt;br /&gt;
&lt;br /&gt;
You can simply type this on the command line this to see if it works. If you are not sure about the path to PHP you can type &amp;quot;&amp;lt;code&amp;gt;which php&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tip:&#039;&#039;&#039;: If you have problems, see the [[PHP]] page. In particular, suspect an alternate php.ini for the CLI PHP command which may not have suitable settings.&lt;br /&gt;
&lt;br /&gt;
== Method 2: Web based cron ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE:&#039;&#039;&#039; In order to use the web based cron script you must first check [[Cron settings]] to make sure this method is permitted. &lt;br /&gt;
&lt;br /&gt;
The idea is to call the following web page (you can try this from your browser):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A command line (text based) browser is needed to run this on the server. Possibilities are as follows (OSX, for example, only ships with curl)...&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/wget -q -O /dev/null/ http://url.of.your/moodle/admin/cron.php&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-O /dev/null/&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
...OR...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/usr/bin/curl http://url.of.your/moodle/admin/cron.php -o /dev/null/ -silent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
(no output is displayed - remove the &#039;&#039;-o /dev/null/ -silent&#039;&#039; to test)&lt;br /&gt;
&lt;br /&gt;
==Using the crontab program on Unix/Linux==&lt;br /&gt;
&lt;br /&gt;
Once you have selected (and tested!) an appropriate command to invoke the Moodle cron it must be added to the web users &#039;crontab&#039; to schedule it to run regularly. &#039;Crontab&#039; is both a file containing the user&#039;s cron commands and is also the name of the (command line) program used to edit it. Use the following command (as root) substituting the correct user in place of &#039;www-data&#039; (e.g. &#039;apache&#039; for Centos, &#039;www-data&#039; for Debian/Ubuntu, &#039;_www&#039; for macOS—Google will know!)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# crontab -u www-data -e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will bring up an editor window (the first time it may ask you which editor to use). Add the command onto the end of the file in this way (it may be empty or it may have some instructional comments):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 */1 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first five entries specify the times, followed by the command, to run. This says to run the command every minute which is normally ok. On a hosted system you may get complaints if you do not run it a lot less often (e.g. to run every two hours use &#039;0 */2 * * *&#039; for the first five entries). If you want to use the wget/curl version, the first five entries remain the same - just change the command part.&lt;br /&gt;
&lt;br /&gt;
== High performance cron tasks ==&lt;br /&gt;
&lt;br /&gt;
Each time cron is run, after the scheduled tasks the adhoc tasks are also run. But adhoc tasks can be queued at any moment, and generally you want them processed as soon as possible and to not have to wait for the scheduled task to run first. You can run one or more dedicated adhoc task processors:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting from Moodle 3.9 you can tell it to stay alive when the queue is empty waiting for new tasks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * * * * * /usr/bin/php  /path/to/moodle/admin/cli/adhoc_task.php --execute --keep-alive=59 &amp;gt;/dev/null&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have a very high low number of adhoc tasks, or scheduled tasks, you can also spawn multiple cron.php and adhoc_task.php processes to get more throughput. By default Moodle will make sure than no more than 3 processes run at any time, you can tune these limits as needed in  Site administration &amp;gt; Server &amp;gt; Tasks &amp;gt; Task processing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scaling up cron and task runners ==&lt;br /&gt;
&lt;br /&gt;
As you scale up you will want to run more processes, especially to run through the queue of adhoc tasks. Especially tasks like document conversions and automated can build up more quickly than they are processed if they are left on default settings. As you add more runners you need to increase the level of allowed concurrency:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;task_scheduled_concurrency_limit = 20;&lt;br /&gt;
$CFG-&amp;gt;task_adhoc_concurrency_limit = 50;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find that certain types of very long running tasks will consume all the available task runners which means no other tasks will run. eg if you have 5 processes and each is running a backup which takes ten minutes, then small very fast and light tasks like a document conversion of forum emails will not get sent until the backups are complete and a runner frees up. To manage this you can throttle certain types of adhoc tasks. A good rule of thumb is that if all of the &#039;heavy&#039; tasks consume all of their limits then you should still have another few runners standing by on idle waiting for anything else.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;task_concurrency_limit = [&lt;br /&gt;
    &#039;core\task\course_backup_task&#039; =&amp;gt; 28,&lt;br /&gt;
    &#039;core_course\task\course_delete_modules&#039; =&amp;gt; 6,&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://linuxweblog.com/node/24 A basic crontab tutorial] &lt;br /&gt;
* [http://www.freebsd.org/cgi/man.cgi?query=crontab&amp;amp;apropos=0&amp;amp;sektion=5&amp;amp;manpath=FreeBSD+6.0-RELEASE+and+Ports&amp;amp;format=html Online version of the man page]&lt;br /&gt;
* [http://www.easycron.com/predictor Predicting Cron job&#039;s run time]&lt;br /&gt;
&lt;br /&gt;
[[es:Cron con Unix o Linux]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Site_security_settings&amp;diff=138953</id>
		<title>Site security settings</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Site_security_settings&amp;diff=138953"/>
		<updated>2020-11-12T23:59:07Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Open to Google */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;.&lt;br /&gt;
{{Security}}&lt;br /&gt;
===Protect usernames===&lt;br /&gt;
&lt;br /&gt;
If enabled, when a user attempts to reset their password and enters a username or email address, the following message is displayed: &amp;quot;If you supplied a correct username or email address then an email should have been sent to you.&amp;quot; This is to prevent a malicious party from using the interface to determine which usernames and email addresses are in use in valid accounts.&lt;br /&gt;
&lt;br /&gt;
If the protect usernames setting is disabled, when a user attempts to reset their password they are provided with feedback regarding whether an account exists with the username or email address supplied. For example, the message &amp;quot;The email address was not found in the database&amp;quot; may be displayed.&lt;br /&gt;
&lt;br /&gt;
===Force users to login===&lt;br /&gt;
&lt;br /&gt;
If you turn this setting on, all users must login before they even see the [[Front Page]] of the site. Note however that this does not prevent guest access to courses, if you have autologin guests enabled in [[User policies]].&lt;br /&gt;
&lt;br /&gt;
===Force users to login for profiles===&lt;br /&gt;
&lt;br /&gt;
Leave this set to Yes to keep anonymous visitors away from user profiles. &lt;br /&gt;
&lt;br /&gt;
===Force users to login to view user pictures===&lt;br /&gt;
&lt;br /&gt;
If enabled, users must login in order to view user profile pictures and the default user picture will be used in all notification emails.&lt;br /&gt;
&lt;br /&gt;
===Open to Google===&lt;br /&gt;
&lt;br /&gt;
Enabling this setting allows Google&#039;s search spiders guest access to your site. Any part of the site that allows guest access will then be searchable on Google. In addition, people coming in to your site via a Google search will automatically be logged in as a guest.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Referrer policy ===&lt;br /&gt;
&lt;br /&gt;
A referrer policy can be set, various parts of moodle rely on the referrer being set so it&#039;s generally best to only remove or reduce the referrer for external links. So a policy of origin-when-cross-origin is probably the best balance. &lt;br /&gt;
See the MDN docs for more details:&lt;br /&gt;
&lt;br /&gt;
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy&lt;br /&gt;
&lt;br /&gt;
==Allow indexing by search engines==&lt;br /&gt;
This determines whether to allow search engines to index your site. The default is Everywhere except login and signup pages.&lt;br /&gt;
&lt;br /&gt;
===Profile visible roles===&lt;br /&gt;
Any role which is checked/ticked here will be visible on  user profiles and the Participation screen.&lt;br /&gt;
&lt;br /&gt;
===Maximum uploaded file size===&lt;br /&gt;
&lt;br /&gt;
Probably the most frequently asked question in the Moodle.org Using Moodle forums is &amp;quot;How do I increase the upload file size limit?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Upload file sizes are restricted in a number of ways - each one in this list restricts the following ones:&lt;br /&gt;
&lt;br /&gt;
1. The Apache server setting LimitRequestBody ... default in Apache 2.x or greater is set to 0 or an unlimited upload size&lt;br /&gt;
&lt;br /&gt;
2. The PHP site settings post_max_size and upload_max_filesize in php.ini : &#039;&#039;&#039;modify php.ini in web server directories&#039;&#039;&#039; ( apache2.x.x/bin/php.ini ) not in php directories :&lt;br /&gt;
 &lt;br /&gt;
 post_max_size = 128M;  to increase limit to 128 Megabytes;&lt;br /&gt;
 upload_max_filesize = 128M;  to increase limit to 128 Megabytes;&lt;br /&gt;
 max_execution_time = 600 ; Maximum execution time of each script, in seconds;&lt;br /&gt;
&lt;br /&gt;
3. The Moodle site-wide maximum uploaded file size setting: &#039;&#039;Settings &amp;gt; Site administration &amp;gt; Security &amp;gt; Site policies &amp;gt; Maximum uploaded file size&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
4. The Moodle course maximum uploaded file size setting in the course default  settings: &#039;&#039;Settings &amp;gt; Site administration &amp;gt; Courses &amp;gt; Course default settings&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
5. The  file size settings in each individual course in &#039;&#039;Course Administration&amp;gt;Settings&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
5. Certain course activity module settings (for example, Assignment)&lt;br /&gt;
&lt;br /&gt;
* See [[File upload size]] for more details.&lt;br /&gt;
&lt;br /&gt;
===User quota===&lt;br /&gt;
&lt;br /&gt;
The maximum number of bytes that a user can store in their own [[Private files]] area.&lt;br /&gt;
&lt;br /&gt;
===Allow EMBED and OBJECT tags===&lt;br /&gt;
Allowing these presents a security risk but if you wish normal users such as students to be able to use them then check the box here.&lt;br /&gt;
&lt;br /&gt;
===Enable trusted content===&lt;br /&gt;
&lt;br /&gt;
By default Moodle will always thoroughly clean text that comes from users to remove any possible bad scripts, media etc that could be a security risk. The Trusted Content system is a way of giving particular users that you trust the ability to include these advanced features in their content without interference. To enable this system, you need to first enable this setting, and then grant the [[Capabilities/moodle/site:trustcontent|Trust submitted content]] capability to a specific Moodle role. Texts created or uploaded by such users will be marked as trusted and will not be cleaned before display.&lt;br /&gt;
&lt;br /&gt;
===Maximum time to edit posts===&lt;br /&gt;
&lt;br /&gt;
This sets the editing time for forum postings. The editing time is the amount of time users have to change forum postings before they are mailed to subscribers.&lt;br /&gt;
&lt;br /&gt;
Please refer to the forum discussions [http://moodle.org/mod/forum/discuss.php?d=28679 Editing a forum post after the 30 minutes deadline] and [http://moodle.org/mod/forum/discuss.php?d=5367 The philosophy underlying &amp;quot;no editing after 30 minutes&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
===Full name format===&lt;br /&gt;
&lt;br /&gt;
This setting has been moved in Moodle 2.6 onwards to &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Users &amp;gt; Permissions &amp;gt; [[Roles settings|User policies]]&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Allow extended characters in usernames===&lt;br /&gt;
&lt;br /&gt;
The default here, unchecked = unenabled, can only contain alphabetical letters in lowercase, numbers, hypen &#039;-&#039;, underscore &#039;_&#039;, period &#039;.&#039;, or at sign &#039;@&#039;. If you enable this, it will be possible to have any characters for the username, but they must still be lowercase. This setting would allow you for example to have usernames with accents such as ö or ê and so on.&lt;br /&gt;
&lt;br /&gt;
Note: In Moodle 3.4.2 onwards, the Site policy URL and Site policy URL for guests settings have been moved to &#039;Policy settings&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
===Keep tag name casing===&lt;br /&gt;
&lt;br /&gt;
If checked, then tags like the following will be displayed: SOCCER, gUiTaR, MacDonalds, music&lt;br /&gt;
&lt;br /&gt;
If unchecked, then all tags will be displayed as follows: Soccer, Guitar, Macdonalds, Music&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tips&#039;&#039;:&lt;br /&gt;
:* For English, off is useful.&lt;br /&gt;
:* For Japanese, no changes are made either way.&lt;br /&gt;
:* For languages where this kind of capitalization changes the meaning, it is best to keep this option on.&lt;br /&gt;
&lt;br /&gt;
===Profiles for enrolled users only===&lt;br /&gt;
&lt;br /&gt;
To prevent misuse by spammers, profile descriptions of users who are not yet enrolled in any course are hidden. New users must enrol in at least one course before they can add a profile description.&lt;br /&gt;
&lt;br /&gt;
===Cron execution via command line only===&lt;br /&gt;
&lt;br /&gt;
[[Cron]] is an action that runs various administrative jobs on your Moodle such as sending out forum posts. Running the cron from a web browser can expose privileged information to anonymous users. Thus it is recommended to only run the cron from the command line or set a cron password for remote access.&lt;br /&gt;
&lt;br /&gt;
===Cron password for remote access===&lt;br /&gt;
&lt;br /&gt;
Setting a password will mean that users can only run cron from the browser if they know the password and add it like this:&lt;br /&gt;
www.YOURMOODLE.com/admin/cron.php/?password=THEPASSWORDYOUSET.&lt;br /&gt;
&lt;br /&gt;
===Account lockout===&lt;br /&gt;
&lt;br /&gt;
Account lockout may be enabled. &lt;br /&gt;
&lt;br /&gt;
Account lockout threshold: After a specified number of failed login attempts, a user&#039;s account is locked and they are sent an email containing a URL to unlock the account. Setting this to &#039;No&#039; means there is no threshold and an account attempting to log in can do so an unlimited number of times.&lt;br /&gt;
&lt;br /&gt;
Account lockout observation window: Observation time for lockout threshold, if there are no failed attempts the threshold counter is reset after this time. This is the counter for how long to watch for more failed attempts by an account trying to log in even after being locked out, the counter will reset at each attempt and last this long.&lt;br /&gt;
&lt;br /&gt;
Account lockout duration: Locked out account is automatically unlocked after this duration.&lt;br /&gt;
&lt;br /&gt;
The account may also be unlocked by an administrator in &#039;&#039;Administration &amp;gt; Site administration &amp;gt; Users &amp;gt; Accounts &amp;gt; Browse list of users&#039;&#039; or by waiting for the account lockout duration to elapse.&lt;br /&gt;
&lt;br /&gt;
===Password policy===&lt;br /&gt;
&lt;br /&gt;
It is highly recommended that a password policy is set to force users to use stronger passwords that are less susceptible to being cracked by a intruder.&lt;br /&gt;
[[Image:Password policy.png|thumb|Password policy]]&lt;br /&gt;
&lt;br /&gt;
The password policy includes option to set the minimum length of the password, the minimum number of digits, the minimum number of lower-case characters, the minimum number of upper-case characters and the minimum number of non alphanumeric characters.&lt;br /&gt;
&lt;br /&gt;
The password policy is enabled by default. Default (recommended) settings are:&lt;br /&gt;
* Password length - 8&lt;br /&gt;
* Digits - 1&lt;br /&gt;
* Lowercase letters - 1&lt;br /&gt;
* Uppercase letters - 1&lt;br /&gt;
* Non-alphanumeric characters - 1&lt;br /&gt;
&lt;br /&gt;
If a user enters a password that does not meet the requirements, they are given an error message indicating the nature of the problem with the entered password.&lt;br /&gt;
&lt;br /&gt;
Enabling the password policy does not affect existing users until they decide to or are required to change their password. An admin can force all users to change their password using the force password change option in [[Bulk user actions]].&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;Tip&#039;&#039;: The password policy may also be applied to [[Enrolment key|enrolment keys]] by ticking the &#039;Use password policy&#039; checkbox in the [[Self enrolment]] settings.&lt;br /&gt;
&lt;br /&gt;
===Password rotation limit===&lt;br /&gt;
&lt;br /&gt;
Here you can specify how often a user must change their password before they can re-use a previous password. Note that this might not work with some external authentication plugins.&lt;br /&gt;
&lt;br /&gt;
===Log out after password change===&lt;br /&gt;
&lt;br /&gt;
By default, users can change their password and remain logged in. Enabling this setting will log them out of existing sessions except the one in which they specify their new password. This setting only applies to users manually changing their password, not to bulk password changes.&lt;br /&gt;
&lt;br /&gt;
===User created token duration===&lt;br /&gt;
&lt;br /&gt;
A new setting in Moodle 3.4 onwards enables the duration of a web services token created by a user (for example via the mobile app) to be set. (Previously the duration was 3 months and this value could not be changed.)&lt;br /&gt;
&lt;br /&gt;
===Group enrolment key policy===&lt;br /&gt;
If this is enabled then when a teacher sets a group enrolment key, they will have to set a key which follows the password policy set above. Note that the group enrolment key policy requires the password policy to be enabled.&lt;br /&gt;
&lt;br /&gt;
===Disable user profile images===&lt;br /&gt;
&lt;br /&gt;
Check/tick this box if you don&#039;t want your users to be able to change their [[User pictures|profile images]]. &lt;br /&gt;
&lt;br /&gt;
===Email change confirmation===&lt;br /&gt;
&lt;br /&gt;
A confirmation step is required for users to change their email address unless the &#039;&#039;emailchangeconfirmation&#039;&#039; box is unchecked.&lt;br /&gt;
&lt;br /&gt;
===Remember username===&lt;br /&gt;
If you want  usernames to be stored during login then set this to &amp;quot;yes&amp;quot;. This will store permanent cookies and in some countries may be considered a privacy issue if used without consent. From a UK point of view, see http://tracker.moodle.org/secure/attachment/24290/UK+Laws+Relating+to+Cookies-LUNS2011.pdf See also the Using Moodle forum discussion [http://moodle.org/mod/forum/discuss.php?d=201558 EU Cookie Law].&lt;br /&gt;
&lt;br /&gt;
===Strict validation of required fields===&lt;br /&gt;
If enabled, users are prevented from entering a space or line break only in required fields in forms. (note: add more info)&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Policies plugin]] - The Policies plugin provides a new user sign-on process, with ability to define multiple policies (site, privacy, third party), track user consents, and manage updates and versioning of the policies&lt;br /&gt;
&lt;br /&gt;
[[es:Políticas del sitio]]&lt;br /&gt;
[[eu:Gunearen_politikak]]&lt;br /&gt;
[[fr:Règles site]]&lt;br /&gt;
[[ja:サイトポリシー]]&lt;br /&gt;
[[de:Sicherheitsregeln der Website]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=138088</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=138088"/>
		<updated>2020-08-15T05:25:58Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Redis session driver */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_auth = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_retry = 100; // Optional, default is 100ms (from 3.9)&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
$CFG-&amp;gt;session_redis_serializer_use_igbinary = false; // Optional, default is PHP builtin serializer.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Be careful on changing the default serializer: it requires &amp;lt;code php&amp;gt;--enable-redis-igbinary&amp;lt;/code&amp;gt; at &#039;&#039;phpredis&#039;&#039; extension compile time &#039;&#039;&#039;and&#039;&#039;&#039; you need to remove &#039;&#039;&#039;the previous session data&#039;&#039;&#039; before using Moodle again.&lt;br /&gt;
&lt;br /&gt;
== Read only sessions ==&lt;br /&gt;
&lt;br /&gt;
There is an experimental feature in Moodle 3.9 allowing certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
&lt;br /&gt;
Details TBA&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Bulk_enrolments&amp;diff=137005</id>
		<title>Bulk enrolments</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Bulk_enrolments&amp;diff=137005"/>
		<updated>2020-05-14T03:57:15Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox plugin&lt;br /&gt;
|type = local plugin&lt;br /&gt;
|entry = https://moodle.org/plugins/local_mass_enroll&lt;br /&gt;
&lt;br /&gt;
maintainer = [[Rogier Van Dongen]]&lt;br /&gt;
|float = right&lt;br /&gt;
}}&lt;br /&gt;
Bulk enrolments allows you to enrol students and add them to groups in a Moodle course using an excel file containing the students&#039; email address or userid. &lt;br /&gt;
Before you start, you will require an excel file containing a complete list of the students&#039; email address or userids in the first column. Subsequent columns contain the names of any groups you want to add each student to. &lt;br /&gt;
&lt;br /&gt;
NOTE: Not to be confused with this plugin with almost the same name:&lt;br /&gt;
&lt;br /&gt;
https://moodle.org/plugins/local_bulkenrol&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Create your CSV&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In order to upload your students successfully, you will need to create a CSV file with the students details. CSVs are simple to create - one way is in a spreadsheet package, making sure to save it as a .csv file type.&lt;br /&gt;
At minimum, your CSV file should contain one column for the main student identifier, usually their  email address but it can also be their userid, or student ID number.&lt;br /&gt;
Ensure you have column labels - this is because Moodle anticipates these and so ignores the first row of CSV file. In other words, don&#039;t put any actual student data in your file&#039;s top row. If you are using email then put &#039;email&#039;, if you are using user IDs then put &#039;userid&#039;.&lt;br /&gt;
If you want to enrol the students into Groups, include a second column which gives the group name for each student. Be careful to type these exactly. Give it a column heading &#039;group&#039;.&lt;br /&gt;
You can add subsequent groups in subsequent columns.&lt;br /&gt;
&lt;br /&gt;
[[File:bulk_upload_csv.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Enrol the Students&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the &#039;&#039;&#039;Settings&#039;&#039;&#039; block on your course, under &#039;&#039;&#039;Course administration&#039;&#039;&#039;, click &#039;&#039;&#039;Users&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Bulk enrolments&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Select &#039;&#039;&#039;Choose a file&#039;&#039;&#039; and upload your CSV file.&lt;br /&gt;
Make sure &#039;&#039;&#039;Role&#039;&#039;&#039; to assign is left as &#039;&#039;&#039;student&#039;&#039;&#039;.&lt;br /&gt;
Set &#039;&#039;&#039;First column contains&#039;&#039;&#039; to reflect they type of data you have used in your spreadsheet, either the students&#039; email address, userid or ID number.&lt;br /&gt;
If you need to create groups, ensure &#039;&#039;&#039;Create group(s) if needed&#039;&#039;&#039; is set to Yes.&lt;br /&gt;
If you would like to create groupings in your course, based on the groups that the students will been placed into, ensure &#039;&#039;&#039;Create grouping(s) if needed&#039;&#039;&#039; is kept to yes.  If you do not want to create groupings, set this to No.&lt;br /&gt;
To receive an email report confirming which students have been enrolled and which groups they have been placed into, keep &#039;&#039;&#039;Send me a mail report&#039;&#039;&#039; set to &#039;&#039;&#039;Yes&#039;&#039;&#039;.&lt;br /&gt;
Click &#039;&#039;&#039;Enrol them to my course&#039;&#039;&#039;.&lt;br /&gt;
Check the students have been enrolled in their groups by going to the &#039;&#039;&#039;Settings&#039;&#039;&#039; menu and under &#039;&#039;&#039;Course Administration&#039;&#039;&#039; click on &#039;&#039;&#039;Users&#039;&#039;&#039; then &#039;&#039;&#039;Groups&#039;&#039;&#039;.&lt;br /&gt;
You should see the groups listed, followed by the number of students in each group in brackets.&lt;br /&gt;
You can also bulk unenrol students from your course by clicking on Bulk unenrolments in the block, and following the instructions above.&lt;br /&gt;
&lt;br /&gt;
[[File:bulk_upload.png]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=136584</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=136584"/>
		<updated>2020-02-02T06:52:52Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Read only sessions = */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Read only sessions ==&lt;br /&gt;
&lt;br /&gt;
There is an experimental feature in Moodle 3.9 allowing certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
&lt;br /&gt;
Details TBA&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=136583</id>
		<title>Session handling</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Session_handling&amp;diff=136583"/>
		<updated>2020-02-02T06:52:42Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: Add section on readonly sessions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
An administrator can change the following settings in &#039;Session Handling&#039; in the Site administration.&lt;br /&gt;
&lt;br /&gt;
Once someone logs in to your Moodle server, the server starts a session. The session data allows the server to track users as they access different pages.&lt;br /&gt;
&lt;br /&gt;
==Use database for session information==&lt;br /&gt;
&lt;br /&gt;
Moodle needs to store the session data in some storage. By default either file or database session storage is selected, this option allows admin to change it. Large installation should use memcached driver described below.&lt;br /&gt;
&lt;br /&gt;
Note that this option disappears after setting the $CFG-&amp;gt;session_handler_class in config.php file.&lt;br /&gt;
&lt;br /&gt;
==Timeout==&lt;br /&gt;
&lt;br /&gt;
If users don&#039;t load a new page during the amount of time set here, Moodle will end their session and log them out.&lt;br /&gt;
&lt;br /&gt;
Be sure this time frame is long enough to cover the longest test your teachers may offer. If a student is logged out while they are taking a test, their responses to the test questions may be lost.&lt;br /&gt;
&lt;br /&gt;
==Cookie prefix==&lt;br /&gt;
&lt;br /&gt;
Most of the time, you can leave this blank, unless you are running more than one Moodle site on the same server. In this case, you will want to customize the name of the cookie each Moodle site uses to track the session. This enables you to be logged into more than one Moodle site at the same time.&lt;br /&gt;
&lt;br /&gt;
Note: If you change &amp;quot;Cookie prefix&amp;quot; or &amp;quot;Cookie path&amp;quot; you will need to login again as the changes take effect immediately.&lt;br /&gt;
&lt;br /&gt;
==Cookie path==&lt;br /&gt;
&lt;br /&gt;
The relative path to this Moodle installation, this may be used to force sending of Moodle session cookie to parent directories. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Cookie domain==&lt;br /&gt;
&lt;br /&gt;
This can be used to send session cookies to higher domains instead of just the server domain. This may be useful for some SSO solutions. Invalid values are ignored automatically.&lt;br /&gt;
&lt;br /&gt;
==Session drivers==&lt;br /&gt;
User sessions may be stored in different backends. Session drivers can be configured only in config.php file - see examples in config-dist.php file.&lt;br /&gt;
&lt;br /&gt;
===Memcached session driver===&lt;br /&gt;
The Memcached session driver is the fastest driver. It requires external memcached server and memcached PHP extension. Server cluster nodes must use shared session storage.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\memcached&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_save_path = &#039;127.0.0.1:11211&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_prefix = &#039;memc.sess.key.&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_memcached_lock_expire = 7200;       // Ignored if memcached extension &amp;lt;= 2.1.0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Make sure the memcached server has enough memory.&lt;br /&gt;
* Use different prefix when storing sessions from multiple Moodle sites in one server.&lt;br /&gt;
* If PECL memcached extension version installed is less that 2.2.0, the locking works differently from other drivers - the lock is expired/released at the end of timeout - see MDL-42485.&lt;br /&gt;
* &#039;&#039;&#039;Don&#039;t use the same memcached server for both sessions and MUC. Events triggering MUC caches to be purged leads to MUC purging the memcached server - thus terminating ALL sessions.&#039;&#039;&#039;&lt;br /&gt;
* The &amp;lt;code php&amp;gt;$CFG-&amp;gt;session_memcached_number_of_replicas&amp;lt;/code&amp;gt; option is no longer supported.&lt;br /&gt;
&lt;br /&gt;
For windows users, PHP.net only supplies binaries for memcache, (and not memcached). (http://windows.php.net/downloads/pecl/releases/)&lt;br /&gt;
&lt;br /&gt;
(As of 2.7, two different contribs exist for memcache session handling - see MDL-42011 - it seems the OU one doesn&#039;t use prefix/lock_expire for some reason... possibly better to use the catalyst patch, where the only difference to the above config.php is the spelling of memcache(d).)&lt;br /&gt;
&lt;br /&gt;
===File session driver===&lt;br /&gt;
This driver is used by default in new installation.&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\file&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_file_save_path = $CFG-&amp;gt;dataroot.&#039;/sessions&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* File based sessions require file system that supports file locking.&lt;br /&gt;
&lt;br /&gt;
===Database session driver===&lt;br /&gt;
This type of driver was used by default in Moodle 2.0-2.5.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\database&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_database_acquire_lock_timeout = 120;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* DB sessions are not compatible with MyISAM database engine.&lt;br /&gt;
* If you are using MySQL/MariaDB make sure that \&#039;max_allowed_packet\&#039; in my.cnf (or my.ini) is at least 4M.&lt;br /&gt;
* The performance is relatively low, it is not recommended for large sites.&lt;br /&gt;
&lt;br /&gt;
===Redis session driver===&lt;br /&gt;
&lt;br /&gt;
The [[Redis]] session driver is available in Moodle 3.1.3 onwards (see MDL-54606). It requires a [[Redis_cache_store#Installing_Redis_server|Redis server]] and the [[Redis_cache_store#Installing_Redis_php_driver|Redis extension]].&lt;br /&gt;
&lt;br /&gt;
Configuration options in config.php:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;session_handler_class = &#039;\core\session\redis&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_host = &#039;127.0.0.1&#039;;&lt;br /&gt;
$CFG-&amp;gt;session_redis_port = 6379;  // Optional.&lt;br /&gt;
$CFG-&amp;gt;session_redis_database = 0;  // Optional, default is db 0.&lt;br /&gt;
$CFG-&amp;gt;session_redis_prefix = &#039;&#039;; // Optional, default is don&#039;t set one.&lt;br /&gt;
$CFG-&amp;gt;session_redis_acquire_lock_timeout = 120;&lt;br /&gt;
$CFG-&amp;gt;session_redis_lock_expire = 7200;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Read only sessions ===&lt;br /&gt;
&lt;br /&gt;
There is an experimental feature in Moodle 3.9 allowing certain pages to start readonly sessions which do not require a write lock with the aim of high performance at scale. &lt;br /&gt;
&lt;br /&gt;
https://tracker.moodle.org/browse/MDL-58018&lt;br /&gt;
&lt;br /&gt;
Details TBA&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Sessions FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[cs:admin/setting/sessionhandling]]&lt;br /&gt;
[[ja:セッションハンドリング]]&lt;br /&gt;
[[de:Sitzungsinformationen]]&lt;br /&gt;
[[es:Manejo de la sesión]]&lt;br /&gt;
[[fr:Gestion des sessions]]&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Custom_certificate_module&amp;diff=129634</id>
		<title>Custom certificate module</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Custom_certificate_module&amp;diff=129634"/>
		<updated>2017-12-11T05:42:14Z</updated>

		<summary type="html">&lt;p&gt;Brendanheywood: /* Helpful links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox plugin&lt;br /&gt;
|type = Activity&lt;br /&gt;
|entry = https://moodle.org/plugins/mod_customcert&lt;br /&gt;
|tracker = https://github.com/markn86/moodle-mod_customcert/issues&lt;br /&gt;
|discussion = https://moodle.org/mod/forum/view.php?id=7163&lt;br /&gt;
|maintainer = [[User:Mark Nelson|Mark Nelson]]&lt;br /&gt;
|float = right&lt;br /&gt;
}}&lt;br /&gt;
==Description==&lt;br /&gt;
The [https://moodle.org/plugins/mod_customcert custom certificate module] allows the generation of dynamic PDF certificates with complete customisation via the web browser. It is different from the [https://moodle.org/plugins/mod_certificate certificate module] which requires PHP and FTP access in order to customise its appearance.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
There are two installation methods that are available.&lt;br /&gt;
&lt;br /&gt;
Follow one of these, then log into your Moodle site as an administrator and visit the notifications page to complete the install.&lt;br /&gt;
===Git===&lt;br /&gt;
&lt;br /&gt;
This requires Git being installed. If you do not have Git installed, please visit the Git website.&lt;br /&gt;
&lt;br /&gt;
Once you have Git installed, simply visit your Moodle mod directory and clone the repository using the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;git clone https://github.com/markn86/moodle-mod_customcert.git customcert&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then checkout the branch corresponding to the version of Moodle you are using with the following command. Make sure to replace MOODLE_32_STABLE with the version of Moodle you are using.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;git checkout MOODLE_32_STABLE&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Use &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; to update this repository periodically to ensure you have the most recent updates.&lt;br /&gt;
===Download the Zip===&lt;br /&gt;
&lt;br /&gt;
Visit the Moodle plugins website and download the zip corresponding to the version of Moodle you are using. Extract the zip and place the &#039;customcert&#039; folder in the mod folder in your Moodle directory.&lt;br /&gt;
&lt;br /&gt;
==Site settings==&lt;br /&gt;
&lt;br /&gt;
To visit the site settings log in as a user with appropriate permissions and visit &#039;Site administration&#039; &amp;gt; &#039;Plugins&#039; &amp;gt; &#039;Custom certificate&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_site_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Show position X and Y===&lt;br /&gt;
&lt;br /&gt;
This will show the X and Y position when editing of an element, allowing the user to accurately specify the location.&lt;br /&gt;
&lt;br /&gt;
This isn&#039;t required if you plan on solely using the drag and drop interface for this purpose.&lt;br /&gt;
&lt;br /&gt;
===Manage templates===&lt;br /&gt;
&lt;br /&gt;
This link will take you to a new screen where you will be able to manage templates.&lt;br /&gt;
&lt;br /&gt;
===Upload image===&lt;br /&gt;
&lt;br /&gt;
This link will take you to a new screen where you will be able to upload images. Images uploaded using this method will be available throughout your site to all users who are able to create a custom certificate.&lt;br /&gt;
&lt;br /&gt;
==Managing templates==&lt;br /&gt;
Templates allow a person with the appropriate permissions to create a site-wide template that can then be used by users when adding a certificate to a course, saving them from re-creating the same certificate over and over again. To create a template log in as a user who has the appropriate permissions and visit &#039;Site administration&#039; &amp;gt; &#039;Plugins&#039; &amp;gt; &#039;Custom certificate&#039; and click on the link &#039;Manage templates&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_manage_templates.png]]&lt;br /&gt;
&lt;br /&gt;
Here you will see a list of templates that have already been created. You can choose to edit these templates, delete them or create a new one. We will be creating a new template - start by clicking on &#039;Create template&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_edit_page.png]]&lt;br /&gt;
&lt;br /&gt;
The name here is what will be displayed to the users when they are creating a certificate in a course and would like to choose a template to load. You can add elements to the template, customise them and rearrange their position. This process is discussed later when we talk about adding a custom certificate to a course and then customising it.&lt;br /&gt;
&lt;br /&gt;
==Adding a custom certificate to a course==&lt;br /&gt;
&lt;br /&gt;
The custom certificate plugin once installed can be added just like any other activity in Moodle. Visit a course, turn editing on and click to add an activity.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_add_activity_page.png]]&lt;br /&gt;
&lt;br /&gt;
===Certificate options===&lt;br /&gt;
&lt;br /&gt;
====Allow anyone to verify a certificate====&lt;br /&gt;
&lt;br /&gt;
Each certificate when issued is assigned a unique code. It is possible to have this code displayed on the certificate by adding it as an element. To validate a certificate a person (eg. employer) may want to enter the code displayed on the certificate to confirm that it is indeed authentic. To accomplish this a logged in user requires the capability &#039;mod/customcert:verifycertificate&#039;, however with this setting set to &#039;Yes&#039; any person with the verification link (including users not logged in) can do this.&lt;br /&gt;
&lt;br /&gt;
====Email students/teachers/others====&lt;br /&gt;
&lt;br /&gt;
These settings enable the emailing of a certificate when a user is able to view it. The certificate may be hidden due to [[https://docs.moodle.org/en/Restrict_access access restrictions]], such as requiring the completion of another activity. A [[https://docs.moodle.org/en/Scheduled_tasks scheduled task]] runs that processes all the certificates that have any of these settings enabled and collects all the users to email that have not been emailed yet and are able to view the certificate and emails them the PDF.&lt;br /&gt;
&lt;br /&gt;
====Required minutes in course====&lt;br /&gt;
&lt;br /&gt;
This is the number of minutes a user is required to be in a course before they are able to view a certificate. This uses the logs in Moodle and hence can not guarantee the result to be 100% accurate.&lt;br /&gt;
&lt;br /&gt;
====Set protection====&lt;br /&gt;
&lt;br /&gt;
This determines what protection we want to set on the PDF.&lt;br /&gt;
&lt;br /&gt;
===Editing a custom certificate===&lt;br /&gt;
&lt;br /&gt;
Once you have added a certificate to your course you can then choose to edit the appearance of it. To do this view the certificate to be taken to the following page.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_edit_menu.png]]&lt;br /&gt;
&lt;br /&gt;
Here you can click on the cog on the top right and select &#039;Edit custom certificate&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_edit_page_with_items.png]]&lt;br /&gt;
&lt;br /&gt;
On the edit page you can see a list of the elements that have already been added to the certificate. You can edit, delete and move these elements. The order of these elements determine when they are rendered on the PDF. So, if you were to add a background image you would want this rendered first.&lt;br /&gt;
&lt;br /&gt;
You can also choose to load a template on this page. If you also have the permissions to manage templates you will also be shown the link to the manage templates page.&lt;br /&gt;
&lt;br /&gt;
===Adding/editing an element===&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_element_list.png]]&lt;br /&gt;
&lt;br /&gt;
The above is the list of items that come with this plugin. These are [[https://docs.moodle.org/dev/Subplugins sub-plugins]] and are fully customisable allowing the community to generate plugins and share them without having to hack the plugin code.&lt;br /&gt;
&lt;br /&gt;
When editing a custom certificate you can choose to add an element which will take you to the page to edit them.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_edit_element.png]]&lt;br /&gt;
&lt;br /&gt;
Each element defines what characteristics you can edit. In the above example we are editing the &#039;Student name&#039; element. The site setting &#039;Show position X and Y&#039; has been enabled which is why &#039;Position X&#039; and &#039;Position Y&#039; are shown.&lt;br /&gt;
&lt;br /&gt;
===Repositioning elements===&lt;br /&gt;
&lt;br /&gt;
When editing a custom certificate under the list of elements there is a link &#039;Reposition elements&#039; that will take you to a page where you can drag and drop the elements. While on this page you can also click on the elements to bring up a dialogue that will allow you to edit its properties without having to go back to the edit custom certificate page.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_reposition_elements.png]]&lt;br /&gt;
&lt;br /&gt;
==Viewing issued certificates==&lt;br /&gt;
&lt;br /&gt;
To view issued certificates a user with the appropriate permissions can simply click on the certificate and click on the link &#039;View X issued custom certificates&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_view_issued_certificates.png]]&lt;br /&gt;
&lt;br /&gt;
Once you click on the link you can view the users who have been issued this certificate and also download their version of the certificate.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_view_issued_certificates_list.png]]&lt;br /&gt;
&lt;br /&gt;
==Verifying certificates==&lt;br /&gt;
&lt;br /&gt;
Each certificate when issued is assigned a unique code. To validate a certificate a person (eg. employer) may want to enter the code displayed on the certificate to confirm that it is indeed authentic. With the setting &#039;Allow anyone to verify a certificate&#039; enabled any person with the verification link (including users not logged in) can verify a certificate, however if it is not set, a user with the appropriate permissions (&#039;mod/customcert:verifycertificate&#039;) can do this by clicking on the certificate to gain access to the link.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_edit_menu.png]]&lt;br /&gt;
&lt;br /&gt;
Here you can click on the cog on the top right and select &#039;Verify certificate&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_verify_certificate_page.png]]&lt;br /&gt;
&lt;br /&gt;
Here you can enter the code to verify its authenticity.&lt;br /&gt;
&lt;br /&gt;
==My certificates==&lt;br /&gt;
&lt;br /&gt;
It is possible that a user may be in several courses each with their own custom certificate activity. It would be time consuming for the user to visit every course to review their certificate. In order to avoid this there is a page where the user can view all the certificates they have received.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_profile_page.png]]&lt;br /&gt;
&lt;br /&gt;
On the user&#039;s profile page under &#039;Miscellaneous&#039; the user can click on &#039;My certificates&#039; which will take them to a page listing all their certificates with the option of downloading them.&lt;br /&gt;
&lt;br /&gt;
[[File:Custom_certificate_my_certificates_page.png]]&lt;br /&gt;
&lt;br /&gt;
==Helpful links==&lt;br /&gt;
See  [https://moodle.org/plugins/mod_customcert the plugin page], the [https://github.com/markn86/moodle-mod_customcert/issues tracker page] and the [https://moodle.org/mod/forum/view.php?id=7163 Moodle forum].&lt;br /&gt;
&lt;br /&gt;
[[Add_fonts_for_embedding]] - see this page for details of adding more fonts for use in TCPDF&lt;br /&gt;
&lt;br /&gt;
==Did you find this plugin useful?==&lt;br /&gt;
Click on the &#039;Add to my favourites&#039; link in [https://moodle.org/plugins/mod_customcert the plugin page].&lt;/div&gt;</summary>
		<author><name>Brendanheywood</name></author>
	</entry>
</feed>