CPSC 343 Database Theory and Practice Fall 2020

HTML/PHP Local Quick Start

This document is intended to describe the local environment for working with HTML and PHP in CPSC 343. Refer to the PHP Quick Start for information on the PHP language, the PHP Web Quick Start for information on getting information about the web server environment, processing HTML forms, and working with sessions and cookies, or the PHP MySQL Quick Start for information on interacting with MySQL from PHP.


Contents


Setup

Your HTML and PHP files will need to be web-accessible so they can be run. A webserver has been set up for your use on the same host as the MySQL server (172.21.7.83); it can access files stored in a particular location on the Math/CS Linux filesystem. To set up this location:

You must use exactly the names indicated (and with the same case).


Naming and Viewing Your HTML and PHP Files

Files containing PHP code must have a filename ending with .php; files containing only HTML code must have a filename ending with .html (or .php, but there's no reason to make the PHP processor handle a file without any PHP).

All of the PHP and HTML files that you create should go within your www/cs450 directory (or a subdirectory of that directory) on the Linux filesystem. You can edit files on your own computer and transfer them with a file transfer program such as FileZilla (see the "SFTP" section in the Using Linux at HWS document for more information) or you can edit files directly on the Linux filesystem. For the latter, the two options are to use a commandline editor such as vim or emacs -nw or, if your computer supports X windows, you can run a GUI program such as atom, nedit, or emacs. See the "SSH" section in the Using Linux at HWS document for more information.

You can browse a listing of the files in your www/cs450 directory with the URL

  http://172.21.7.83/cs450s22/username

where username is replaced by your Linux username.

You can go directly to a file by giving its URL e.g. http://172.21.7.83/cs450s22/fprefect/datetime.php is the URL for a file called datetime.php in fprefect's www/cs450 directory, and http://172.21.7.83/cs450s22/fprefect/ex1/datetime.php would refer to a file called datetime.php in fprefect's www/cs450/ex1 directory.


Viewing the Quick Start Examples

The examples used in the other Quick Start documents are available for you to try out. The URL:

  http://172.21.7.83/cs450s22/quickstart

Viewing the PHP Error Log

Because the PHP is processed by the webserver, PHP syntax errors and other problems which prevent PHP from executing are logged on the server. Normally this messages go to the webserver's error log (which is not available to regular users), but to help your debugging, I have redirected PHP errors to a web-accessible file:

  http://172.21.7.83/cs450s22/php_errors.txt

All PHP errors are logged to this file, so it will contain much more than just your current error. However, the most recent additions are at the end and the error messages include the filename where the error occurred - use this to help you locate the relevant information. Don't forget to reload the page in order to see the most recent version of the log.

Note: to keep the file size from growing out of control, the log is periodically rotated. php_errors.txt.1, php_errors.txt.2, etc contain older versions.


Off-Campus Access

If you are not on the campus network, you will either need to run VPN (information) or use port forwarding (which requires ssh). For port forwarding, run the following on your local machine:

  ssh -CNL 9001:172.21.7.83:80 username@math.hws.edu

Replace username with your CS department username, and enter your CS department password when prompted for a password. This command takes traffic sent to port 9001 on your local machine, sends it over the ssh connection to math.hws.edu, and tells math.hws.edu to then forward it to port 80 (the webserver port) on 172.21.7.83. You can change 9001 to something else if you want - it's just a port that is probably not being used by something else. Now when you want to access a URL involving 172.21.7.83, replace it with localhost:9001 instead e.g.

  http://localhost:9001/cs450s22/quickstart/

Valid HTML 4.01!