Cogs of the web in plain english

A while back a client asked for help bringing their great idea to life, but really having no clue where to start or how websites really get built. This was my explanation of the web development lingo in plain English. Hopefully it will be useful to someone else.


Get a domain name via a registrar…

For people, names are usually easier to remember than numbers. Thats why a bunch of smart people at University of Wisconsin came up with a system to convert a text ‘name’ into the number that identifies a computer on the Internet. ICANN is the organization that manages requests for domain names. The registrar acts as a broker, doing the paperwork to request a domain name on your behalf.

Its a lease, not a purchase.
When a name is registered, its ‘owned’ by you for a period of time specified in the paperwork. You can extend that time-frame at any time before the domain name ‘expires’. The shortest period of time you can register a domain for is one year. ICANN allows the registrar to set their own fees, so you’ll see different prices from different registrars.

Popular registrars in America include GoDaddy.com, Network Solutions , Register.com, Tucows, Web.com

Registrars also also provide another service called domain name service or DNS. This is the actual server responsible for pointing your domain name to the correct computer on the net. This allows you to register your site with say GoDaddy and actually host it somewhere else. (like your own server room)

In my experience, GoDaddy is the least expensive. I also like their on-line tools for managing DNS and details about the domain a lot. They are pretty intuitive. You should expect to spend between $10 and $50 a year per domain name.

One gotcha they don’t explain very well on any of the sites; When registering your domain name you’ll be asked to provide contact information. Its important that you fill in current and correct information here. If there are any issues with your domain, the registrar with attempt to contact you with the information on file. If the action (transfer, sale, cancel) is not disputed in 90 days, the action is accepted by default. I worked for someone who allowed an employee to register their domain name, and when he was fired about a year later, he took the companies domain name with him. (remember e-mail relies on your domain name too) It took them two years to get the mess around that name straighted out. ICANN’s arbitration process is very slow.

Now you need a server…

Web hosting leasing space on a web server and connectivity to the Internet so you can share files/pages with people over the Internet. The web host maintains the machine, web server software and networking infrastructure as a service. Most web hosts have a guaranteed uptime, or % of the time that your site will be accessible via the Internet. (99.9% uptime roughly equates to 45 minutes of downtime a month)

There are also several types of hosting:

Shared hosting: Servers are expensive. The more people a web hosting company can serve from a single physical server, the more money they make. This makes the service very affordable (as low as $5 a month) but at the expense of performance. All the sites hosted on the server compete for resources(CPU cycle, disk space, RAM). One busy site can slow the whole server down.

Virtual Private Servers(VPS): With special software a physical server can be split into several logical servers. (Think Virtual PC where you can run microsoft windows on your mac) You can rent one of these virtual machines and have a higher level of access to the machine and a guaranteed set of resources without the expense of leasing a whole a server.

Dedicated hosting:
Dedicated hosting is leasing a whole physical server. This means your not sharing computer resources with any other sites. Its also one of the more expensive options when it comes to hosting. ($99 to $1000/month)

Co-location:
This is a dedicated server where you bring your own computer. Your renting space in the data center and network connectivity. This level of service is very expensive ($500/month and up) and does not include support for the hardware or software.

Cloud/Grid hosting:
Similar to VPS, except your use of resources like CPU and memory is metered. You pay for what you use. If your site gets really busy, you bill will be higher, but the performance of your site will not degrade because your server is really spread across thousands of physical computers. Services like this include AppJet, Google AppEngine, Amazon EC2, Microsoft Azure Services, ETC.
Because the work is spread across many physical machines, the likelihood of a machine failure with a cloud setup is very low. The rates often very competitive. These cutting edge services are often not a easy to utilize as a simple hosting solution. Expect that to change soon.

A web platform
When web hosts talk about the ‘web platforms’ they support they talking about different application layer and database layer technologies they support. The application layer is where the logic of the web application lives. The database layer is where most of the data used by an application is stored. That said, there are many combinations of the two that are popular. The technologies Popular application layers are PHP, .NET, Java, Ruby, Perl and Python. Popular databases are MySQL, MS-SQL, Oracle, Postgre and DB2.
Secure servers
To have a secure connection to a webserver requires an SSL (Secure socket layers) certificate be installed on the web server. This is a unique identifier that shows the issuer has verified your business and trusts you. The more trusted the issuer, the more expensive the certificate. Technically, a certificate issued by the cheapest provider is just as secure and the most expensive one. The only difference is the process they use to verify you.

Additional Recommended Services:

Version control
Version control is a system which can manage source code produced by many developers and make sure they don’t overwrite each others changes while they work on the same set of code. SVN is a free tool and can be installed on most servers. Unfortunatly, most hosting companies don’t allow you to install extra software. There are several companies which provide ‘hosting’ for source control. Most of these companies also provide other tools along with these accounts to further enhance developer collaboration.

Issue tracking
Issue tracking is an automated system for tracking features and bugs in software. Its vital to a collaborative development environment. So much so that all of the version control companies I listed above include it with their services at no extra cost. There are also several open source tools like mantis, trak, bugzilla, and jira. At the service center, we use mantis. I also use mantis with other clients hosted from my godaddy account.

Serving Office 2007 documents to IE Users with Apache

I encountered an issue downloading Office 2007 documents with IE. When downloaded IE would download them as ZIP files instead.

In reality, these are zip files. Our users need them to open in the correct application.

The solution was adding the new mime types to apache.
I was unaware that apache provides mime type info for each file served or that IE actually used that information.

Adding the following my apache config fixed the problem:

1
2
3
4
5
    #Types for the new office documents
    AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx
    AddType application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx
    AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx
    AddType application/vnd.ms-xpsdocument .xps

References:
http://blogs.msdn.com/dmahugh/archive/2006/08/08/692600.aspx
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype

Send a file via POST with cURL and PHP

cURL is a great library. It can do just about anything that a normal web browser can do including send a file via a post request.

This makes it really easy to transmit files between computers. In my case, I was looking for an easy way to send images snapped by various webcam systems to a central server with php managing the images.

Here is a simple script to send a file with php/cURL via POST:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
	$target_url = 'http://127.0.0.1/accept.php';
        //This needs to be the full path to the file you want to send.
	$file_name_with_full_path = realpath('./sample.jpeg');
        /* curl will accept an array here too.
         * Many examples I found showed a url-encoded string instead.
         * Take note that the 'key' in the array will be the key that shows up in the
         * $_FILES array of the accept script. and the at sign '@' is required before the
         * file name.
         */
	$post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
 
        $ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,$target_url);
	curl_setopt($ch, CURLOPT_POST,1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	$result=curl_exec ($ch);
	curl_close ($ch);
	echo $result;
?>

And here is the corresponding script to accept the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$uploaddir = realpath('./') . '/';
$uploadfile = $uploaddir . basename($_FILES['file_contents']['name']);
echo '<pre>';
	if (move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {
	    echo "File is valid, and was successfully uploaded.\n";
	} else {
	    echo "Possible file upload attack!\n";
	}
	echo 'Here is some more debugging info:';
	print_r($_FILES);
	echo "\n<hr />\n";
	print_r($_POST);
print "</pr" . "e>\n";
?>

And that's it.
Navigate to the 'send' script and it will transmit the file sample.jpeg to the accept script.

Note that you can include other arguments in the post along with the file. This allows you to authenticate the upload. I'm using pre-shared strings to 'validate' that upload came from my send script.

This works with the command line version of php too.

 

UPDATE Oct. 2014 – 

If you're using PHP 5.5 or better, check out the recently added 'CurlFile' class which makes the whole process a lot easier.

 

References:
http://us3.php.net/manual/en/function.move-uploaded-file.php
http://us3.php.net/manual/en/features.file-upload.post-method.php
http://curl.haxx.se/libcurl/php/examples/multipartpost.html
http://forums.devshed.com/php-development-5/php-curl-send-a-file-533233.html