running-php-via-web
running php on rucs (not using a web server)
Reminder:
We previously saw
a review of essential linux/unix commands,
how to connect to rucs,
and
how to run php programs from the command line.
You should be familiar with those, before proceding.
Recall that when a web-server gets a request, it decides how to respond.
For php.radford.edu, some of the configuration rules:
For requests of the form ~userName/somePath/someFile.php,
it looks on
userName's H-drive,
for the file
dynamic_php/somePath/someFile.php,
and it runs that .php program.
The program's printed output becomes the response sent back to the browser.
The .php file must be readable by everybody (since it's being served up to the www),
and it must be non-writable by group,other
(as a security measure: other users can't implant malware into your php program).
Apache runs php with the privileges of the file's owner (su).
php.radford.edu only accepts secure (https) connections.
Place the .php file inside dynamic_php/ on your H: drive.
You may have to create that directory if it doesn't already exist, using mkdir.
Make sure the file is world-readable, but not group-writable:
chmod o+r g-w blend.php.
(This makes it other-readable, non-group-writable, without changing any other permissions.
You could instead use go-w ugo+r to additionally ensure that it
is non-group-writable, and readable by user,group,other;
however those are usually already part of the standard default.)
Make sure all the folders enclosing your file
are other-executable-and-executable but not group-writable:
chmod o+rx g-w . .., chmod o+x . ...
One crude way to get things to work:
Set every file to be rwx r-x r-x
(whether or not it's a folder, .html file, or .php file):
Recursively change permissions:
chmod -R u=rwx go=rx ~/dynamic_php/
or (using the octal representation of the user/group/other permissions, 111 101 101) just
chmod -R 755 ~/dynamic_php/
If the php interpreter hits an error, the program terminates with no output
(so nothing is sent back to the client —
status code 500: internal server error)!
Note that this often happens when php is simply first reading/parsing your file,
(for example, a missing semicolon).
So even if you have error_reporting(E_ALL); in the first line of your program,
you'll still get back an empty, 500:internal-server-error response.
To fix this: run you php from the command-line, where syntax errors will generate a message
and a line-number!
Here is a quick check-list of common problems, if you try running your program via the web but
get an error:
Error 404 (Not Found):
Recall from quizzes:
Given the URL
http://php.radford.edu/~someUser/someDir/someFile.php,
the web-servers php.radford.edu will look for someUser's H: drive,
and within that look for dynamic_php/someDir/someFile.php.
(Remember to (a) put someDir/ inside your ~/dynamic_php/,
and (b) don't include “dynamic_php/” in your URL.)
Error 403 (Forbidden):
Make sure the permissions are correct on (a) the file itself, and
(b) its enclosing folder, and (c) the next-higher enclosing folder, (d) …
(y) the next-heigher-yet enclosing folder,
(z) the enclosing ~/dynamic_php.
For example, check:
ls -ld ~/dynamic_php/itec325/hw00/someFile.php
ls -ld ~/dynamic_php/itec325/hw00/
ls -ld ~/dynamic_php/itec325/
ls -ld ~/dynamic_php/
and make sure that each of the files is readable/executable by others,
and not writable by group/others (e.g.rwxr-xr-x).
Error 500 (Server Error):
This is almost certainly due to your php program not being a valid PHP program
(perhaps it's missing a semicolon somewhere).
Solve this by running your program from the command-line (not via the web at all),
and seeing what the error-message is.