Installing Moodle on Debian based distributions: Difference between revisions

From MoodleDocs
(Added a couple of required php extensions and settings.)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Installing Moodle as a Debian package==
==Installing Moodle as a Debian package==


Moodle used to be included as a Debian package.  However, it has not been included in recent releasesThere is talk of it being included again in the Jesse release but now, follow the instructions below to install Moodle on Debian.
Moodle used to be included as a Debian package.  It is not recommended to install using any kind of installer with MoodleIn the long run you will be much better to install manually (or using git) so that the code is original without any alteration.


==Installing moodle from .tgz(.tar.gz) or .zip file==
==Installing moodle from .tgz(.tar.gz) or .zip file==
Line 16: Line 16:
Setting up a LAMP in Debian is very easy. Once you get used to Debian administration including installation and configuration are much simpler compared to other linux distros. The following describes how to install apache, php and mysql on the Debian distribution.  
Setting up a LAMP in Debian is very easy. Once you get used to Debian administration including installation and configuration are much simpler compared to other linux distros. The following describes how to install apache, php and mysql on the Debian distribution.  


For installation of the necessary packages the easiest option to use apt-get through the command line interface.  Debian has easy access to a Root Terminal
For installation of the necessary packages the easiest option to use apt-get through the command line interface.  Debian has easy access to a Root Terminal.  Either run all commands as SUDO or switch to root user by using su command.


