Web hosting provider - 534Part IIIAdvanced Features and TechniquesWhen PHP is used
Monday, April 30th, 2007534Part IIIAdvanced Features and TechniquesWhen PHP is used as a Web server module, there is little risk of source code being releasedby the Web server, as any file with the proper extension is parsed by the PHP module. If PHPis installed as a CGI program, however, things are not so simple. If you cannot run PHP as a server module, the next most secure setup is to run it as an inter- preter for CGI scripts, just as you would Perl or Python. Place all your PHP programs in the cgi-bindirectory for your server or your account andarrange for the PHP interpreter to be invoked when they are executed. On Unix, this is doneby adding a line similar to the following as the first line of every script: #! /usr/local/bin/phpTo use this setup, you must compile PHP with the –enable-discard-pathconfigurationoption. This setup has the disadvantage that the URLs for most of your pages contain /cgi-bin/. The next most secure setup is a bit more complicated and is actually counter to the recom- mendations of CERT, a respected authority on computer security: We place the PHP inter- preter itself in the cgi-bindirectory. It is usually inadvisable to put an interpreter in thecgi-bindirectory, because the rules for invoking CGI programs would allow any file on theserver to be parsed as a program. PHP is written to operate safely from the cgi-bindirectory, however, if configured correctly. If you intend to use this setup, first carefully read the security and configuration sections ofthe PHP manual, as they may contain important information not available as this book wentto press. This setup relies upon the Web server to redirect URLs of the form: http://your.server/program.phpto URLs of the form: http://your.server/cgi-bin/php/program.phpThe precise directives that will cause your Web server to do this vary. For Apache they are: Action php-script /cgi-bin/phpAddType php-script .phpIf you are using Apache, be sure to compile PHP with the –enable-force-cgi-redirectconfiguration option. This option utilizes a feature specific to Apache to prevent PHP fromexecuting when invoked by URLs of the second form. Your setup is complete. If you are using any other server software, you must compile PHP with the –disable- force-cgi-redirectconfiguration option. PHP cannot distinguish the two types of URLsand serves a document of either type. This allows a visitor to view files without regard forWeb-server based access restrictions. Assume, for example, that the URL www.secrets.com/ top/secret/hush.phphas access restrictions placed on it. A cracker could use the URLwww.secrets.com/cgi-bin/php/top/secret/hush.phpto read the file anyway. In this case, the Web server is giving PHP the path name /top/secret/hush.php. PHP deter- mines the location of the program file by prepending the configuration value doc_rootto thegiven path name. By default, this value is the same as the Web server s document root (thedirectory corresponding to www.secrets.com/). Setting doc_rootto another directory willlimit PHP to programs in that directory and its subdirectories instead of the entire collectionof Web-server documents. Any visitor may access any of the PHP programs by the methodjust described, however, without regard for Web-server-based access controls. Be careful!
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services