home—lects—hws
D2L—breeze (snow day)
running-php-on-rucs
including files
running on rucs: file-protections
splitting into multiple files
We can take
blend.php (src),
and separate the code from the test-cases:
utils.php (src), and separately
utils-test.php (src).
The directive require-once is a run-time instruction
which just goes to the require'd file and
(effectively) splices it into the current file,
and continues evaluating line-by-line.
(So it's reminiscent of java's import, but
require-once significantly more simple-minded.
Beware trampling on identifiers, and it's poor practice to
have any dangling tags / code in the require'd file.)
This also lets us separate a program that uses blend
from the test cases:
some-web-page.php (src),
and
some-web-page.php (output).
(Can you figure how to fix the errant “\n” on that page?)
Linux Review
You'll want to be familiar with the main options for the following:
- ls -lF — list files in long format (show permissions/timestamp);
use -d to show directories themselves (rather than their contents).
- cd — change directory
- mkdir — make a directory
- chmod — change (permission) mode
- nano — edit a file
(also, vim and emacs are more powerful editors, but harder to learn).
Accessing rucs
Before we even revisit the code, let's talk about rucs
(“radford university computer science”; it's a machine managed by the ITEC department,
not the campus IT division):
How to log on to rucs, so you can run php on it:
First, start the VPN, if you are off campus.
Then, either
use ssh yourUserName@rucs.radford.edu
or
run putty.
Note that if rucs is down, then ruacad.radford.edu can also be used.
Be aware: rucs and ruacad are not the
campus web server, nor the php server!
You don't have accounts on those machines
(although your H: drive is shared by those machines).
In particular: the version of php you run from
rucs's command-line is slightly different than the
version run by php.radford.edu !-o
- How to run a php file:
Either php -a for a quick interactive session;
or
from the command-line, php filename.php.
- How to edit files on rucs:
Either log in to rucs and edit locally (vim, emacs, or pico);
or
from your PC, mount your H: drive and then edit locally
(using Notepad or JEdit or eclipse... but not Word).
Running a php file via the web
Recall that when a web-server gets a request, it decides how to respond.
For php.radford.edu, some of the configuration rules:
-
It only accepts secure (https) connections.
-
For requests of the form ~userName/somePath/someFile.php,
it looks for the H-drive file ~userName/dynamic_php/somePath/someFile.php,
and it runs that .php program.
The program's printed output becomes the response.
-
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).
Let's put our php program on the web!
-
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 g-w blend.php.
-
Make sure all the folders enclosing your file are other-executable but not group-writable:
chmod g-w . .., chmod o+x . ...
-
One crude way to get things to work:
Set every file to be rwxr-xr-x (whether or not it's a folder, .html file, or .php file):
Recursively change permissions:
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)!
To change this default, include at the top of your php program:
error_reporting(E_ALL|E_STRICT);
|
home—lects—hws
D2L—breeze (snow day)