Unit- V Chap

Download Report

Transcript Unit- V Chap

Created by : Ashish Shah, J. M. Patel College
Enabling CGI & PHP With Apache
UNIT- V
CHAP - II
1
Created by : Ashish Shah, J. M. Patel
College
WHAT IS CGI
CGI, the Common Gateway Interface, is a
protocol that defines a standard method
enabling Web servers to communicate with
external programs. These programs are known
as CGI scripts, CGI programs, or, more
colloquially, just CGIs.
 CGI scripts are commonly used to create or
update Web pages or parts of Web pages
dynamically.
 CGI is far more flexible than SSI and provides
additional functionality that SSI cannot.

2
Created by : Ashish Shah, J. M. Patel
College
HOW CGI CAN BE ENABLED WITH APACHE




The ScriptAlias directive associates a directory name
with a file system path, which means that Apache
treats every file in that directory as a script.
If not present, add the following directive to
httpd.conf:
ScriptAlias /cgi-bin/ “/var/www/cgi-bin”.
This directive tells Apache that any URL beginning
with /cgi-bin/ should be served from /var/www/cgibin.
Apache reads and executes the script /var/www
/cgi-bin/cgiscript.pl.
3
Created by : Ashish Shah, J. M. Patel
College

If necessary, modify the configuration file to
include the ScriptAlias directive shown, and
restart Apache as explained previously.
4
Created by : Ashish Shah, J. M. Patel
College
TESTING CGI SCRIPT
Save this script as cgitest.pl, make it executable
(chmod 755 cgitest.pl), and then put it in
/var/www/cgi-bin. Finally, open the URL
http://localhost/cgi-bin/cgitest.pl.
 If you see similar output, your server’s CGI
configuration works. If you enable CGI execution
for other directories, make sure to test those
configuration options as well before putting the
server into production.

5
Created by : Ashish Shah, J. M. Patel
College
OUTPUT OF CGI TEST PAGE
6
Created by : Ashish Shah, J. M. Patel
College
ENABLING PHP IN APACHE
PHP is an extremely popular and capable HTML
scripting language.
 As shipped in Fedora Core and RHEL, PHP is
enabled and ready to run, simply presents a
short PHP script you can use to make sure that
PHP is working properly.
 Create the PHP script shown in Listing below,
and save it as
var/www/html/tests/phptest.php.

7
<html>
<head>
<title>PHP Test Page</title>
<link rel=”stylesheet” type=”text/css” href=”rhlnsa3.css”>
</head>
<body>
<h1>PHP Test Page</h1>
<div id=”content”>
<pre>
<?php
system(“ls -lh /var/www”);
?>
</pre>
</div> <!-- content -->
<?php include(“footer.html”); ?>
</body>
</html>
Created by : Ashish Shah, J. M. Patel
College
8

Created by : Ashish Shah, J. M. Patel
College
Open the document in your Web browser,
using the URL http:
//localhost/tests/phptest.shtml
9