Mercury Web Server Information

Login

Please visit the Mercury page for login information.

URL

Users will be shown their URL when they log in to mercury.swin.edu.au using the Terminal (PuTTY).

Web directory creation

The first time you log in (using the Terminal), the required directories will be created and the URLs will be shown. After the directories are created you can upload files using File Transfer (WinSCP).

Student URLs for subjects follow a standard structure:

mercury.swin.edu.au/[subjectCode]/s[studentID]

  • Note the lowercase 's' before the student ID

Example: A student in the subject COS10020 with the ID 1234567

mercury.swin.edu.au/cos10020/s1234567

URL structure after this point depends on the directory structure you create.

  • The URL to your web pages will only be valid for the semester in which you are studying the subject.
Public Access

Your website will be only accessible by you and teaching staff in your subject. This functionality if controlled by the .htaccess file.

Directory Structure

Normally you will have a top level directory named after your subject code with a www directory. Within that, the web directories are arranged with the following sub directories:

htdocs

This directory is used for .html and .php files. It can also contain .js files, images, etc. All files here must be read only (writable only by the owner)

cgi-bin

This directory is used for cgi scripts. They must be executable .cgi scripts. All files here must be read only (writable only by the owner)

data

This can be used to save files which are written to and from your .php or .cgi scripts. Files here can be written by the web server.

Careful attention to permissions will prevent you from being locked out of your files.

.htaccess configuration

User Restrictions

Your .htaccess file is created in the htdocs directory when logging in via the Terminal for the first time. This file is pre-populated with configuration that allows for yourself and your teacher to view your website.

If you believe your .htaccess is missing or misconfigured you can simply delete it and login again via Terminal and it will be re-created.

Additional directives

You can customise access to your web pages by editing your .htaccess file.

To allow an additional user, add a line like this:

require ldap-user <username>

Example: Allow access to user s0795194

require ldap-user s0795194

To ensure that authentication is only attempted over https your file it will contain the following directive and should not be removed:

SSLRequireSSL

SSL Redirection

If you only want your site accessed via SSL (https) you can add this to your .htaccess file:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

For more information on how to configure the .htaccess file please visit the Apache website

Forbidden Error

If you receive a forbidden error when accessing your own website it is most likely because the .htaccess file exists but cannot be read by Apache. To fix this you will need to allow Apache to read this file by changing the permission.

To do this log in to mercury and run the following command:

chmod o+r /home/students/accounts/s[student number]/[subject code]/www/htdocs/.htaccess

Alternatively, in WinSCP open the .htaccess file properties (right mouse click>properties) and tick the R box in the Others row. This procedure will be similar when using Cyberduck.

WinSCP Properties

Viewing error logs

You can view your Apache error log by navigating to Mercury error page.

PHP

Mercury is currently running PHP version 5.4.

Memory Limit

If you run out of memory in your php script you will get an error

Fatal error: Allowed memory size of nnnnn bytes exhausted

You can alter the limit with the php command

ini_set('memory_limit','16M');

Place that in an appropriate place such as your config.php

File Permissions

When writing files into the data directory it is important to respect the unix file permissions and umask setting. This code shows how to correctly save files from php:

<?php
   echo "File access sample<br>";

   // set the mask so user (apache) and group (the student) have full access
   umask(0007);

   // the directory we will use.  Relative to htdocs.  It should start with /data
   $dir = "../data/assign1";

   // mkdir requires permissions specified. We use 02770 which gives apache & student access
   if(!is_dir($dir))
   {
      mkdir($dir, 02770);
   }

   // create a file
   $f = fopen("$dir/test1.txt", "w");

   // and write some data
   fwrite($f, "success!");
   fclose($f);

   // read back the file
   $data = file("$dir/test1.txt");
   echo $data[0];
?>

If you have uploaded a file which you can not remove from your student account, you should be able to remove it from a php script using the unlink() function.

Database Access

Please see Database Instructions for details and example code.

Sending email

If you want to send email from php, please set a sender address for your bounce messages:

mail($to, $subject, $message, $headers, "-r 1234567@student.swin.edu.au");

mod_rewrite

mod_rewrite can be complex to get working. You should start by carefully reading the documentation on the Apache website

Your web directory is configured using an Alias so you must specify the RewriteBase Directive

For example, your .htaccess might look like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /hit1234/s1234567/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*.png$) generate_image.php?filename=$1
</IfModule>

You could then implement your generate_image.php like this:

<?php
   $filename = $_GET['filename'];

   $image = imagecreate(640, 480);
   $red_pen = imagecolorallocate($image, 255, 0, 0);
   $black_pen = imagecolorallocate($image, 0, 0, 0);
   imagefilledrectangle($image, 0, 0, 640, 480, $red_pen);

   $message = "This is $filename";
   $x = 0;
   for($i = 0; $i < strlen($message); $i++)
   {
       imagechar($image, 10, imagefontwidth(10) * $i, 0, $message[$i], $black_pen);
   }

   header('Content-type: image/png');
   imagepng($image);
   imagedestroy($image);

?>