Creating a Website on Chalmers’ Servers

Yesterday I helped a friend move a website over to the student web space provided by Chalmers University. I’m posting this up while it’s still fresh in my mind in the hope that it helps others looking to do the same.

Chalmers students each get 500MB to 1GB of space on the university network and 10MB for database use. You can use the space for storing files but also for hosting your own website. This guide is for anyone who’d like to use it to create a website or simply make files accessible through the web. It also covers setting up a MySQL database and connecting to it through a PHP script.

What you will need

Your URL at Chalmers

CID being the Chalmers ID assigned to you. From now on wherever I write ‘CID’, you should replace it with your real CID.

Step 1: Connect to the server

This guide uses FileZilla, an application which allows you to transfer files from your own computer to a remote server simply by dragging them over.

  1. Open FileZilla
  2. Select File > Site Manager…
  3. Click ‘New Site’
  4. Give it a name (e.g. ‘Chalmers’)
  5. On the right hand side enter the following details
    Host: remote1.studat.chalmers.se
    Servertype: SFTP - SSH File Transfer Protocol
    Logontype: Normal
    User: Your CID
    Password: Your CID password
  6. Click ‘Connect’

Step 2: Create the ‘www’ folder

Once you’re connected your working directory should be:
/chalmers/users/CID/
Files in this directory are not accessible over the web — you probably don’t want everything in your space accessible to the outside world anyway. To start making files available over the web, we have to create a ‘www’ folder in this directory.

  1. In FileZilla, right click on your CID and choose ‘Create directory’
  2. Type www to replace the selected text and click ‘OK’
  3. You should now see the www folder appear in the list

Anything you place in the www folder from now on will be accessible from the web.

Step 3: Upload a simple web page

  1. Save the HTML below to a file called index.html.
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<title>Stu Dent's Home Page</title>
    	</head>
    	<body>
    		<h1>Stu Dent's Home Page</h1>
    
    		<p>Welcome! I'm a student at Chalmers 
    		training to be a good, obedient 
    		employee. I'm very happy.</p>
    	</body>
    </html>
    
  2. In FileZilla, locate your newly created file and drag it into the www folder we created in the previous step.
  3. Now access http://web.student.chalmers.se/~CID/ in your browser, replacing CID with your real CID.

If everything worked out well, you should be seeing a page titled Stu Dent’s Home Page. If you’re happy working with HTML, CSS or even JavaScript, this guide ends here. You can upload whatever you like in your www folder and it will be accessible through the URL.

If you’d like to work with PHP and MySQL, follow the steps below.

Step 4: Add PHP

In this step we’re going to upload another file. It’s based on the HTML above but includes a little PHP to show the current date and time.

  1. Save the code below to a file called test.php.
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8" />
    		<title>Stu Dent's Home Page + Date and Time</title>
    	</head>
    	<body>
    		<h1>Stu Dent's Home Page + Date and Time</h1>
    
    		<p>Welcome! I'm a student at Chalmers 
    		training to be a good, obedient 
    		employee. I'm very happy.</p>
    
    		<p>It is <?php echo date('l jS F H:i:s'); ?> 
    		inside this computer here in Gothenburg.</p>
    	</body>
    </html>
    
  2. In FileZilla, locate test.php and drag it into the www folder.
  3. Now access http://web.student.chalmers.se/~CID/test.php in your browser.

If everything worked out well again, you should see a page titled Stu Dent’s Home Page + Date and Time.

If you see a message saying Internal error, the most likely reason is incorrect directory and file permissions. To fix the permissions first right click on the ‘www’ directory and choose ‘File Attributes…’. In the field labeled ‘Numeric value’ enter 755 and click ‘OK’. Now do the same for test.php but in the ‘Numeric value’ field enter 644.

Step 5: Enable MySQL

Before connecting to MySQL you need to create a database for your account. To do this you’ll need your CID/net username and password. The username is usually just your CID with ‘/net’ added to the end. So if your CID is ‘johns’ the username you use here is ‘johns/net’. You can read more about the difference on the Chalmers accounts page.

  1. Access https://web.student.chalmers.se/db/
  2. When prompted, enter your CID/net username and your CID/net password.
  3. Under the MySQL heading, click ‘Skapa konto’ (create account)
  4. Make a note of the details: username, password, database name and server address

If you ever forget your password, you can login again and click the ‘byt lösenord’ button to get a new password.

Unfortunately I don’t think Chalmers offer GUI access to MySQL. So to administer your database you’ll have to either install a MySQL GUI app, or do it through the command line. I won’t explain how to do either of these here but you can follow the links in the further reading section below to find out more. And if you’re installing a popular PHP application, e.g. WordPress, it will take care of table creation for you — all you do is supply it with the details you noted down in this step.

