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 PresentationTRANSCRIPT
![Page 1: Creating a Home Web Server](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/1.jpg)
Creating a Home Web Server
![Page 2: Creating a Home Web Server](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/2.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/3.jpg)
![Page 4: Creating a Home Web Server](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/4.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/5.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/6.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/7.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/8.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/9.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/10.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/11.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/12.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/13.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/14.jpg)
Downloading and Using PHP
![Page 15: Creating a Home Web Server](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/15.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/16.jpg)
Download and Install PHP
![Page 17: Creating a Home Web Server](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/17.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/18.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/19.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/20.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/21.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/22.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/23.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/24.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022062309/5681377c550346895d9f1608/html5/thumbnails/25.jpg)
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