Skip to content

Setting up moodle with LDAP authentication

Peter Willendrup edited this page Jun 27, 2016 · 15 revisions

Install dependencies for moodle:

$ apt-get install php5-gd php5-xmlrpc php5-intl
$ apt-get install mysql-client mysql-server php5-mysql php5-curl php5-ldap

Create a folder for moodledata - that needs to reside outside the webserver root, e.g. in /srv/moodledata. Should be owned by www-data:www-data.

$ chown www-data:www-data /srv/moodledata

Now enter your webroot and download the latest moolde from moodle.org, e.g.

$ wget https://download.moodle.org/download.php/direct/stable29/moodle-2.9.3.tgz

And unpack it:

$ tar -xzf moodle-2.9.3.tgz

Enable moodle in nginx using e.g. NOTE: probably better to remove all these suggested edits to the nginx conf and just use the 'monolithic' nginx server file from the repo...

	rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;
	location /moodle {
		alias /srv/mcweb/moodle;
	}

This is required to enable php5:

$ apt-get install php5-cli php5-fpm 
	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		try_files $uri $uri/ = 404;
	#	# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	#	# With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}

Also, your index line in the server block needs to contain "index.php":

	index index.html index.htm index.php;

Furthermore, the file fastcgi_params located in '/etc/nginx' must be extended a little bit:

fastcgi_param	PATH_INFO		$fastcgi_path_info;
fastcgi_param	PATH_TRANSLATED		$document_root$fastcgi_path_info;

fastcgi_param	QUERY_STRING		$query_string;
fastcgi_param	REQUEST_METHOD		$request_method;
fastcgi_param	CONTENT_TYPE		$content_type;
fastcgi_param	CONTENT_LENGTH		$content_length;

fastcgi_param	SCRIPT_FILENAME		$document_root$fastcgi_script_name;
fastcgi_param	SCRIPT_NAME		$fastcgi_script_name;
fastcgi_param	REQUEST_URI		$request_uri;
fastcgi_param	DOCUMENT_URI		$document_uri;
fastcgi_param	DOCUMENT_ROOT		$document_root;
fastcgi_param	SERVER_PROTOCOL		$server_protocol;

fastcgi_param	GATEWAY_INTERFACE	CGI/1.1;
fastcgi_param	SERVER_SOFTWARE		nginx/$nginx_version;

fastcgi_param	REMOTE_ADDR		$remote_addr;
fastcgi_param	REMOTE_PORT		$remote_port;
fastcgi_param	SERVER_ADDR		$server_addr;
fastcgi_param	SERVER_PORT		$server_port;
fastcgi_param	SERVER_NAME		$server_name;

fastcgi_param	HTTPS			$https;

Restart nginx.

Point your browser to e.g. mcstas-01.risoe.dk/moodle to perform the installation. Perform suggested adjustments to e.g. Opcache.

Configure Moodle for LDAP support:

Enable LDAP through Plugins -> Authentication -> Manage athentication

(Click on the "eye" next to LDAP server.)

Plugins -> Authentication -> LDAP server ->

- bind settings: don't cache passwords: yes
- user lookup settings: 
    - Contexts: ou=users,dc=fysik,dc=dtu,dc=dk (e.g.)
    - User attribute: uid
- data mapping:
    - First name: cn
    - Surname: sn
    - Email address: mail

Configure Moodle to use the "self service password" for password resets etc.

In Plugins -> Authentication -> Manage Authentication -> Common Settings (below in page) - insert e.g. https://www.e-neutrons.org/?page_id=268 as the value in Forgotten password URL

Clone this wiki locally