Thursday, March 24, 2011

Run your own unix web server part1

Setting up and running a Unix web server is surprisingly easy. Recently, on del.icio.us, I ran across the article Become Your Own Web Host in 75 Steps. Without too much explanation, the article describes how to install FreeBSD, MySQL, PHP, and Apache. Hopefully the following series will expand on that article and go a little deeper.

We will be installing:
  • FreeBSD (STABLE)
  • MySQL
  • Apache
  • PHP
  • and some other apps helpful to webmasters
Before we start, you'll need
  1. 1 blank CD
  2. A CD burner
  3. A computer with an ethernet card
  4. An Internet connection with a static IP address

Download FreeBSD


Your new webserver can be any old, cheap, Intel-based box, as FreeBSD will run on any old piece of crap.
  1. First, make sure your computer is compatible
    • Go to the FreeBSD Releases page
    • Check Hardware Notes for the Stable Release
    • Make sure your hardware is compatible with that release. I can almost guarantee that it is...
  2. Download FreeBSD
    • Go to the FreeBSD home page
    • Follow instructions for downloading the production/stable release
    • Download just the disc1.iso ISO image
  3. Burn the iso to your blank CD

Boot up Install CD


Now you should have:
  • 1 FreeBSD ISO CD
  • 1 computer (with a network card) ready to be transformed into a web server
Let me warn you that FreeBSD's installer is more old school than my VHS copy of Wild Style. But like Wild Style, it never gets old.

Installer Notes:
  • Use the arrow keys to move
  • Use space to select
  • Use enter to execute/select
  • Don't use the number pad; stick to the regular number keys
...Ok, let's go:
  1. Boot up
    Put your freshly burned CD into the soon-to-be webserver and turn it on. If all goes well you'll see the FreeBSD daemon asking you what you want to do
  2. Select the default option: Boot FreeBSD
  3. Use the arrows to select Standard - Begin Standard Installation, then hit Enter

The FreeBSD Installer


  1. Select Standard, hit Enter
  2. Use arrow keys to delete all current partitions: D deletes current partition; A uses entire partition; Q when you're done
  3. Boot Manager Select Boot Mgr, hit enter
  4. Disk Label Editor: Create disk partitions: Type C to create a new partition. Create custom partitions, something like below. Create the partitions in this order:
    2GB FS Mount Point: /
    1GB SWAP
    1GB FS Mount Point: /tmp
    1GB FS Mount Point: /var
    10GB FS Mount Point: /usr
    [all remaining] FS Mount Point: /home

    The 2nd partition (SWAP) should be 2x the amount of RAM installed. Partitions /, /tmp, and /var can stay rather small (use the defaults above) no matter how big your HD is.

    Type Q to finish
  5. Select Distribution Choose All
  6. Ports Collection Yes you want the ports skeleton (you'll go back to the Select Distribution screen. Scroll up, select Exit
  7. Installer Source Select CD/DVD
  8. Last Chance Hell, yeah. Delete everything, reformat the HD, give me some BSDLove
FreeBSD creates the filesystems that you named in the Disk Label Editor, and begins installing stuff. During the installation, you can see what's going on in a number of different views:
ALT-F1 - default GUI view
ALT-F2 - verbose installation log
ALT-F4 - emergency interactive shell
After extracting the source, and installing the source, you'll get to a screen that says:

Congratulations


Hit OK and move on...

Configuration


  1. would you like to configure any ethernet or SLIP/PPP network devices? Yes
  2. Select Your Network Card Select the first option unless you're sure your network card is one of the other options
  3. try IPV6? No
  4. try DHCP? No
  5. Network Info:
    Host [servername] If you want your server to be "foo.example.com", enter "foo" here
    Domain example.com
    enter the rest of your net info, click OK
  6. function as a network gateway? No
  7. inetd and network services that it provides? No
  8. enable SSH? Yes
  9. anonymous FTP? No
  10. NFS server? No
  11. NFS client? No
  12. customize system console settings? Yes
    I just select SAVER and select a really retro screen saver...like snake...
  13. Set this machine's timezones now? Yes
  14. Linux binary compatibility? Yes - this should let you run compiled linux binaries through FreeBSD's emulator.
  15. Does this system have a PS/2, serial, or bus mouse? No - mice are for wimps.
  16. FreeBSD Package Collection - Browse the collection now? No - we'll add ports later on
  17. Add any initial user accounts? Yes
    Select User; hit Enter
    • Login ID: web
    • UID: [default]
    • Group: [leave blank]
    • Password: *******
    • Full Name: Web Master
    • Member Groups: wheel
    • Home Directory: /home/web
    • Login Shell: /bin/csh (I like csh better than the default, sh)
  18. Set Root's Password
  19. Visit the general configuration menu for a chance to set any last options? No
  20. Use the right arrow to select [Exit Install]
    Hit Enter
  21. Are you sure you want to exit? Hell, fricken' yes, I'm sure
Your system will restart. Remove the install CD, and behold your new FreeBSD webserver

First Startup


You'll see a verbose startup messages page across the screen. The first startup, you'll eventually be asked to create an SSH key. To do this, just type a screenful (maybe 10 lines) of random junk then hit enter.

Your system will finish booting up and eventually prompt you with:

FreeBSD/i386 (foo.example.com) (ttyv0)
login: []

Login


Log in as web and the password you made, and start familiarizing yourself with some unix commands:

Next Steps

Now you have a FreeBSD web server connected to the internet. SSH is enabled, but not FTP. More importantly, to serve web pages, you'll need to install some additional software.

In the next lesson, we'll install:
  • PHP
  • MySQL
  • Apache
  • ...and more.

No comments:

Post a Comment