cPanel Shared Hosting Installation

From MoodleDocs

Overview

Shared hosting is a good choice for providing internet access for a small number of students on a self managed Moodle site at a moderate cost. Using cPanel is a relatively easy way to install Moodle but you may soon run into performance problems and restrictions on student numbers.

This method sets up moodle as a sub-folder in your domain ie www.example.com/moodle. This allows other applications to be run on the same domain,

Shared Hosting Requirements

  • A hosting and domain package with a SSL Certificate. (Check by going to https://example.com (Change example.com to your own site name) You should see a landing page.
  • To follow this guide, these cPanel Tools ( PHP Selector, phpMyAdmin, Database Wizard or Manage Databases, Terminal and File Manager) must be available.

Note on cPanel, there is a search box to allow you to find tools.

  • Go to PHP Selector. Moodle 5.1 requires php 8.2 or higher
  • Go to phpMyAdmin and find Database type and version. Moodle 5.1 requires a minimum of MySql 8.4, MariaDB 10.11.0, or PostgreSQL 13.

If your hosting service does not meet these requirements, this installation will fail

You can:.

  • Ask your provider for an upgrade
  • Find another provider

What you need to know before starting a Moodle installation

  • The type of database you have (Moodle will ask this during installation)
  • The name of your home directory (look on top of the tree at the left of cPanel File Manager). On most shared hosting, it is /home/username)
  • The location of the web root. This is where your html files are placed and usually it is called public_html

Set up PHP for Moodle

  1. Log in to cPanel and click on PHP Selector.
  2. Choose PHP 8.3 from the available versions. (Version 8.2 also meets Moodle requirement.'
  3. Enable required PHP extensions by checking these at minimum: `sodium`, `curl`, `openssl`, `mbstring`, `xml`, `intl`, `json`, and `fileinfo`.
  4. Adjust PHP settings in the Options tab:
    1. Set memory_limit to at least 128M. -
    2. Ensure max_input_vars is 5000 or higher.
    3. Confirm file_uploads is On.
    4. Save or apply the changes.

Database settings

Go to the cPanel phpMyAdmin tool to find your database type.

  • It may be mariadab, mysql, or postgresql. The web based install will ask this later.

On the cPanel phpMyAdmin, set your character set and collation.

  1. Character set: Use utf8mb4 (full UTF-8 support) to handle all Unicode characters.
  2. Collation: Use utf8mb4_unicode_ci for case-insensitive, language-aware sorting

Use cPanel Terminal

Go to Terminal in cPanel and paste these commands one after another, pushing enter after each line.

git clone -b v5.1.0 https://github.com/moodle/moodle ~moodle
mkdir ~/moodledata
chmod 755 ~/moodledata ~/moodle 
ln -s ~/moodle/public ~/public_html/moodle

These commands will

  • Obtain moodle and place it in your home directory
  • Create a moodledata folder to hold files uploaded to moodle
  • Set permissions for the folderexa
  • Create a link so your moodle will open in example.com/moodle

Web based Moodle Installation

Go to https://example.com/moodle and follow the instructions.

  1. First screen - Choose your language.
  2. Second screen - Confirm paths
    1. Web Address: https://example.com/moodle (Replace example.com with your actual domain name)
    2. Moodle Directory: /home/cpanelname/public_html/moodle (Replace cpanelname with your actual cPanelname, find it on File Manager if you are not sure)
    3. Data Directory : /home/cpanelname/moodledata
  3. Third screen - Choose database driver (a choice of MySql, MariaDB or PostgreSQL). Check phpAdmin if you have forgotten.
  4. Fourth screen -Database settings
    1. Database settings: localhost
    2. Database name
      1. Now we have to set up the database in cPanel Database Wizard.
      2. cPanel Database Wizard Step 1: Create A Database - call your new database moodle in the Database Wizard.
      3. Copy the database name ( including the cpanel prefix) from cPanel to your web based installations screen)
    3. Database user
      1. cPanel Database Wizard - next to create a user called moodleuser
      2. Copy the user name ( including the cpanel prefix) from cPanel to your web based installations screen)
    4. Database password
      1. Copy the password from cPanel to your web based installations screen)
    5. cPanel Database Wizard Step 3: Add user to the database
      1. Important - check All Privileges to allow your new user access to the database
  5. Continue to the Check page - if there are any php problems, resolve them in PHP Selector.
    1. If all green, continue with the installation.

Set up the Schedule Using a Cron job

  1. Go to Cron Jobs under Advanced in cPanel
  2. Open Add New Cron Job'
  3. Under cron settings, set as frequently as possible (On many shared cPanel hosts, the minimum allowed cron frequency is every 5 minutes, every minute is not permitted under many hosting plans)
  4. Paste in this coomand /usr/local/bin/php ~/moodle/admin/cli/cron.php