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

CGI (Common Gataway Interface)

CGI is a program that runs on the server machine when some user request is recieved.

  • How to configure the Apache to permit CGI http://httpd.apache.org/docs/2.2/en/howto/cgi.html
  • httpd.conf
    <Directory /home/*/public_html/cgi>
      Options +ExecCGI
      AddHandler cgi-script .cgi
    </Directory>
    
    • This configuration enables CGI programs (whose file extension is .cgi) within the /home/*/public_html/cgi directories to run.

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 'conent-type: text/html'
    echo 
    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/
      

  • 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 'content-type: text/html'
    echo 
    echo Hello World! $1
    
    • This code is very dangerous since it can run arbitrary codes passed as an argument to this CGI program.

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
      

  • Anyway, my CGI program does not work!
    • consider the settings of SELinux, which protects unauthorized accesses.

  • Recent Appach implementation displays 'Internal Server Error' when the content-header is not generated from your CGI script.

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