Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 408/508: Programming for Linguists Lecture 16 October 16 th.

Similar presentations


Presentation on theme: "LING 408/508: Programming for Linguists Lecture 16 October 16 th."— Presentation transcript:

1 LING 408/508: Programming for Linguists Lecture 16 October 16 th

2 Last Time Puzzle left over: – use Javascript regex replace to delete all non-heads in:

3 Last Time Examples: all heads => [X] all labels => X

4 Last Time Examples: all non-heads => [X] crucially (?=\[) means [ is not part of the match, so next match can begin at the last [ (instead of one character past)

5 Last Time Examples: all non-heads have been deleted i.e. we have the frontier of the tree delete extra right brackets

6 Building a Webserver We'll use cgi-bin and bash scripts initially … Apache2 is the most common webserver software – unfortunately, configuration are different on OSX and Ubuntu

7 Common Gateway Interface (CGI) The glue between a webserver and programs that run on the computer (= server) hosting the webserver Normally, a webserver sends out (static) webpages in response to (URL) requests from a client (your web browser). Sometimes, we want the request to run a program (a script or binary) on the server that does some computation and generates some result to be displayed on the client (as a webpage). http://server/cgi-bin/program?parameter generated.html client server: webserver

8 Apache Webserver on OSX Webpage storage locations: –/Library/WebServer/Documents index.html.en It works! – ~/Sites(/Users/username/Sites) – index.html – http://localhost/~sandiway/ http://localhost/~sandiway/ cgi-bin: –/Library/WebServer/CGI-Executables – Example: http://localhost/cgi-bin/test.cgi permissions for.cgi should be readable and executable, e.g. chmod 755 test.cgi

9 Apache Webserver on Ubuntu Ubuntu: – sudo apt-get update – sudo apt-get install apache2 http://localhost/ DocumentRoot /var/www/html /var/www/html/index.html CGI binaries: /usr/lib/cgi-bin files must be made executable!

10 Apache Webserver on OSX Pre-installed on OSX To run cgi-bin files outside of the default /Library/WebServer/CGI-Executables we need to modify the Apache httpd configuration file: /private/etc/apache2/httpd.conf – Uncomment: AddHandler cgi-script.cgi Warning message: – "Could not reliably determine the server’s fully qualified domain name" – Solution: define in httpd.conf: ServerName localhost

11 Apache Webserver on OSX Apache webserver: – /usr/sbin/apachectl – sudo apachectl -k start|stop|restart Port number: – 80standard (httpd daemon listens on this port) Configuration file: – /private/etc/apache2/httpd.conf Log: – ErrorLog "/private/var/log/apache2/error_log"(see httpd.conf)

12 Apache2 on Ubuntu Apache webserver: – sudo service apache2 restart|stop|start – sudo apache2ctl -k start|stop|restart(apache2ctl is in /usr/sbin) Port number: – 80standard(httpd daemon listens on this port) Master configuration file: – /etc/apache2/httpd.conf Log: – ErrorLog /var/log/apache2/error_log Configuration files: – /etc/apache2/sites-enabled/000-default.conf – /etc/apache2/conf-enabled/serve-cgi-bin.conf

13 Apache2 on Ubuntu /etc/apache2/conf-enabled/serve-cgi-bin.conf

14 Apache2 on Ubuntu Debian-based (e.g. Ubuntu) Apache2: – sudo a2enmod cgi effect is permanent creates symbolic link from mod-enabled to mod-available – sudo service apache2 restart

15 Sending information: GET HTML form: – – First: – Last: – Information encoded using alphanumeric characters: why? URLs are restricted to alphanumeric characters only bash accesses the URL-encoded string via the environment variable QUERY_STRING program.cgi?first=Sandiway&last=Fong

16 Sending information: GET program.cgi: #!/bin/bash echo "Content-type: text/plain" echo #echo $QUERY_STRING origIFS=$IFS IFS='=&' set -- $QUERY_STRING IFS=$origIFS echo "1: 2: 3: 4: " In bash: IFS = internal field separator (for arguments) default: space newline tab set – String -- option: positional parameters are set after parsing String


Download ppt "LING 408/508: Programming for Linguists Lecture 16 October 16 th."

Similar presentations


Ads by Google