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 Chalmers ID (CID) and password
- Your CID/net and password (this is different from the above)
- FileZilla FTP client (but it’s also possible to connect via SSH or a different client if you prefer working that way)
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.
- Open FileZilla
- Select File > Site Manager…
- Click ‘New Site’
- Give it a name (e.g. ‘Chalmers’)
- 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 - 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.
- In FileZilla, right click on your CID and choose ‘Create directory’
- Type www to replace the selected text and click ‘OK’
- 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
- 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>
- In FileZilla, locate your newly created file and drag it into the www folder we created in the previous step.
- 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.
- 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>
- In FileZilla, locate test.php and drag it into the www folder.
- 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.
- Access https://web.student.chalmers.se/db/
- When prompted, enter your CID/net username and your CID/net password.
- Under the MySQL heading, click ‘Skapa konto’ (create account)
- 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
- 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; } ?>
- 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!'; ?>
- 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']; ?>
- Upload all 3 files to the www folder
- Access http://web.student.chalmers.se/~CID/create_table.php5 to create the table
- Now access http://web.student.chalmers.se/~CID/counter.php5 to see the visitor count.
- 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
- Chalmers accounts
- Chalmers databases
- Brief intro to creating a site on Chalmers’ servers (in Swedish)
- MySQL GUIs
- PHP tutorials
9 Comments
Thanks for sharing your knowledge about this.
K1 This is exactly what I need right now… Cheers! I’ll let you know if I manage to do it 😀
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!
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?
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…
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.
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!
Thanks g. Good to know.
I had no idea we could have a web page on Chalmers.se,
Thanks a lot for the info.