CentOS Linux installation

Jump to: navigation, search

Note: You are currently viewing documentation for Moodle 2.4. Up-to-date documentation for the latest stable version of Moodle may be available here: CentOS Linux installation.

Installing Moodle 2.0 on stock version of CentOS 5.5 is not that straightforward due to a limitations imposed by the software available in the default repositories.

So let us go step by step in configuring and installing Moodle 2.0 on CentOS 5.5.


  • We have just a minimal OS installation
  • PHP is not installed
  • No RDBMS is installed
  • Apache is not installed
  • We plan on using MySQL as Moodle RDBMS


As you may or may not know Moodle 2.0 requires following versions of software:

Element Version
PHP 5.2.8 (5.3.3 or more recent recommended)
MySQL 5.0.25 (5.5.x recommended)
Apache 2.2.x (CentOS ships with 2.2.3)


By default CentOS 5.5 ships with PHP 5.1.6. It is very old version and unsupported by Moodle 2. To avoid recompiling PHP I recommend use of certified PHP build -Zend Server 5.x Community Edition .


Before being able to download it you will need to register and login on the site which is free of charge. Site offers several options for installing the product and the one I recommend is the RPM installer.

You can find detailed description of this process here. Make sure to install PHP 5.3 for the best results.

Execute this in command line

sh install_zs.sh 5.3 ce

and after all the installation process add this package:

yum -y install php-5.3-xmlrpc-zend-server

Finally start the zend server:

service zend-server start


Zend Server can be configured using nice web frontend that can be accessed through
http://<server url>:10082/ZendServer/

We will not go into details of how to use it but instead I will just list the PHP options and their recommended values that you should set.

date.timezone=<Your server timezone>

Also disable all extensions that Moodle does not use to speed things up.


MySQL is a good choice for Moodle RDBMS but it requires a bit more tackling to get adequate power. CentOS repositories ship with older version of MySQL (5.0.77 at the time of writing). It is highly recommended to install and use MySQL 5.5 using Oracle's official rpm packages.

Getting the packages

To do that go to MySQL 5.5. GA download page. Download the client utilities ( MySQL-client-5.5.x-x.rhel5.xxxx.rpm ) and MySQL Server (MySQL-server-5.5.x-x.rhel5.xxxx.rpm) package.


After that install the downloaded packages by executing this from command line:

 rpm -ivh MySQL-* 


MySQL 5.5 does not install any configuration file by default so we need to create one. You can use one of the existing configuration files as starting points for your personalized configuration. They are located here:


To use any of these just copy them to the /etc/my.cnf. For example:

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

For the purporse of installing Moodle 2.0 this is the configuration that I recommend as a starting point for a small Moodle instance:

port            = 3306
socket          = /var/lib/mysql/mysql.sock
port            = 3306
socket          = /var/lib/mysql/mysql.sock
#You can disable the TCP/IP protocol support 
#and all of the communication will be done through UNIX sockets
#If you use additional web applications or other programs 
#that do not support connections through UNIX Sockets, 
#do not disable TCP/IP. Just force the
#server to accept connections only from localhost

#Disable symbolic links
If you plan on having heavy duty Moodle instance with a lot of users you should increase
, and of course add more RAM.

Do not forget to start the server.

service mysql start


Now it is time to create database for the Moodle. This is the recommended command:

create database <dbname> character set=utf8 collate=utf8_bin;

The reason for specifying collation as utf8_bin is that it is the only collation that offers proper treatment of special and accented characters in sorting and comparison. For more details on this see this forum thread.


Apache will be installed autoimaticly by the zend-server installation script. The only thing we should do is to slightly optimize the default configuration. To do that we should modify the

These are the recommended settings that should be added or modified:

#Display only web server name without any additional info
ServerTokens Prod

<Directory "/var/www/html">
# ....
    Options -Indexes FollowSymLinks
    AllowOverride None
#add this to activate compressing and caching of the pages
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/xml
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE image/svg+xml
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/atom_xml
        AddOutputFilterByType DEFLATE application/x-javascript
        AddOutputFilterByType DEFLATE application/x-httpd-php
        AddOutputFilterByType DEFLATE application/x-httpd-fastphp
        AddOutputFilterByType DEFLATE application/x-httpd-eruby
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE application/x-javascript
        AddOutputFilterByType DEFLATE text/javascript
        AddOutputFilterByType DEFLATE text/ecmascript
        AddOutputFilterByType DEFLATE text/js
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        Header append Vary User-Agent env=!dont-vary
        ExpiresActive On
        ExpiresByType image/gif A2592000
        ExpiresByType image/png A2592000
        ExpiresByType image/x-icon A2592000
        ExpiresByType image/jpeg A2592000
        ExpiresByType image/pjpeg A2592000
        ExpiresDefault "access plus 1 day"
        FileETag none
#Disable any additional server info on error pages
ServerSignature Off


We need now to obtain and deploy Moodle files. We will use the simplest deployment scenario that involves minimal ammount of work and offers at the same time appropriate level of security.

Getting Moodle

Download from moodle.org latest stable release of Moodle 2 and unpack it into
cd /tmp/
wget http://download.moodle.org/download.php/direct/stable20/moodle-latest-20.tgz
tar xzpf moodle-latest-20.tgz -C /var/www/html/

Configuring file structure

Now that we have moodle files deployed in
we need to add a directory for moodledata.
mkdir /var/www/moodledata

And now to apply appropriate file permissions for both directgories.

First moodle directory:

chown -R root:apache /var/www/html/moodle/
chmod -R u=rwX,g=rX,o= /var/www/html/moodle/

And than moodledata directory:

chown -R root:apache /var/www/moodledata/
chmod -R ug=rwX,o= /var/www/moodledata/


Start the installation in a usual manner. Make sure to enter the valid name of the database you just created, choose mysqlnd/mysqli as database driver and make sure to select "Unix socket" option for best performance.

db connection.png

Because of the way we applied file permissions to the
directory installation will not be able to save
. Just copy the content of the file from the browser and manually add it to the directory.


To reflect the changes in Moodle 2.0 and use of Zend Server procedure for activating cron is following:

Copy the following content and save it into
/usr/bin/sudo -u apache /usr/local/zend/bin/php-cli /var/www/html/moodle/admin/cli/cron.php

Then mark the file as executable:

chmod u=rwx,go= /etc/cron.hourly/moodle2.cron