Using the web server

stuweb.cms.gre.ac.uk is an Apache web server is hosted on the Unix system. Students can run PHP, Perl or just standard HTML pages on this server. The information below will help you use the server.

The server is supported by the Faculty systems team. To contact them please contact cms-support@gre.ac.uk with FULL details of the problem (including your University username, where you are studying, the problem you are having and the error messages you are getting). Please ensure that you have looked at the information below first as the articles listed cover most of the common questions and problems that students have.

How to set up your website in your Unix home area

Your website files must be kept in a directory named public_html which must reside in the root directory of your home area. e.g.

/home/userid/public_html

This directory must have file permissions set to ‘755’ which means; readable by you, writable by you and executable by you alongside being readable and executable by everyone else. This is so that other people can view your web pages using a browser.

When an account is created for you on the Unix system, this directory will already be in place with all the proper permissions set. However, if at any time these settings change, they can be re-done again by logging into Unix via ssh to stulinux.cms.gre.ac.uk and executing the following command at the shell prompt.

% checkhomepage

Files that are text-based (e.g. HTML, PHP, etc.) should have their permissions set to ‘644’. This can be achieved by using the chmod command as follows:

% chmod 644 your_file.html

Any subdirectories created inside ~/public_html must also have their permissions to ‘755’. More information regarding setting these permissions can be found by visiting the following link:
The chmod Command

Running pages on stuweb.cms.gre.ac.uk

To make a page available on the Apache server simply save the web page into the public_html folder in your Unix home area and then open a browser such as Firefox or Google Chrome and go to the following URL:

http://stuweb.cms.gre.ac.uk/~username/webpage.htm

You will need to replace username with your university login id and replace webpage.htm with the name of the web page you created. For example, if user sj593 created a page called myphotos.htm they would use the following URL:

http://stuweb.cms.gre.ac.uk/~sj593/myphotos.htm

Note that the server is case-sensitive, so it will treat myphotos.htm (along with MyPhotos.htm, MYPHOTOS.HTM, mYpHOTOS.htm, etc.) as different files. So if your file is called MyPhotos.htm you need to ensure you access it via the following URL:

http://stuweb.cms.gre.ac.uk/~sj593/MyPhotos.htm

Otherwise you won’t be able to view your file via the web server.

Password protected web pages/directories

You can restrict access to your webpages based on two criteria. One method is a username/password combination and the other method is by restricting access to only certain IP addresses and domains. Here is an example of how to password protect your webpage:

Password Protection

Create a file called .htaccess (it MUST be called this) in your ~/public_html directory. Copy the following text into the file replacing userid with your own user ID:

AuthType Basic
AuthUserFile /home/userid/public_html/.htpasswd
AuthName "special directory" 
Require valid-user

Now make the .htpasswd file (which stores the usernames and passwords of your valid users) with the following command:

htpasswd -c ~/public_html/.htpasswd username

Once the .htpasswd file is created you will need to grant access so that the web server can read the file. This can be done using the chmod command.

chmod 644 .htpasswd

Restrict by IP address

This is similar to the previous method. Create a file called .htaccess in your ~/public_html directory and place the following commands inside it replacing IP-ADDRESS with the IP address or domain you want to allow access from.

AuthType Basic

order deny,allow
deny from all
allow from IP-ADDRESS

Writing to files from your website

To allow the web server to write files to your home area from your website, you must create a directory to store the files and change the permissions so that the web server can write to it. This is done using the following commands:

Login into Unix via ssh and change to the directory containing your script and run these two command (where OUTPUT is the directory being created):

mkdir OUTPUT
chmod 777 OUTPUT

Now change your code so that new text files are written to that directory.

Example PHP code (order.xml is the file being written)

$fp = fopen("ORDERS/order.xml", "w") or die("Couldn't create new file");

Also note that you will need to change the permissions of your file once it is written to 0666, so that you can delete it later. Add the following code after you have closed the file:

chmod("ORDERS/order.xml", 0666);

Running cgi script from cgi-bin

Before you can run the cgi script on stuweb.cms.gre.ac.uk, you must first login into Unix via ssh to stulinux.cms.gre.ac.uk and run the following commands:

cd ~/public_html
mkdir -m 755 cgi-bin

All perl cgi scripts must have a file type of .pl, be executable and live in a directory called ~/public_html/cgi-bin

Sending email using cgiemail

This page demonstrates the use of an HTML form to send email using the cgiemail program. email.txt must be place inside your public_html directory or a subdirectory of it.

Any script creating excessive mail error messages is likely to result in it being disabled.

WARNING: Inappropriate use of University email facilities will result in your account being disabled.

// Change [userid] to your user ID e.g. gsg03

<form method=post action="/cgi-bin/cgiemail/~[userid]/email.txt">
Your Userid: <input type="text" name="userid">
Your Email Address: <input type="text" name="email">
Comments:
<textarea cols=40 rows=5 wrap=physical name="comment"></textarea>
<input type="submit" name="send" value="Submit"><input type="reset"> </form> // Where email.txt is placed under ~/public_html directory and contains: To: your_userid@gre.ac.uk Subject: Testing cgiemail userid = [userid] email = [email] comment = [comment] If email.txt was placed in the directory ~/public_html/mysite the action command would change to: /cgi-bin/cgiemail/~[userid]/mysite/email.txt

Sending email using PHP

This page demonstrates the use of a PHP to send an email on stuweb.

Any script creating excessive mail error messages is likely to result in it being disabled.

WARNING: Inappropriate use of University email facilities will result in your account being disabled.

// Change [userid] to your userid e.g. gsg03

<?php
echo "Sending email!";
mail("[TO_ADDRESS]", "[SUBJECT]", "[MESSAGE]", "From: [USERID]@gre.ac.uk\r\n");
?>

Comments are closed.