October 9 - ndgriffeth/Class-Notes-and-Lectures GitHub Wiki

Project

Recommendation: TextWrangler for Mac OS X

PHP tutorial on youtube: http://www.youtube.com/watch?v=iCUV3iv9xOs

Assignment Comments

Diagnosing Errors -- Useful Log Files

Additional information on log files: http://httpd.apache.org/docs/2.2/logs.html

There are two important kinds of logs, the error log and the access log.

The access log.

The access log contains an entry for each request sent to the server:
192.168.1.130 - frank [08/Oct/2013:11:25:13 -0400] "GET /~nancyg/Examples/testvariable1.php HTTP/1.1" 200 103

The format of entries is configurable. The above uses the "common" configuration. Explanation:

192.168.1.130: the IP address of the client that made the request to the server  
-            : some identity information about the client, normally not checked 
frank        : the userid as determined by http authentication.  
               If the document is not password-protected, this will be "-".  
[08/Oct/2013:11:25:13 -0400]
             : date and time.  -0400 is time zone.  
"GET /~nancyg/Examples/testvariable1.php HTTP/1.1"
             : request line from the client, given in double quotes
             : method, resource requested, protocol version  
200          : Status code.  Successful responses start with 2; redirections start with 3; errors caused by the client start with 4; errors caused by the server start with 5.  
-            : The size of the object being sent to the client (103 bytes).  If "-", nothing was sent. 

The error log.

The error log contains an entry for each error:
[Tue Oct 08 11:25:13 2013] [error] [client ::1] PHP Notice: Undefined variable: var in /Users/nancyg/Sites/Examples/testvariable1.php on line 6

The error log is relatively free-form and descriptive. Note, it has a date, a message type (error), some client identifying information, and the PHP error message.

How to find the logs

On Mac OS X:

  • /var/log/apache2/access_log
  • /var/log/apache2/error_log

On Ubuntu

  • /var/www/apache2/access.log
  • /var/www/apache2/error.log

On Windows

  • $_SERVER['DOCUMENT_ROOT']/../log/access.log
  • $_SERVER['DOCUMENT_ROOT']/../log/error.log

These errors can be shown on the Web page if the PHP option display_errors is set to On in the php.ini file. The php.ini file can be in various places:

On Mac OS X: /etc/php.ini
On Ubuntu: /etc/php5/apache2/php.ini
On Windows: In the php directory. Depends on where you installed php.

Exercise: Access the Web server on a neighbor's computer and look at the resulting entries in their error and access logs. You should try it with a page that is there and one that is not.

Changing file permissions on Mac OS X

http://osxdaily.com/2011/02/21/change-file-permissions-mac/

It's similar but not identical on Ubuntu: right-click (or command-click, if using Virtual Box on a Mac) on the file or folder and select "Properties". Now, set folder and file permissions from the various drop-down boxes.

Looking at Apache and PHP configuration

More on Apache configuration files: http://httpd.apache.org/docs/2.2/configuring.html

Finding and editing configuration files

On a Unix system, all configuration files are in /etc For Apache 2.2, go to /etc/apache2

Getting to the files is simple on Ubuntu, either using the command line or using the Finder, and easy with command line on a Mac. However, you have to play a trick to use the Finder for accessing these files. Here's how:

  • Open the Finder.
  • Use the Go menu: Go>Go to folder (shift-ctl-G), then type the path to the directory. The finder will then display the directory.
  • You can now right-click on a file to open it with the program of your choice.

Important statements in the configuration files

Configuration files contain extensive comments: see this example.

ServerRoot: Determines location of document root (default depends on the operating system)

Listen: Determines port on which apache listens (default 80)

LoadModule: dynamically loaded modules (php is not loaded by default, you have to delete the "#" to get it loaded).

User: the username of the user for the Web server

Group: the groupname of the user for the Web server

ServerAdmin: the email address of the server administrator

ServerName: the name and port that identifies the server

DocumentRoot: the fully-qualified pathname of the document root

ErrorLog: the fully-qualified path to the error log

LogFormat: the format of a line in the log

UserDir: the name of the directory in the user's space
The module userdir_module is required for this (see LoadModule)

Review Questions.

  1. What are the two kinds of logs that Apache writes? What does each contain?
⚠️ **GitHub.com Fallback** ⚠️