For this exercise, you will start working with your group's server. Of course, that means some of the parts will be completed by your group, not necessarily individually.
-
[This step is all once-per-group work. Coordinate as necessary.] If your group hasn't already, complete the basic OS installation on your server. Install Apache and enable the userdir module and the expires module:
sudo apt-get install apache2-mpm-prefork
sudo a2enmod userdir
sudo a2enmod expiresEdit the file
/etc/apache2/mods-enabled/userdir.conf
to allow any overrides in an.htaccess
file. Remember that when you make any changes to the server config, you need to restart Apache:/etc/init.d/apache2 restart
If you have problems with your Apache config, your first stop should be the error log file:
/var/log/apache2/error.log
.Install the MySQL server and client: (Make sure everyone in the group knows the MySQL root password.)
sudo apt-get install mysql-server mysql-client
Note: If you would like to choose a different web or database server, you are welcome to do so with the following cautions: (1) my instructions will be for Apache/MySQL; (2) Apache is very flexible and well-suited for the many apps running together and config things we'll be doing in this course—other open source servers might not have the flexibility to deal with these (slightly odd) situations.
-
Create a database on your server. (Perhaps name the database your userid to prevent conflicts with group members.)
Create a table
people
with columnsid
(an auto increment integer and the primary key),firstname
, andlastname
(both varchars).Create a table
purchases
with columnsid
(an auto increment integer and the primary key),person_id
(a foreign key to the people table),date
(a datetime), andprice
(a decimal(5,2)).For MySQL, the statements to create the tables are like this:
CREATE TABLE `people` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `firstname` varchar(100) DEFAULT NULL, `lastname` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB CHARSET=utf8; CREATE TABLE `purchases` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `person_id` int(10) unsigned NOT NULL, `date` datetime NOT NULL, `price` decimal(5,2) NOT NULL, PRIMARY KEY (`id`), KEY `person_ind` (`person_id`), CONSTRAINT `person_key` FOREIGN KEY (`person_id`) REFERENCES `people` (`id`) ) ENGINE=InnoDB CHARSET=utf8;
Use the
INSERT
statement to populate these tables with a couple of rows of test data. -
Use the
mysqldump
command to produce a dump of the database in a filedatabase.txt
. -
Download the (UTF-8 encoded) JSON file
exer4-courses.json
which contains some class lists we can work with. [The course and instructor data is from some semester in the past; the student userids and registrations are randomly generated, so any similarity to real students is a coincidence.]Write a program in whatever programming language makes you happy (as long as it has a JSON library) that:
- Uses a JSON library to read the
exer4-courses.json
into a data structure. - Counts the total number of courses each student is registered in. (e.g. “rzk11” is registered in 22 courses—I didn't say the data was realistic).
- Uses the JSON library to output that information as JSON in a file
output.json
in some sensible format.
Some possible JSON libraries: JSON for Python, JSON for Ruby, JSON for PHP, JSON for Java.
- Uses a JSON library to read the
-
Upload your database dump, program from your previous step, and the produced
output.json
to your group's web server. Create apublic_html
directory and put your files there (i.e. in/home/userid/public_html/
).For group n, port 8000+n on
cmpt470
is forwarded to your port 80. So, if everything is set up properly, your files should be available at a URLs like:http://cmpt470.csil.sfu.ca:8000+n/~userid/output.json
[If for some reason, you have a server running on port 8080, you can find it on port 9000+n on
cmpt470
.] -
Create an
.htaccess
file in yourpublic_html
that uses theAddType
directive to make your program code serve as plain text (media typetext/plain
) and your JSON file with the correct type (application/json;charset=utf-8
).Use Apache mod_expires to set a cache expiry time on your JSON file (but not your other files) of 6 hours after access.
Submit the URLs of your work through the Course Management System.