(note, this is NOT me in the picture above)

One of my proudest moments–in server setup–involved setting up an UbuntuLinux server to host Moodle. Of course, I often feel late to the party when I get excited about learning how to do this. Still, it is an accomplishment I’m proud of for now…the same way a child is when it learns how to crawl. What’s funny is that I’d asked a colleague for some help, and he was kind enough to say, I’m waiting for you to figure it out, Miguel, then write it up in your blog. Well, here you go.

Although I’d done this in simulation, setting up a “production” site for a company was certainly a fun challenge where “failure was not an option.”

Of course, I spent ample time researching the site, as well as visiting other sites, to develop the notes below. 
Below are my rough notes on the process–completed successfully with UbuntuServer 11:
Step 1 – Install the Software You Need
At the command line/terminal, type the following…be ready to write down/remember any usernames and passwords that you are asked to create through the next two steps.

sudo apt-get install tasksel

Per Ubuntu web siteTasksel is a Debian/Ubuntu tool that installs multiple related packages as a co-ordinated “task” onto your system. We will use that to install Apache/MySQL server:

Step 2 – Install Apache/MySQL

sudo tasksel install lamp-server

Once this step is complete, you should be able to go to http://localhost and see a message saying something along the lines of “It Works!” etc. You will get some errors if you don’t take the next step:

a) Edit the httpd.conf file

sudo nano /etc/apache2/httpd.conf 

This will create a blank file to which you can paste the following into the body:

ServerName localhost

b) Restart the web server with the command below:

sudo /etc/init.d/apache2 restart

Note that you can stop the server with this command:

sudo /etc/init.d/apache2 stop

…or “start” it by replacing the word “stop” in the command above.

Step 3 – Install PHP and Other Needed Extensions
Below are steps that you will need to take (there might be some slight overlap) to setup PHP and other needed components for Moodle. You will want to take each line one by one (although you can also combine them as you see fit):

sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo apt-get install php5-curl curl  php5-xmlrpc php5-gd php5-intl

sudo apt-get install unzip zip aspell-en aspell-fr aspell-de aspell-es
sudo apt-get install php5-ldap php5-odbc

sudo apt-get install libapache2-mod-php5 libapache2-mod-ruby libapache2-mod-python php5 php5-common php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-mysql php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Step 4 – Install AntiVirus

sudo apt-get install clamav-base clamav-freshclam clamav

This will install antivirus tools on the server.

Step 5 – Edit the PHP.ini file

nano /etc/php5/apache2/php.ini

Note that you can replace the word “nano” with your text editor of choice, such as vim or leafpad or gedit (the latter two can only be used in a GUI environment, while vim and nano can be used at the command line in text-only environment).
You will want to make–at minimum–the following adjustments:

  • display_errors = Off
  • display_startup_errors = Off
  • register_globals = Off
  • post_max_size = 2000M
  • mysql.connect_timeout = -1
  • max_execution_time = 5000
  • max_input_time = 5000
  • memory_limit = 2000M
  • file_uploads = On
  • upload_max_filesize = 2000M
  • At this point, you will want to restart the server with the following command and begin the process of copying Moodle to the appropriate location, probably /var/www/moodledirectory.

    Step 6 – Installing Moodle
    To install Moodle, you will need to do some command line magic with MySQL and copying-n-pasting stuff. Below are my rough notes on the subject:

    a) Create MySQL database and a MySQL user @ localhost that will be used during Moodle install configuration

    #mysql -u root -pcreate database sandbox default character set utf8;
    grant all privileges on sandbox.* to ‘moodleuser‘@’localhost’ identified by ‘yourpassword‘;
    flush privileges;

    Note that “sandbox” , “moodleuser” could be replaced to be anything else. You can create additional users and assign them rights:

    mysql> CREATE USER ‘mguhlin’@’localhost’ IDENTIFIED BY ‘PASSWORD’;
    mysql> GRANT ALL PRIVILEGES ON *.* TO ‘mguhlin’@’localhost’ WITH GRANT OPTION;

    In the scenario above, a user “mguhlin” is being created.

    b) Create Moodledata folder
    You will need to create a MoodleData directory. Here’s the command to do it:

    sudo mkdir /var/moodledata

    Since I like to put all my Moodle instances’ MoodleData folders as subdirectories of MoodleData, I would create new subdirectories in the following way:

    sudo mkdir /var/moodledata/sandbox

    If I needed to assign write access, I would probably do something like the following:

    sudo chmod -R 777 /var/moodledata

    c) Download the Moodle installation file
    From the command line, you can download the Moodle installation file. For example:

    wget “”

    should enable you to download the Moodle file. Once downloaded, you can unzip the file in this way:


    By the way, if the wget command pulls up a blank file (not one that is 30-40 megs in size), you may want to get the direct link for the Moodle install file download (click on the regular link and then before it starts to download, copy-n-paste the link for “direct link”). I sometimes use a URL shortener ( to get a shorter link to work with if I have to type, rather than copy-n-paste, the link into the Terminal window.

    d) Create folder where Moodle PHP files will be stored.
    To create the folder where you will store the Moodle PHP files–these are the files you extracted after downloading and unzipping the file from above. You can create the folder with this command:

    sudo mkdir /var/www/sandbox

    where sandbox is the name of the proposed Moodle instance.

    Then copy the contents of your downloaded, unzipped Moodle install file with this command:

    sudo cp -rv /home/yourusername/moodle/* /var/www/sandbox/

    e) Begin the web-based install process
    Go to your web browser and type in the URL of the server, or, if on your own computer, type


    You should see the start of the Moodle installation. Follow the steps suggested. After you’ve installed Moodle, you should see everything pop up as normal.

    Step 7 – Cron Job Setup
    Your Moodle will need to occasionally run cron jobsWhy is the cron job important? 

    Cron assists some of Moodle’s modules to perform tasks on a scheduled basis. For example, the cron process might tell Moodle to check all discussion forums so it can mail out copies of new posts to people who have subscribed to that forum. The primary Moodle script that does all this is located in the admin directory, and is called cron.php. However, it can not tell itself to run, so you need to set up a mechanism where this script is run regularly (eg every five or ten minutes). This provides a “heartbeat” so that the script can perform functions at periods defined by each module.
    Read Cron – MoodleDocs

    You can edit the cron job in the following way:

    env EDITOR=nano crontab -e

    Paste in a modified line of instructions for every Moodle instance you have running on the server:

    */10 * * * * wget -q -O /dev/null “http://localhost/sandbox/admin/cron.php”

    Note that this line of instruction will run the cron job every 10 minutes. There are other ways of accomplishing this task, so be open to the possibilities!

    To edit cron jobs, go to /etc/cron.weekly, /etc/cron.hourly, /etc/cron.monthly. For example:

    cd /etc/cron.weekly

    Optional Step A – OPENSSH
    If you want to have a secure (SSL) installation of Moodle–which may result in a performane hit–or simply do SSL for your Moodle logins, you will need to take the following step BEFORE (although I did it after as long as you are comfortable moving (mv) files and folders around) your start installing Moodle. Please note that I found this tutorial helpful for moving beyond this point.

    sudo apt-get install openssh-server unattended-upgrades 

    These steps are relevant and I encourage you to follow this tutorial in two parts:
    I’m grateful to the author of the tutorials above that helped me get this!!

    Get Blog Updates via Email!

    Enter your email address:

    Delivered by FeedBurner

    Everything posted on Miguel Guhlin’s blogs/wikis are his personal opinion and do not necessarily represent the views of his employer(s) or its clients. Read Full Disclosure