Web Server Programming
This page is about server-side Web programming. Before you can do such programming your server needs to be set up. See Web Server Administration for details.
Server-side programs have two major components- a data engine (usually a relational database) and a scriptable Web server or one with a CGI interface.
It's probably possible to build a web application without a database, but I wouldn't recommend it. The database is where your data lives, and data is the important part of your app. Using a database means you don't have to figure out how to structure your own data. MySQL is a relational database engine. Relational databases store data in tables, like so:
This probably looks familiar to you if you work with spreadsheets. Spreadsheets also use tabular data, and spreadsheets are ok, but database > spreadsheet. Let's look at this table. First off, you wouldn't have that first column in a spreadsheet (because the spreadsheet already provides it). BoxID is the "primary key" for this table. Every table must have a primary key. The primary key serves two important functions:
- It is a unique identifier for each record (row) in a table.
- It serves as an endpoint to identify relations between tables.
What are relations between tables? We'll get to that in a bit. First, let's have a look at the RAMconfig column. Why are there numbers for RAMConfig? Those numbers don't really describe anything, do they?
Check this out:
So what, it's another table. This table lists a bunch of configurations of RAM. Big deal. But the other table has a column for configurations of RAM. If we had entered all that RAM data into the top table we would have had to repeat ourselves a bunch of times, since two machines each have RAMConfig number 2. Instead, we split off the RAM data into a separate table with its own data, and a primary key isomorphic to the RAMConfig column in the first table. Then we tell the database something like:
ALTER TABLE `accounts` ADD CONSTRAINT `FK_myKey` FOREIGN KEY (`RAMconfig`) REFERENCES `RAMconfigs` (`configID`) ON DELETE CASCADE ON UPDATE CASCADE;
That's basically what SQL (Structured Query Language) commands look like. That command is probably wrong, SQL is fairly complicated. OR you could just install phpMyAdmin and draw a little arrow going from RAMconfig in the Computers table to configID in the RAMconfigs table and hey presto, you've got a relation without typing all that complex stuff.
Popular languages for Web programming include PHP, Perl, Python and Ruby. Any language can be used for Web programming, and many have. To avoid re-inventing wheels Web programmers frequently make use of *frameworks*, which are libraries of code available for re-use.
PHP is an old scripting language. The name kinda-sorta stands for Hypertext Preprocessor, which is PHP's main function. PHP has been around since the early 1990s (hence 'ancient', though Perl hackers still think of PHP as the 'new kid') and has since grown into a full-featured scripting / programming language. As of PHP 5 the language supports OOP, but that's a topic for a different class. PHP can be embedded in HTML files. The server can sometimes parse PHP in files with .html extension, but using .php extension is safer.
Here's a sample of some embedded PHP: