Moodle on Solaris
January 2nd, 2008 by JohnRecently I had the opportunity to install Moodle—a PHP-driven, open source course management system for online learning—on one of our enterprise class servers running Sun Solaris 10 and Sun Java System Web Server 7.0. While there were a number of packages available to simplify the installations of some versions of PHP and Moodle, I needed to install Moodle 1.9, for which there were not suitable packages readily available. In this entry I document the steps I took to perform manual installations of both pieces of software, as well as some of the technical issues I ran into along the way.
Contents
As the documentation indicates, Moodle requires several pieces of software to be installed before it can run. First it requires a web server, which in my case was the Sun Java System Web Server 7.0. Second, the web server must have a fairly recent version of PHP installed, with a number of options and extension modules enabled (see below). Finally, a database server is required, which in my case was going to be MySQL.
The PHP installation needs the following options and extensions to be enabled for best results:
- The mysql extension—or the pgsql extension if you are using a PostgreSQL server (required).
- The GD and FreeType 2 libraries.
- The mbstring option.
- Basic extensions: tokenizer, session, etc. (usually enabled by default).
- Other extensions: iconv, zlib, curl, and openssl.
- Additional extensions if you are using some more advanced Moodle features (see Moodle docs).
You also, of course, need a suitable compiler and make utility for compiling and installing PHP with the above options configured (and also for your web and database server software if those are not already compiled or installed).
Since the Sun web server was already installed and running on our server, I only needed to install PHP, MySQL, and all other prerequisite software on which these two items depended.
Installing Prerequisite Packages
For the prerequisites, I used the packages available at Sunfreeware.com. The installations were very straightforward for the most part (just a bit tedious in high concentration!), so I will not document them in detail. As an example, to install the zlib package on our server, I downloaded the file zlib-1.2.3-sol10-x86-local.gz to /tmp, and then ran the following commands from the shell (as root):
cd /tmp gunzip zlib-1.2.3-sol10-x86-local.gz pkgadd -d zlib-1.2.3-sol10-x86-local
Note that a number of the packages have dependencies on other packages, which must be installed as well. Most of the packages are installed to /usr or /usr/local. Also, for the GD package, you have the option of either installing it separately or using the bundled GD package that comes with PHP. I simply used the bundled package.
The MySQL server software can also be downloaded as a package from Sunfreeware, but it requires some additional manipulation. The relevant additional instructions are placed in /usr/local/doc/mysql. They involve adding a new system user/group, adjusting permissions, running a script to set up the basic grant tables, and starting the server daemon. It is also necessary to configure default MySQL user accounts and secure the server properly. I am not documenting these procedures here; see the MySQL installation docs for more information. (Note: if you are using a MySQL package from a different source, or are compiling it manually, you must use a version that is compatible with the PHP distribution you are installing. For example, if you will be running a 32-bit installation of PHP, you must install a 32-bit version of MySQL, or else you will get errors. Note also that ’strict mode’ should remain turned off in the configuration file for MySQL to work with Moodle.)
Once MySQL is installed and running, it is necessary to create a new empty database for Moodle to use, and this database must be configured to use the utf8 character set. Using the command line MySQL client, I did this as follows:
cd /usr/local/mysql/bin
./mysql -u root -p
...
mysql> CREATE DATABASE moodle;
mysql> ALTER DATABASE moodle
-> DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
It is also recommended to create a MySQL user account specifically for Moodle:
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,
-> DROP,INDEX,ALTER ON moodle.*
-> TO moodleuser@localhost IDENTIFIED BY 'somepassword';
mysql> QUIT
...
./mysqladmin -u root -p reload
...
(Note the password above should be changed for an actual installation.)
Once MySQL and all of the prerequisite packages were installed, I was able to begin the PHP installation. I downloaded php-5.2.5.tar.gz from the PHP web site to /tmp, and got the source files extracted:
cd /tmp gunzip php-5.2.5.tar.gz tar -xvf php-5.2.5.tar cd php-5.2.5
I was now ready to run the included configure script to configure the PHP build. This step involves enabling the options and extensions mentioned above, specifying the install locations of any relevant dependencies, and also specifying any other parameters necessary for build.
The installation of PHP with the Sun Java System Web Server actually presents several options at this junction: PHP can be compiled as a regular CGI module, a FastCGI module, or an NSAPI module. Roughly, these options are in order from the simplest but least efficient to the more complicated but most efficient. I decided to take the middle ground and install PHP as a FastCGI module. (For more information on the different types of installations and their pros and cons, see Sun documentation.)
Below is the code I used to configure the build. (Note that it is necessary to export the install location of your C compiler to PATH, so that the configure script can make use of it. In my case, I was using the Sunfreeware gcc package. If you are using a different compiler, make the appropriate adjustments.)
PATH=/usr/local/bin:$PATH export PATH ./configure --prefix=/usr/local \ --enable-fastcgi \ --enable-force-cgi-redirect \ --enable-mbstring \ --with-mysql=/usr/local/mysql \ --with-gd \ --with-png-dir=/usr \ --with-jpeg-dir=/usr \ --with-xpm-dir=/usr \ --with-freetype-dir=/usr \ --with-zlib=/usr/local \ --with-curl=/usr/local \ --with-openssl=/usr/local/ssl
(Note: if you are installing an older version of PHP, you may run into an error at this point stating that the ‘GD build test failed’. A closer inspection of the config.log file may reveal that the build test for GD failed because it was unable to locate necessary libiconv symbols. If this is the case, you may need to adjust environment variables manually or edit the configure script directly by adding -liconv wherever -lgd appears in a build. For more information, see this article.)
Once the configure script completed successfully, it was time to build and install PHP:
make make install
This installed PHP in /usr/local. In particular, it installed /usr/local/bin/php-cgi, which was the FastCGI module.
To configure additional PHP options after it is installed, it is necessary to use a php.ini file. You can copy one of the distribution files into /usr/local/lib and then edit it, e.g.:
cp php.ini-recommended /usr/local/lib/php.ini
The following options should be set in php.ini for Moodle to work:
; The memory limit must be at least 16M memory_limit = 128M safe_mode = Off file_uploads = 1 session.auto_start = 0 session.bug_compat_warn = 0 session.save_handler = files magic_quotes_runtime = 0 ; The following setting is recommended magic_quotes_gpc = 1
Consult the PHP documentation for more information on php.ini.
Sun Java System Web Server 7.0 now needed to be configured to use my PHP FastCGI module. This involved editing a few different configuration files. First I navigated to the appropriate directory (note that the path below is specific to my setup, which was running on moodle.whardy.com):
cd /var/opt/SUNWwbsvr7/https-moodle.whardy.com/config
Then I enabled the FastCGI module by adding the following line to the file magnus.conf:
Init fn=load-modules shlib="libfastcgi.so"
Next I had to add a Service type directive to the file obj.conf, placing it inside the default object as follows:
<Object name="Default">
Service type="magnus-internal/php"
fn="responder-fastcgi"
app-path="/usr/local/bin/php-cgi"
bind-path="localhost:3101"
app-env="PHPRC=/usr/local/lib"
app-env="PHP_FCGI_CHILDREN=2"
app-env="PHP_FCGI_MAX_REQUEST=200"
app-env="FCGI_WEB_SERVER_ADDRS=127.0.0.1"
app-env="LD_LIBRARY_PATH=/usr/local/lib/php"
PathCheck fn="find-index"
index-names="index.php,index.html,home.html,index.jsp"
...
</Object>
Note that the PathCheck directive above includes index.php. This allows the web server to run a PHP script (named index.php) as the default document in a directory. Note also that there are usually lots of other directives in the obj.conf file, which I am not displaying above for brevity.
Finally, I associated file extensions with the new type by adding a line to mime.types:
type=magnus-internal/php exts=php,php3,php4,php5
The web server needed to be restarted for the changes to take effect:
../bin/stopserv ../bin/startserv
At long last I was ready to install Moodle! Well, almost. First I needed to create a data directory outside of web root where Moodle would be able to store course documents, user pictures, and so on. I created it directly above the web root (note again the path below is specific to my server setup):
cd /var/opt/SUNWwbsvr7/https-moodle.whardy.com mkdir moodledata chmod -R 770 moodledata
Finally, I was able to run the web-based installer at http://moodle.whardy.com/install.php. Here I entered basic configuration parameters including database type/host/username/password/table, web root path, data directory path, etc. These parameters were all obtained from the installation steps above. After this, I accessed http://moodle.whardy.com/admin/ to complete the installation. (Note: the installation scripts provide status information during installation. If you run these scripts and encounter errors, consult the Moodle installation docs for information on the possible causes.)
Once these steps were complete, Moodle was ready to go! Or was it?
After setting up some test courses and adding documents to the courses, I noticed what seemed to be some bugginess in the displaying of uploaded files. When I would click on any links to access files, I would just get a page that said "No input file specified". In addition, none of my user pictures were showing up in my profile. All of this despite the fact that the files had been successfully uploaded into my moodledata folder.
After poking around, I realized that the URL’s for these resources in Moodle’s HTML output looked a little funky, coming out in the form:
http://moodle.whardy.com/file.php/1/mycourse/myfile.html
It turns out this is a feature, however, not a bug, in Moodle’s implementation. Moodle writes the URL’s in this way by default in order to improve caching performance for clients and proxy servers. It’s called the ’slasharguments’ feature, and while it means well, it unfortunately did not work well with my server setup.
Luckily there are ways around it! The simplest workaround is to just disable slasharguments. From the Moodle administrator, you go to Server -> HTTP, uncheck ‘Use slash arguments’, and click ‘Save Changes’. Easy enough. URL’s will then be written in the form:
http://moodle.whardy.com/file.php?file=/1/mycourse/myfile.html
But what if you like the caching benefits provided by the slash URL format? It is possible to keep the slashes when running Moodle on the Sun Java System Web Server; you just have to code silent URL rewriting into the web server configuration. This is done by first returning to the web server configuration files:
cd /var/opt/SUNWwbsvr7/https-moodle.whardy.com/config
Then you make the following addendum to obj.conf, again in the default object:
<Object name="Default"> ... <If $uri =~ "^/file\\.php/(.*)$"> NameTrans fn="restart" uri="/file.php?file=/$1" </If> </Object>
Of course the web server must be restarted for the changes to take effect:
../bin/stopserv ../bin/startserv
And now Moodle should work fine even with slasharguments enabled.
To see our Moodle installation in action, visit www.SunStudentCourses.com
References