Step 6: Create simple PHP + MySQL app

In this step we’ll connect to MySQL through PHP. The application is a very simple counter. Each time the page is accessed the MySQL database is updated to increase the counter value. The new value is then fetched and displayed to the user. It is made up of 3 PHP files:

  • connect_to_db.php5 contains the code to connect to the database we created in the previous step
  • create_table.php5 contains code to create the database table we’ll use to store the counter value
  • counter.php5 contains the code to update the counter value and display it to the user
  1. Save the code below to a file called connect_to_db.php5 and replace CID with your real CID and password with the database password you noted down in the previous step.
    <?php
    // show all errors
    error_reporting(E_ALL);
    ini_set('display_errors', 1); 
    
    try {
    	// DB config
    	$username = 'CID'; // your CID
    	$dbname = 'CID';   // your CID
    	$pw = 'password';  // DB password
    	$hostname = 'db.student.chalmers.se';
    	
    	// try connecting
    	$pdo = new PDO(
    	"mysql:host=$hostname;dbname=$dbname",$username,$pw);
    } catch (PDOException $e) {
    	// deal with errors
    	echo "Failed to get DB handle: ".$e->getMessage();
    	exit;
    } ?>
    
  2. Save the code below to a file called create_table.php5.
    <?php
    // include PHP file which connects to the database
    require_once 'connect_to_db.php5';
    
    // create table
    $pdo->exec("CREATE TABLE counter(visitors int)");
    
    // insert initial value (0)
    $pdo->exec("INSERT INTO counter VALUES(0)");
    
    echo 'Done!'; 
    ?>
    
  3. Save the code below to a file called counter.php5.
    <?php
    // include PHP file which connects to the database
    require_once 'connect_to_db.php5';
    
    // update counter
    $pdo->exec("UPDATE counter SET visitors = visitors + 1");
    
    // get new value
    $row = $pdo->query("SELECT visitors FROM counter")->fetch();
    
    // show visitor count
    echo 'You are visitor '.$row['visitors'];
    ?>
    
  4. Upload all 3 files to the www folder
  5. Access http://web.student.chalmers.se/~CID/create_table.php5 to create the table
  6. Now access http://web.student.chalmers.se/~CID/counter.php5 to see the visitor count.
  7. Refresh the page and you should see the number increase — each time you access the page a new number is stored in the database.

Note: If you get the internal error message again, make sure you update the file permissions to 644 as described above. Also, by giving these new files .php5 extensions we force the server to use a newer version of PHP (PHP 5) to process the files.

Further reading

This entry was posted in General. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

9 Comments

  1. Posted 23 August 2009 at 12:08 am | Permalink

    Thanks for sharing your knowledge about this.

  2. g.
    Posted 24 August 2009 at 5:36 pm | Permalink

    K1 This is exactly what I need right now… Cheers! I’ll let you know if I manage to do it :D

  3. g.
    Posted 24 August 2009 at 7:38 pm | Permalink

    I managed perfectly to get wordpress to work, and now I broke it… Guess I shouldn’t have done the 755-644 everywhere :'( Anyway, brilliant info there!

  4. Posted 24 August 2009 at 9:29 pm | Permalink

    That’s great to hear it g. I haven’t tried setting up WordPress on a Chalmers account so it’s good to know it works. So you only had a problem when you changed all permissions?

  5. g.
    Posted 25 August 2009 at 10:33 pm | Permalink

    Yeah it’s very strange, it seemed at first it was resetting the permissions, but the wordpress ceased to work at all after 5 minutes. Not sure what happened there…

  6. Posted 25 August 2009 at 10:47 pm | Permalink

    If it’s still not working, let me know what the error message is — I might try installing it just to test.

    Update: WordPress does work as long as you don’t enable permalinks — doing so will create a .htaccess which for some reason the server does not like. If you do enable by mistake, delete the .htaccess file in the WordPress root directory and change permalink settings to default.

  7. Posted 14 March 2010 at 7:41 pm | Permalink

    I found today that phpMyAdmin has errors connecting, but using Heidi SQL is a breeze, so I’d recommend that for backup duties. Thanks for the alternatives!

  8. Posted 15 March 2010 at 3:42 pm | Permalink

    Thanks g. Good to know.

  9. Posted 12 August 2011 at 11:29 am | Permalink

    I had no idea we could have a web page on Chalmers.se,
    Thanks a lot for the info.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting