A Beginner's Guide to Setting Up A Web Hosting System (Or, the design and implementation of a system for the worldwide distribution of pictures of

40 

Full text

(1)

A Beginner's Guide to Setting Up A

Web Hosting System

(Or, the design and implementation of a system for the worldwide distribution of pictures of cats.)

(2)

Yes, you can download the slides

(3)
(4)

A brief history of a web request

User types in a URL

Browser breaks the request into pieces: 1. Protocol (http, ftp, gopher, etc.)

2. Domain name or IP address 3. Path

If it's a name, asks the resolver (handwaving here, because what the resolver is and how it behaves varies and almost never matters) for the IP.

Resolver queries root name servers for the authoritative name server.

Uses new-found name server details to find out the IP address. Sends an HTTP request to server.

(5)
(6)

The LAMP Stack

(LAMPBPDAHOOPTCTTMTWAMAP)

1. Linux

2. Apache 3. MySQL

4. PHP/Perl/Python/Ruby (that's Ruby with a P)

5. BIND

6. Postfix/Sendmail 7. Dovecot

8. And hundreds of other pieces that come together to make the world a more awesome place

(7)

DNS

(8)

How DNS Really Works (The

handwaving version)

1. You "buy" a domain name

2. Registrar creates a record in the root name servers

3. Clients query root servers, and then your servers (assuming root servers have accurate information)

4. DNS servers along the way cache the information, making DNS awesomecrazyfast when you do it right

(9)
(10)

Installing a name server

There are many name servers, but BIND serves more than

75% of the world's DNS traffic, so it's probably good enough for us. You don't have to run your own name server, but you need to understand how DNS works, no matter what.

Red Hat, CentOS, Fedora, Scientific Linux, etc. $ sudo yum install bind dnsutils

Debian, Ubuntu

$ sudo apt-get update

(11)

Configuring BIND

Add a zone (probably in /var/named/chroot/var/named or similar) $ttl 38400 @ IN SOA xenhost.virtualmin.com. ( 1244378204 ; serial 10800 ; refresh 3600 ; retry 604800 ; expire 38400 ) ; negative TTL virtualmin.com. IN NS ns1.virtualmin.com. virtualmin.com. IN NS ns2.virtualmin.com.

(12)

Configuring BIND Continued

Add some records

virtualmin.com. IN A 67.228.198.99

www.virtualmin.com. IN A 67.228.198.99 mail.virtualmin.com. IN A 67.228.198.98 @ IN MX 5 mail

(13)

Configuring BIND Continued

Check the configuration

# named-checkconf -t <path to chroot> Restart BIND

RHEL, CentOS, Fedora, etc. # service bind restart Debian, Ubuntu

(14)

It isn't working!

Use whois to make sure you got it right at the root servers. # whois virtualmin.com

(15)

HTTP (A lot simpler than DNS, and I

can prove it)

$ telnet virtualmin.com 80 Trying 67.228.198.99... Connected to virtualmin.com (67.228.198.99). Escape character is '^]'. GET / HTTP/1.1 host: www.virtualmin.com ...

(16)

Installing Apache

Red Hat, CentOS, Fedora, etc. $ sudo yum install httpd Debian, Ubuntu

$ sudo apt-get update

$ sudo apt-get install apache2 apache2-mpm-prefork

(17)
(18)

Configuring Apache

Pretend like the single-site mode of Apache does not exist.

Always use VirtualHosts, even if you only want one domain, because some day you'll want a second, I guarantee it.

(19)

Configuring Apache VirtualHosts

NameVirtualHost 67.228.198.99:80 ... <VirtualHost 67.228.198.99:80> ServerName virtualmin.com ServerAlias www.virtualmin.com DocumentRoot /home/virtualmin/public_html

ScriptAlias /cgi-bin/ /home/virtualmin/cgi-bin/ DirectoryIndex index.html index.htm index.php <Directory /home/virtualmin/cgi-bin>

allow from all </Directory> </VirtualHost>

(20)

CGI Scripts

<VirtualHost 67.228.198.99:80> ServerName virtualmin.com

ServerAlias www.virtualmin.com

DocumentRoot /home/virtualmin/public_html

ScriptAlias /cgi-bin/ /home/virtualmin/cgi-bin/

DirectoryIndex index.html index.htm index.php

<Directory /home/virtualmin/cgi-bin> allow from all

</Directory>

(21)

A Simple CGI Application

#! /usr/bin/perl use warnings; use strict;

print "Content-type:text/html\n\n";

print "<html><head><title>Hello World!</title></head>\n\n"; print "<body>\n";

print "<p>Hello world!</p>\n"; print "</body></html>";

(22)

What about PHP?

PHP can run as a CGI, so it should already work in ~/cgi-bin, but you pay a performance penalty.

So, we can add mod_php or mod_fcgid to the picture to PHP is always running.

I recommend mod_fcgid (and suexec), but I'm going to cover

mod_php because it's simpler, and this is a beginner's guide. At the end, I'll tell you how to automatically get a working

suexec+fcgid environment for PHP, and any other language that works with fcgid.

(23)
(24)

Installing mod_php

Red Hat, Fedora, CentOS, etc. $ sudo yum install php Debian, Ubuntu

$ sudo apt-get update

$ sudo apt-get install php5 libapache2-mod-php5

(25)

Configuring PHP

It's probably already done for you. The PHP packages on both Red Hat and Debian based systems include a default

configuration that'll probably Just Work(tm).

But, just in case:

Red Hat, CentOS, Fedora:

Edit /etc/httpd/conf.d/php.conf, remove the # in front of the DirectoryIndex, AddHandler, and AddType

directives.

Debian, Ubuntu:

(26)

A Simple PHP Application

This goes in ~/public_html, rather than ~/cgi-bin

<?php

phpinfo();

(27)
(28)

MySQL

A database stores data.

A relational database stores data and provides mechanisms to find specific pieces of data based on relationships to other data.

MySQL also happens to be required for the vast majority of large web applications (Drupal, Joomla, Wordpress, Ruby On Rails, MediaWiki, etc.).

(29)

Installing MySQL

Red Hat, CentOS, Fedora, etc.

$ sudo yum install mysql mysql-server php-mysql Debian, Ubuntu

$ sudo apt-get update

$ sudo apt-get install server mysql-common mysql-client php5-mysql

(30)

Configuring MySQL

Copy an appropriate /etc/my.cnf (if one does not already exist) from the install directory, and set a root password.

Don't touch anything else, until you know what you're doing. # mysqladmin -u root password 'newpassword'# sudo

(31)
(32)

Mail is not a single thing

"My email isn't working" is not a sensible thing to say, unless all mail services are not working.

Email is made up of:

1. Message Transfer Agent/SMTP Server (Sendmail, Postfix, Exim, QMail)

2. IMAP/POP Server (Dovecot, Cyrus, Courier, etc.)

3. Delivery Agent (procmail, binmail, maildrop, postdrop, etc.) 4. Optional Spam and Anti-virus servers (SpamAssassin,

ClamAV, etc.)

5. Mail Retrieval Agent (i.e. "mail client", Outlook (lookout!), Thunderbird, RoundCube, Usermin, Mail.app)

(33)
(34)

Installing a Mail Server (all the pieces)

Make sure your system has a fully qualified domain name! (I'm serious.)

Red Hat, Fedora, CentOS, etc.

$ sudo yum install postfix procmail dovecot spamassassin

There are no ClamAV packages in RHEL/CentOS.

Debian, Ubuntu

$ sudo apt-get update

$ sudo apt-get install postfix postfix-pcre procmail dovecot spamassassin spamc clamav-base clamav-daemon clamav clamav-freshclam clamav-docs

(35)

Configuring a Mail Server

You don't (much).

The mail stack packages on the distributions we're talking

about almost work right out of the box for simple deployments. If you find yourself following a big complicated tutorial, the

tutorial is doing it wrong (or, at least, wrong for you at this time).

Handwaving, because there's no way I can cover all of the details of this.

(36)

The Promised Land

(Or, the point in our story in which I show you how to do all of this, and a whole lot more, with a single command.)

(37)
(38)
(39)

The command

Go here: http://www.virtualmin.com/download

Read the page. Download the Virtualmin GPL install script.

Run it like this:

(40)

Figure

Updating...

References

Updating...

Related subjects :