Use the following command to install apache2, php5 and mysql (Note: Debian is now shipping with MariaDB as default database server - see here to install Community Edition of MySQL instead: https://linuxconfig.org/how-to-install-mysql-community-server-on-debian-9-stretch-linux)
Use the following command to install apache2, php5 and mysql (Note: Debian is now shipping with MariaDB as default database server - this database is just fine to use with Moodle.)


apt-get install apache2 php7.1 mysql-server php7.1-mysql libapache2-mod-php7.1 php7.1-gd php7.1-curl php7.1-xmlrpc php7.1-intl php7.1-zip php7.1-mbstring  
Debian 11 comes with PHP 7.4 which is not compatible with latest Moodle version so you need to add the Sury repository so that you can install a compatible php version.<syntaxhighlight lang="linux-config">
apt-get -y install lsb-release ca-certificates curl
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
dpkg -i /tmp/debsuryorg-archive-keyring.deb
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
 
</syntaxhighlight>Debian 11 comes with Mariadb 10.5 which is not compatible with latest Moodle version so you need to add the Mariadb repository.<syntaxhighlight lang="linux-config">
apt install wget
 
wget https://r.mariadb.com/downloads/mariadb_repo_setup
 
echo "30d2a05509d1c129dd7dd8430507e6a7729a4854ea10c9dcf6be88964f3fdc25 mariadb_repo_setup" \
    | sha256sum -c -
 
chmod +x mariadb_repo_setup
 
./mariadb_repo_setup \
  --mariadb-server-version="mariadb-10.6"
 
</syntaxhighlight>Update Repositories:
<code>apt-get update</code>
 
Install LAMP:
<code>apt-get install apache2 php8.2 mariadb-server php8.2-mysql libapache2-mod-php8.2 php8.2-gd php8.2-curl php8.2-xmlrpc php8-2.xml php8-2.soap php8.2-intl php8.2-zip php8.2-mbstring </code>


The mentioned packages are installed along with the dependencies depending on what was already installed on your Debian system.
The mentioned packages are installed along with the dependencies depending on what was already installed on your Debian system.
Line 34: Line 57:
Now we must make a few changes in the php7.1 configuration file. Open it using
Now we must make a few changes in the php7.1 configuration file. Open it using


  gedit /etc/php/7.1/apache2/php.ini
  gedit /etc/php/8.2/apache2/php.ini
or
or
<pre>nano /etc/php/7.1/apache2/php.ini</pre>
<pre>nano /etc/php/8.2/apache2/php.ini</pre>


add the entries  
if they are not already entered, add the entries  
  extension=mysql.so  
  extension=mysql.so  
  extension=gd.so
  extension=gd.so
Line 44: Line 67:
Sometimes these entries are provided as example lines being commented out . You can remove the commenting to activate the entries.
Sometimes these entries are provided as example lines being commented out . You can remove the commenting to activate the entries.
Then make the following changes (adjust to your preference)
Then make the following changes (adjust to your preference)
This will allocated more memory and allow files to be uploaded up to 80MB.  This should be enough for most multi-media files.  Hard drive space is cheap and the default is only 2MB.  It is recommended that you change the settings to the following values:
This will allocated more memory and allow files to be uploaded up to 80MB.  This should be enough for most multi-media files.  Hard drive space is cheap and the default is only 2MB.  It is recommended that you change the settings to the following values or as high as you want:


  memory_limit = 40M
  memory_limit = 40M
  post_max_size = 80M
  post_max_size = 80M
  upload_max_filesize = 80M
  upload_max_filesize = 80M  
The setting below needs to be set to at least 5000 to allow install to complete.
max_input_vars=25000


To test the php installation, you can create a text file named phpinfo.php with the contents <?phpinfo()?>
To test the php installation, you can create a text file named phpinfo.php with the contents <?phpinfo()?>
Line 73: Line 98:


Create the Moodle database
Create the Moodle database
  mysql> CREATE DATABASE moodle;
  mysql> CREATE DATABASE moodle CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 
(this should set the database up correctly to work with Moodle)
Then ensure that the database is set to UTF8 which is required by later distributions of Moodle
<pre>mysql> ALTER DATABASE moodle charset=utf8;</pre>


Then exit the database
Then exit the database
Line 85: Line 108:


===Step 3: Download moodle===
===Step 3: Download moodle===
I HIGHLY recommend looking at the Git Installation documents and using git to download Moodle.  It will make your life so much easier going forward!  However, if you do not want to make your life easier and like to do things the hard way, follow the next instructions!!
Download moodle from http://download.moodle.org/?lang=en.
Download moodle from http://download.moodle.org/?lang=en.


Line 95: Line 120:


You can also copy instead of moving it in case you want a backup of the code on your machine.
You can also copy instead of moving it in case you want a backup of the code on your machine.
<pre>cp -R moodle /var/www</pre>
<pre>cp -R moodle /var/www</pre>Change permissions and change ownership to the apache user.<pre>chmod -R 755 moodle</pre>You will probably need to do this as root (no problem if you are using the Root Terminal!)
 
You will probably need to do this as root (no problem if you are using the Root Terminal!)


===Step 5: Create a data directory and set Moodle directory permissions===
===Step 5: Create a data directory and set Moodle directory permissions===
Switch to the correct directory
Switch to the correct directory (it is not recommended to put the moodledata in the www folder so move up a folder and create the directory in the var folder or any other folder of your choosing.)
<pre>cd /var/www</pre>
<pre>cd /var/</pre>


Create a directory for user and course files  
Create a directory for user and course files  
Line 110: Line 133:
  chown -R www-data:www-data moodle
  chown -R www-data:www-data moodle
  chown -R www-data:www-data moodledata
  chown -R www-data:www-data moodledata
<br><pre>chmod -R 755 moodle</pre><br>
<pre>chmod -R 755 moodledata</pre>
<pre>chmod -R 755 moodledata</pre>


On a production server, you may want to tighten up privileges.
On a production server, you may want to tighten up privileges.


===Step 6: Change Apache to use Moodle as the web site===
=== Step 6: Change Apache to use Moodle as the web site===


Note that the server comes with Apache running and looking at the /var/www directory.  But there is nothing in that folder, so one just gets a redirect.  Edit as follows to have it point at Moodle instead:
Note that the server comes with Apache running and looking at the /var/www directory.  But there is nothing in that folder, so one just gets a redirect.  Edit as follows to have it point at Moodle instead:
Line 123: Line 145:
  <pre>nano /etc/apache2/sites-available/default</pre>
  <pre>nano /etc/apache2/sites-available/default</pre>


On about line 4, change DocumentRoot "/var/www" to
On about line 4, change DocumentRoot "/var/www/html" to


  DocumentRoot "/var/www/moodle"
  DocumentRoot "/var/www/moodle"


On about line 10, change <Directory "/var/www/"> to
On about line 10, change <Directory "/var/www/html/"> to


  <Directory "/var/www/moodle/">
  <Directory "/var/www/moodle/">
Line 138: Line 160:


  /etc/init.d/apache2 restart
  /etc/init.d/apache2 restart
*
'''At some point, you will need to set up SSL for the site.  These instructions are simply to get you up and running.''' 


===Step 7: Finally install===
===Step 7: Finally install===
* Go to http://localhost/moodle and follow the instructions.
*Go to http://localhost/moodle and follow the instructions.




Line 159: Line 181:
* For the database user, enter root
* For the database user, enter root


* For Password, enter the password for the database that you created earlier
*For Password, enter the password for the database that you created earlier


Continue through the dialogs until installed.  
Continue through the dialogs until installed.  


===Install cron===
=== Install cron ===


Moodle needs a periodic call to do maintenance work like sending out emails, cleaning up the database, updating feeds, etc.  To run the cron every 10 minutes, do the following
Moodle needs a periodic call to do maintenance work like sending out emails, cleaning up the database, updating feeds, etc.  To run the cron every 2 minutes, do the following


<pre>crontab -u www-data -e</pre>
<pre>crontab -u www-data -e</pre>


Add this line and save.
Add this line and save.
<pre>*/10 * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php  >/dev/null</pre>
<pre>*/2 * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php  >/dev/null</pre>




Use CNTL-X to save
Use CNTL-X to save


 
[[Category:Administrator]]
 
 
 
[[Category: Administrator]]
[[Category:Installation]]
[[Category:Installation]]



Latest revision as of 21:36, 22 May 2024

Installing Moodle as a Debian package

Moodle used to be included as a Debian package. It is not recommended to install using any kind of installer with Moodle. In the long run you will be much better to install manually (or using git) so that the code is original without any alteration.

Installing moodle from .tgz(.tar.gz) or .zip file

Step 1: Install required packages

After installing your Debian distro, install these packages (if you've not already done so). See Installing Apache, MySQL and PHP or refer to the respective user manuals. Using apt-get, aptitude or synaptic you can install these very easily.

  • Web Server (Apache highly recommended)
  • Database Server (MySQL or PostgreSQL recommended)
  • PHP, PHP-MySQL mod (or mod for your database)
  • Various PHP modules necessary for Moodle

LAMP in Debian

Setting up a LAMP in Debian is very easy. Once you get used to Debian administration including installation and configuration are much simpler compared to other linux distros. The following describes how to install apache, php and mysql on the Debian distribution.

For installation of the necessary packages the easiest option to use apt-get through the command line interface. Debian has easy access to a Root Terminal. Either run all commands as SUDO or switch to root user by using su command.

Use the following command to install apache2, php5 and mysql (Note: Debian is now shipping with MariaDB as default database server - this database is just fine to use with Moodle.)

Debian 11 comes with PHP 7.4 which is not compatible with latest Moodle version so you need to add the Sury repository so that you can install a compatible php version.

apt-get -y install lsb-release ca-certificates curl
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
dpkg -i /tmp/debsuryorg-archive-keyring.deb
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Debian 11 comes with Mariadb 10.5 which is not compatible with latest Moodle version so you need to add the Mariadb repository.

apt install wget

wget https://r.mariadb.com/downloads/mariadb_repo_setup

echo "30d2a05509d1c129dd7dd8430507e6a7729a4854ea10c9dcf6be88964f3fdc25 mariadb_repo_setup" \
    | sha256sum -c -

chmod +x mariadb_repo_setup

./mariadb_repo_setup \
   --mariadb-server-version="mariadb-10.6"

Update Repositories:

apt-get update

Install LAMP: apt-get install apache2 php8.2 mariadb-server php8.2-mysql libapache2-mod-php8.2 php8.2-gd php8.2-curl php8.2-xmlrpc php8-2.xml php8-2.soap php8.2-intl php8.2-zip php8.2-mbstring

The mentioned packages are installed along with the dependencies depending on what was already installed on your Debian system.

Now you may fire up a browser and type localhost to check whether the apache2 default page is shown,

If you are familiar with apache settings, you can edit the apache configuration files using the text editor gedit or nano by typing:

gedit /etc/apache2/apache2.conf

or

nano /etc/apache2/apache2.conf

However, for a basic install, you should not need to mess with this file.

Now we must make a few changes in the php7.1 configuration file. Open it using

gedit /etc/php/8.2/apache2/php.ini

or

nano /etc/php/8.2/apache2/php.ini

if they are not already entered, add the entries

extension=mysql.so 
extension=gd.so

Sometimes these entries are provided as example lines being commented out . You can remove the commenting to activate the entries. Then make the following changes (adjust to your preference) This will allocated more memory and allow files to be uploaded up to 80MB. This should be enough for most multi-media files. Hard drive space is cheap and the default is only 2MB. It is recommended that you change the settings to the following values or as high as you want:

memory_limit = 40M
post_max_size = 80M
upload_max_filesize = 80M 

The setting below needs to be set to at least 5000 to allow install to complete.

max_input_vars=25000

To test the php installation, you can create a text file named phpinfo.php with the contents <?phpinfo()?> and save it at /var/www. Restart apache with the command below. Now access this file through the browser localhost/phpinfo to check the installation of php.

You can restart apache 2 by

/etc/init.d/apache2 restart

or service apache2 restart

Step 2: Setup MySQL Database

Set a secure root password for the database (you might have already done this in the initial install process)

mysqladmin -u root password "mySecurePassword"

Note that on a secure production server, you will want to create a different user than root to access the database.

Now log in

mysql -u root -p

Enter your password

Create the Moodle database

mysql> CREATE DATABASE moodle CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

(this should set the database up correctly to work with Moodle)

Then exit the database

mysql> exit;

You can restart mysql by

/etc/init.d/mysql restart

Step 3: Download moodle

I HIGHLY recommend looking at the Git Installation documents and using git to download Moodle. It will make your life so much easier going forward! However, if you do not want to make your life easier and like to do things the hard way, follow the next instructions!!

Download moodle from http://download.moodle.org/?lang=en.

Step 4: Unpack file

  • For zip file, use unzip <your_file>. For tgz(tar.gz), use tar -zxvf <your-file>. You can also use any of the GUI front-ends such as file-roller or ark or just let Debian unzip it with Archive Manager. You will get a folder moodle (or moodle-2.8.1 or something similar). It will probably be located in your Downloads folder unless you told the Archive Manager or the Download utility to save it somewhere else. We will presume it is in your Download folder.

From terminal type

cd /home/YourUSERNAME/Downloads
mv moodle /var/www

You can also copy instead of moving it in case you want a backup of the code on your machine.

cp -R moodle /var/www

Change permissions and change ownership to the apache user.

chmod -R 755 moodle

You will probably need to do this as root (no problem if you are using the Root Terminal!)

Step 5: Create a data directory and set Moodle directory permissions

Switch to the correct directory (it is not recommended to put the moodledata in the www folder so move up a folder and create the directory in the var folder or any other folder of your choosing.)

cd /var/

Create a directory for user and course files

mkdir moodledata

Set ownership and permissions so that Apache can access the files

chown -R www-data:www-data moodle
chown -R www-data:www-data moodledata
chmod -R 755 moodledata

On a production server, you may want to tighten up privileges.

Step 6: Change Apache to use Moodle as the web site

Note that the server comes with Apache running and looking at the /var/www directory. But there is nothing in that folder, so one just gets a redirect. Edit as follows to have it point at Moodle instead:

gedit /etc/apache2/sites-available/default or

nano /etc/apache2/sites-available/default

On about line 4, change DocumentRoot "/var/www/html" to

DocumentRoot "/var/www/moodle"

On about line 10, change <Directory "/var/www/html/"> to

<Directory "/var/www/moodle/">

Around line 17, comment out the line for the default page:

# RedirectMatch ^/$ /apache2-default/

You can change other values like ServerAdmin if appropriate. For all changes, you should restart Apache for the new settings to take effect.

/etc/init.d/apache2 restart

At some point, you will need to set up SSL for the site. These instructions are simply to get you up and running.

Step 7: Finally install


Step 8: Setup Moodle

If you are only going to test Moodle on your internal network, just enter the local IP address as the web address. You can find the local IP address under DHCP by typing

ifconfig eth0


If you have a web address that points to your server, use that instead.

From a browser on another machine, enter

http:// ----- your web address -----
  • For the database user, enter root
  • For Password, enter the password for the database that you created earlier

Continue through the dialogs until installed.

Install cron

Moodle needs a periodic call to do maintenance work like sending out emails, cleaning up the database, updating feeds, etc. To run the cron every 2 minutes, do the following

crontab -u www-data -e

Add this line and save.

*/2 * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php  >/dev/null


Use CNTL-X to save