Apache and MySql

#Apache
So… Apache is apache – nothing to say – just install and use it. To do so in the terminal the following command should be executed: “sudo apt-get install apache2″. And if you manage to type your sudo password correctly – after couple of seconds it will be installed. You even can check it right away by navigating your browser to “localhost”.
ApacheWorksScreen
“It works!” your browser will say – no jokes. But to start creating your personal page would be nice to change physical directory on your computer for websites. The easy way is to set it up under user home directory where you and other user can have dedicated pages. To do so in good old terminal the following command should be executed – “sudo a2enmod userdir” after which the server need to be restarted – “sudo service apache2 restart”. Now to complete the preparation a directory “public_html” has to be created under user’s home directory. To check that it works – create simple “index.html” file under public_html directory and define there simple test paragraph or header.
userPageScreen
Here we go. Quick and easy just in few minutes we can start creating a web page.

#MySQL
Well, you know, sooner or later you’ll come to a point where there will be need for database and MySQL is a good choice. To manage with it you can use either phpMyAdmin or command based client. Today I’m in a command line mood so just type in terminal the following command: “sudo apt-get install mysql-server mysql-client”. And yeps, now we can play with it a bit. You can run it by command “mysql -u root -p” and then just create first database.

For test purposes, I’ll create database where information about courses I’m currently taking will be kept.

  • So “Create Database hhCourses”.
  • The next thing is to create little teacher table: “CREATE TABLE Teacher(id INTEGER PRIMARY KEY, name NVARCHAR(50), email NVARCHAR(50));”.
  • Second table I need is Room: “CREATE TABLE Room(number INTEGER PRIMARY KEY, type NVARCHAR(50));”.
  • After that I need table which would represent course modules: “CREATE TABLE Module(id INTEGER PRIMARY KEY, code NVARCHAR(10));”.
  • And finally the main course table: “CREATE TABLE Course(id INTEGER PRIMARY KEY, name NVARCHAR(100), dayOfWeek NVARCHAR(10), courseTime TIME, moduleId INTEGER REFERENCES Module(id), roomNumber INTEGER REFERENCES Room(number), teacherId INTEGER REFERENCES Teacher(id));”.

showTablesScreen

Now it is time to put into it some data:
INSERT INTO Teacher VALUES(1, ‘Pekka’, ‘pekka@mail.com’);
INSERT INTO Teacher VALUES(2, ‘Juhani’, ‘juhani@mail.com’);
INSERT INTO Teacher VALUES(3, ‘Tero’, ‘tero@mail.com’);

INSERT INTO Module VALUES(1, ‘SYS’);
INSERT INTO Module VALUES(2, ‘DAT’);
INSERT INTO Module VALUES(3, ‘ITP’);

INSERT INTO Room VALUES(4004, ‘lab’);
INSERT INTO Room VALUES(1001, ‘lecture’);
INSERT INTO Room VALUES(5001, ‘lab’);
INSERT INTO Room VALUES(5009, ‘lab’);

INSERT INTO Course VALUES(101, ‘Development project’, ‘MON’, ’10:00:00′, 1, 4004, 1);
INSERT INTO Course VALUES(102, ‘Linux’, ‘THU’, ’12:00:00′, 2, 5001, 3);
INSERT INTO Course VALUES(103, ‘Java’, ‘WED’, ’16:00:00′, 3, 5009, 2);
INSERT INTO Course VALUES(104, ‘Mobile’, ‘FRI’, ’08:00:00′, 3, 5009, 2);

Check:
tableDataScreen

That’s it folks! Play around and enjoy.

One thought on “Apache and MySql”

Leave a Reply

Your email address will not be published. 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>