Creating a website

Creating a Website at CSE

Each user account is entitled to a website, which is hosted out of the home directory of the account. You may also be interested in using CGI Scripts and general information about World Wide Web.

Executive summary

Your entire website, i.e. all files and scripts comprising it, has to be contained within your ~/public_html directory. Symbolic links to files outside public_html will not be followed. It is customary to put CGI scripts in a cgi-bin subdirectory. File permissions have to be set so as to be accessible by the webserver (see next section). You can access your website by either of these URLs:
  • http://www.cse.unsw.edu.au/~username/
  • http://username.web.cse.unsw.edu.au/
which both map to ~username/public_html/index.html on the filesystem. This is your base website; subdirectories and files other than index.html are simply appended to the URL e.g.: http://www.cse.unsw.edu.au/~username/cgi-bin/coolscript.pl

File Permissions

The webserver runs as a user (w3serv, for the interested) and therefore is treated as just-another-user by the filesystem when it tries to access your public_html. This means you have to set world file access permissions:
  • world-execute on all directories including your homedir, a step often forgotten
  • world-read on all files, unless they are scripts
  • world-execute on all scripts

Detail

You can set up a website with public access by putting your home page in the file index.html, or one of the alternatives listed below, in a directory called public_html in your home directory. public_html is created for users on their first login but needs to be manually created for other accounts. Your home directory and the public_html directory will both need to be world-executable (which allows anybody to access the directory), because to the filesystem a browser is coming from the outside world - even if it's you running the browser looking at your own web page on the CSE system. You can do this using chmod. The HTML files within public_html that you want people to be able to access need to be world-readable. Any scripts you want people to be able to run need to be world-executable and, if you like, can also be world-readable. How to setup a website in one minute:
  • cd this sets your current working directory to your homedir
  • mkdir public_html if necessary
  • chmod o+x public_html
  • chmod o+x .
  • vi public_html/index.html (or use your favorite editor)
  • chmod o+r public_html/index.html
When asked to access a CSE website, i.e. the CSE webserver receives a request for either http://www.cse.unsw.edu.au/~username or http://username.web.cse.unsw.edu.au, it looks within ~username/public_html for a file called one of the following:
  • index.html
  • index.htm
  • index.shtml
  • index.cgi
  • index.php
This file is the homepage. If it does not exist or isn't world-readable the webserver will return an error if somebody tries to access the base website. However, URLs accessing a specific file within the website will still work. For example, with the following directory: %ls -l ~fblo123/public_html total 100 -rw-r----- 1 fblo123 fblo123 278767 May 2 21:21 index.html -rw-r--r-- 1 fblo123 fblo123 278767 May 2 21:21 aboutme.html the URL http://fblo123.web.cse.unsw.edu.au/ will return an error, but http://fblo123.web.cse.unsw.edu.au/aboutme.html will work. index.html needs to be written in HTML as will, most likely, the majority of your files. By convention files in your website, like other files, are suffixed to indicate the content: indeed, HTML files need to be suffixed with .html in order to be rendered by most browsers. Scripts don't necessarily need a suffix as long as they start with a line invoking the relevant interpreter, but it will make life easier for you if you label them .pl or .php appropriately. Each HTML file is a webpage. When beginning to build your website, you will probably hyperlink most of your webpages to index.html; later as you become more ambitious you may want a definite structure. There are many places to learn about HTML, but a couple of good sites for beginners are: http://www.htmlcodetutorial.com/ http://http://www.htmldog.com/guides/htmlbeginner/ which also includes a Beginner's Guide to CSS. If you just want information on the HTML tags (elements) there are lots of websites for that also, but W3.org is about as authoritative as you can get: http://www.w3.org/TR/html4/index/elements.html HTML is easy to write. Bad HTML is even easier. Cast an eye over http://webpagesthatsuck.com/ occasionally and learn some basic design principles.

Specifying Charset for web pages (optional)

If you notice your website failed to display the expected contents due to character encoding you can change server-side directives in Apache to specify the character encoding sent by the server.

To do so, you will need to modify the .htaccess file in your website directory.
more details about .htaccess usage, please see Restricting web access(taggi)

Open .htaccess file in text-editor, use the following syntax to specify the character encoding for the selected file extension AddCharset encoding .file_extension For instance, to following example will server all files with the extension .html as UTF-8 AddCharset UTF-8 .html You can use <File> tag to apply different character encoding to your nominated pages. The following example will server UTF-8 for example.html page only. <Files "example.html"> AddCharset UTF-8 .html </Files> More details can be found on W3C website: Setting charset information in .htaccess(W3C)

Related topics

There are lots of other questions relating to your own website at CSE!
Last edited by mgao 31/07/2015

Tags for this page:

html, web, url