Creating a Home Web Server

25
Creating a Home Web Server

description

Creating a Home Web Server. What is a Server?. Software program Runs continuously Lets people download files from your computer Can be any kind of file, but we’re mainly concerned with .html files. How a WAMP server gets PHP code to a client browser (Windows Apache MySQL PHP Web Server). - PowerPoint PPT Presentation

Transcript of Creating a Home Web Server

Page 1: Creating a Home Web Server

Creating a Home Web Server

Page 2: Creating a Home Web Server

What is a Server?

• Software program

• Runs continuously

• Lets people download files from your computer– Can be any kind of file, but we’re mainly

concerned with .html files.

Page 3: Creating a Home Web Server
Page 4: Creating a Home Web Server

Request a.php

Send back a.html

a.php

<?Echo “Hello”;?>

PHP Interpreter

Rendered PHPIn HTML format

How a WAMP server gets PHP code to a client browser(Windows Apache MySQL PHP Web Server)

Client Browser

Rendered PHPIn HTML format

<html><body>Hello</body></html>

My SQLDatabase

WAMP Server

Page 5: Creating a Home Web Server

Setting up a Home Web Server

• Download Apache version 2.2.15:– http://httpd.apache.org/download.cgi#apache22– “Win32 Binary without crypto (no mod_ssl)

(MSI Installer)”

Page 6: Creating a Home Web Server

Make Sure It Worked

• Find Apache HTTP Server in your programs menu and click ‘Start’!

• In a web browser, type the address http://localhost/

• See the victory message

Page 7: Creating a Home Web Server

Configuring Your Server

• Make a folder for your html files

• We’re going to change 3 lines in the file conf\httpd

• Open the file in Notepad

Page 8: Creating a Home Web Server

Comments/Documentation## This is the main Apache HTTP server configuration file. It contains the# configuration directives that give the server its instructions.# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.# In particular, see # <URL:http://httpd.apache.org/docs/2.2/mod/directives.html># for a discussion of each configuration directive.#

<IfModule log_config_module> # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule>

Page 9: Creating a Home Web Server

Editing the Config File1. Comment out old root directory, replace with yours

## DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.#DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"

# DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"DocumentRoot "C:/Users/Jacob/Documents/BIY”

Note the direction of the slashes!

Page 10: Creating a Home Web Server

Editing the Config File

2.## This should be changed to whatever you set DocumentRoot to.#<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">

# <Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"><Directory "C:/Users/Jacob/Documents/BIY">

Page 11: Creating a Home Web Server

Editing the Config File3.## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# Options FileInfo AuthConfig Limit# AllowOverride None

# AllowOverride None AllowOverride All

Page 12: Creating a Home Web Server

Using the Server

• Refresh the Apache server

• Put some files in your folder and go to http://localhost/ to see them

Page 13: Creating a Home Web Server

Using the Server

• Name a file index.html to make it the “homepage.”

• Then you can use hyperlinks to reach the other pages in the folder.

• While your server is running, other computers can access your server using your IP address (though you will probably have to work around your firewall, and this can be complicated)

Page 14: Creating a Home Web Server

Downloading and Using PHP

Page 15: Creating a Home Web Server

Download and Install PHP

• Download PHP from http://us3.php.net/get/php-5.2.13-win32-installer.msi/from/a/mirror

• When prompted for what server to setup for, choose Apache 2.2.x

• The installer will try to configure Apache for you, but it might not work (it didn’t for my computer).

Page 16: Creating a Home Web Server

Download and Install PHP

Page 17: Creating a Home Web Server

Installation Options• Don’t install every option! Some of them

will cause you pain.

• For now, leave out all the extensions but take everything else.

Page 18: Creating a Home Web Server

Configuring Apache AgainAdd the following lines to the end of our old friend, conf\httpd

LoadModule php5_module "C:/Progra~2/PHP/php5apache2_2.dll"AddHandler application/x-httpd-php .php

PHPIniDir "C:/Progra~2/PHP/”

In place of C:/Progra~2/PHP/, put the path of the folder which contains the file php5apache2_2.dll.

C:/Progra~2/PHP/ is the default for Windows 7. It will almost assuredly be different for Vista or XP (or for non-Microsoft OS’s).

Page 19: Creating a Home Web Server

Ready to Program in PHP!

• Restart your Apache server.• If Apache refuses to start, you may have mistyped

something, you may have forgotten to not install the extensions, or there may be some other problem. If you get stuck, feel free to call or e-mail Jacob.- Jacob Bredthauer [email protected] 402-680-5441

• Now let’s start doing some basic PHP tasks!

Page 20: Creating a Home Web Server

echoTry putting this simple file on your server:

<HTML><HEAD></HEAD><BODY> <?php echo "Web designers rule!"; ?></BODY></HTML>

From the user’s point of view, the echo’d statement appears to be part of the html code.

The echo command is analogous to “print” in Python or “System.out.println” in Java.

Page 21: Creating a Home Web Server

echoEcho statements can contain HTML tags.

<HTML><HEAD></HEAD><BODY><?phpecho “<p class=‘myclass’><a href=‘www.build-it-yourself.com’>Web designers</a> rule!</p>”;?></BODY></HTML>

Page 22: Creating a Home Web Server

VariablesPHP can store variables and use them in math operations or other functions.

<?php$n = 2;$nsquared = $n*$n;?>

<HTML><HEAD></HEAD><BODY><?phpecho “$n squared equals $nsquared.";?></BODY></HTML>

Page 23: Creating a Home Web Server

Things to Remember About PHP

• If a file contains any PHP code, save it with the extension .php (instead of .html).

• End every PHP statement with a semicolon.

• Variables always begin with $.

Page 24: Creating a Home Web Server

Suggestions for Next Week

• Install Apache and PHP.

• Make a simple website that uses PHP on your server.

Page 25: Creating a Home Web Server

Helpful Links

• Apache download: http://httpd.apache.org/download.cgi#apache22

• Apache tutorial: http://lifehacker.com/124212/geek-to-live--how-to-set-up-a-personal-home-web-server

• PHP download: http://us3.php.net/get/php-5.2.13-win32-installer.msi/from/a/mirror

• PHP install manual: http://www.php.net/manual/en/install.windows.installer.msi.php

• PHP configuring Apache: http://www.php.net/manual/en/install.windows.apache2.php