cPanel Shared Hosting Installation
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,
- 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
- Log in to cPanel and click on PHP Selector.
- Choose PHP 8.3 from the available versions. (Version 8.2 also meets Moodle requirement.'
- Enable required PHP extensions by checking these at minimum: `sodium`, `curl`, `openssl`, `mbstring`, `xml`, `intl`, `json`, and `fileinfo`.
- Adjust PHP settings in the Options tab:
- Set memory_limit to at least 128M. -
- Ensure max_input_vars is 5000 or higher.
- Confirm file_uploads is On.
- 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.
- Character set: Use utf8mb4 (full UTF-8 support) to handle all Unicode characters.
- 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.
- First screen - Choose your language.
- Second screen - Confirm paths
- Web Address: https://example.com/moodle (Replace example.com with your actual domain name)
- Moodle Directory: /home/cpanelname/public_html/moodle (Replace cpanelname with your actual cPanelname, find it on File Manager if you are not sure)
- Data Directory : /home/cpanelname/moodledata
- Third screen - Choose database driver (a choice of MySql, MariaDB or PostgreSQL). Check phpAdmin if you have forgotten.
- Fourth screen -Database settings
- Database settings: localhost
- Database name
- Now we have to set up the database in cPanel Database Wizard.
- cPanel Database Wizard Step 1: Create A Database - call your new database moodle in the Database Wizard.
- Copy the database name ( including the cpanel prefix) from cPanel to your web based installations screen)
- Database user
- cPanel Database Wizard - next to create a user called moodleuser
- Copy the user name ( including the cpanel prefix) from cPanel to your web based installations screen)
- Database password
- Copy the password from cPanel to your web based installations screen)
- cPanel Database Wizard Step 3: Add user to the database
- Important - check All Privileges to allow your new user access to the database
- Continue to the Check page - if there are any php problems, resolve them in PHP Selector.
- If all green, continue with the installation.
Set up the Schedule Using a Cron job
- Go to Cron Jobs under Advanced in cPanel
- Open Add New Cron Job'
- 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)
- Paste in this coomand /usr/local/bin/php ~/moodle/admin/cli/cron.php