Download presentation
Presentation is loading. Please wait.
1
Enabling CGI & PHP With Apache
Created by : Ashish Shah, J. M. Patel College Enabling CGI & PHP With Apache Unit- V Chap - II
2
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.
3
How CGI can be enabled with Apache
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/cgi-bin. Apache reads and executes the script /var/www /cgi-bin/cgiscript.pl.
4
If necessary, modify the configuration file to
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.
5
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 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.
6
Created by : Ashish Shah, J. M. Patel College
Output of CGI Test Page
7
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.
8
<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
9
Open the document in your Web browser, using the URL http:
Created by : Ashish Shah, J. M. Patel College Open the document in your Web browser, using the URL http: //localhost/tests/phptest.shtml
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.