Saturday 19 May 2012

First local LAMP site

It's all coming together...

In my post about installing PHP, I created a small script to see if it was a birthday or not. I'm now going to turn this into an actual local site using all the constituent parts of LAMP and some CSS. Using MySQL may be a little overkill, but I think it would be good to practice first on a nice simple site.

I already have the site set up in my hosts folder located at /etc/hosts.
My virtual hosts file is also already set up but seems a bit bloated. At the moment I will leave it as it is. I think a future post about virtual hosts may be a good idea.

Create a database in mysql
CREATE DATABASE isitmikesbirthday;
USE isitmikesbirthday;
I now need to set up a user for my script to select from the database as and set up any database tables I want.
GRANT SELECT ON isitmikesbirthday.* TO 'iimb'@'localhost' IDENTIFIED BY 'password';
Then create a table with for my information
CREATE TABLE persons(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), first_name VARCHAR(10), last_name VARCHAR(10), date_of_birth DATE);
I then need to put some data into the table
INSERT INTO persons (first_name,last_name,date_of_birth) VALUES ('Michael','Gwynne','xxxx-09-27');
That should be the MySQL part over. Now to the PHP script. It should be pretty self explanatory. This script should also be foolproof and have all the error checking needed in it.

Hmm, it seems I can't paste PHP code into Blogger. I'll have to find a work around and come back to this. Unless anyone knows how to.... please feel free to comment below.
In the mean time, you can download my code in order to have a look at it.
isitmikesbirthday?
Simple site


There are several things I realise are slightly bad practice in my code.
  1. Some of these things like the class and CSS should be spilt into separate files.
  2. The member variables of Date should not be public and should be instead called by helper functions to avoid accidental assignment.
With my first two goals in mind:
  1. Google Friendliness (Speed, W3C validation etc..)
  2. Neat, Readable, Self-documenting code
Please have a look at the code and see if you can find any ways to improve performance, readability and security. Comment below, add reasoning if neccessary.

No comments:

Post a Comment