| Version 15 (modified by leo, 6 years ago) |
|---|
An Introduction to the Web Application Development
Installing Apache(HTTPD) Web Server
> yum install httpd
Configuration Files of Apache
- /etc/httpd/conf/httpd.conf
- /etc/httpd/conf.d/*.conf
If you cannot find these configuration files in the above locations, try:
> rpm -ql httpd
This command shows all installed files of the Apache(httpd).
How to set up the apache server
- see the manual (急がば回れ)
CGI (Common Gataway Interface)
CGI is a program that runs on the server machine when some user request is recieved.
- httpd.conf
<Directory /home/*/public_html/cgi> Options ExecCGI </Directory>
- This configuration enables CGI programs within the /home/*/public_html/cgi directories to run.
- In general, the use of .htaccess file to enable CGI programs is not recommended. See the details in http://httpd.apache.org/docs/2.2/howto/htaccess.html
Reflect the modifications to the configuration files to the Apache
# etc/init.d/httpd restart
The First CGI Program
- $HOME/public_html/cgi/hello.sh
#!/bin/sh echo Hello World!
- access to the URL: http://(your server's IP address or localhost)/~(your_login_name)/cgi/hello.sh
A Very Brief Introduction To Shell Scripts
- Shell scripts support you to reduce redundant work.
- An example that retrieves all web pages listed in mybookmark.txt
- mybookmark.txt
http://www.cnnsi.com/ http://redsox.com/ http://major.jp/
> for url in $(cat mybookmark.txt); do wget $url; done;
This command-line script is equivalent to write:> wget http://www.cnnsi.com/ > wget http://redsox.com/ > wget http://major.jp/
- mybookmark.txt
- A good and reasonably short tutorial I found on the web: http://www.hsrl.rutgers.edu/ug/shell_help.html
- You should spend time to read this tutorial (or other docuemnts you want) until you learn how to write shell scripts, or you will lose much more time.
Set environment variables using shell scripts
.bashrc (which is a (shell script) file processed when a bash shell is launched)
export LANG=en_US export JAVA_HOME=/usr/java/j2sdk1.5; export PATH=$JAVA_HOME/bin:$PATH
Security Considerations
- $HOME/public_html/cgi/doWhateverMaliciousThingsYouCanImagine.sh
#!/bin/sh echo Hello World! $1
- This code is very dangerous since it can run arbitrary codes passed as an argument to this CGI program.
- search the Google for many security issues related CGI scripts
- I found this: http://www.w3.org/Security/Faq/wwwsf4.html
Trouble Shooting
- Access to my CGI program is forbidden.
- check the file permission of your program:
> ls -l (yourCGIProgram) -rw-r--r-- 1 leo users 18703 Sep 14 2005 hello.sh
> chmod o+x hello.sh
or if the apache server runs as a group named 'apache'> chgrp apache hello.sh > chmod g+x hello.sh
- check the file permission of your program:
Assignments
Task 1
Write a CGI program that displays an HTML page, the content of which shows current date and time.
- The resulting html source looks like as follows:
<html> <head><title>My Clock</title></head> <body> <p>Wed May 16 00:45:41 JST 2007</p> </body> </html>
- To display an HTML page, the CGI program must output the following HTTP protocol message:
Content-Type: text/html
Task 2
Install the PukiWiki? program (http://pukiwiki.sourceforge.jp/), then confirm its wiki pages can be modified.
Advanced Web Development Resources
- Java Servlet
- Ruby On Rails
- Google Web Toolkit


