Saturday, March 15, 2014

How Apache and PHP works


-----
How Apache and PHP works

INTRODUCTION

PHP is a server-side scripting language widely used in web development. PHP is what turns your web site from a static fileserver into a dynamic web application.
By default, Apache only knows how to serve static HTML pages to the client. You can write as many HTML pages as you want, which is fine for basic web sites. But if you want to have users post to a forum, or process credit card transactions, or make your own online calendar, a server-side language like PHP is what you need.
Read Reference 1 for further information.
Read Reference 6 on location of XAMPP configuration files.

STEPS

1) HTTPD

1.1) Apache server is operated by a program known as httpd (Short for HTTP daemon). It is a software program that runs in the background of a Web server and waits for incoming server requests. Thedaemon answers the requests automatically and serves the hypertext and multimedia documents over the Internet using HTTP.
1.2) In order to run PHP scripts, Apache httpd requires two files; PHP Processor (php.exe, php-cgi.exe or php5apache2.dll) and PHP Configuration (php.ini).

2) PHP Processor.

Run phpDesigner. Open c:\xampp15\apache\conf\httpd.conf
2.1) Press Ctrl+F, type php in the Find box and press Enter. Press F3 repeatedly until you find the lines below.
Line no. 249 creates an alias “/php/” that points to the folder “c:/xampp15/php/”.
Line no. 250 defines action for resource type “application/x-httpd-php” is “/php/php-cgi.exe”.
However, these two lines are commented, which means that they are not active. Instead this version of Apache runs PHP as an Apache Module.
Line no. 251 tells Apache to load php5apache2.dll module.
Read Reference No.2 for further info on running PHP as Apache Module and as CGI.
Line no. 252 and 253 defines the valid application resource extension format that will be passed to PHP for processing ie .phps, .php, .php5 .php4 .phtml
2.2) Besides defining method for running PHP and valid PHP extensions, httpd also defines other items that have security implications to PHP such as alias and directory access.

3) PHP Configuration.

Before you start, you may try running file search for php.ini files in c:\xampp15
There are a number of php.ini files. So which one is actually used by Apache?
3.1) Browse http://localhost/xampp/  and click phpinfo()
3.2) Find the item “Configuration File (php.ini) Path” and look at the value, e.g., C:\xampp15\apache\bin\php.ini .
Notice as well that the item “Server API” value is “Apache 2.0 Handler” means that Apache is running PHP as a module (refer Step 2.1 above). Otherwise the value would be as follows:
Knowing this value is important for determining anti-hacker/security suite (read Reference 5)  
3.3) Run phpDesigner. Open c:\xampp15\apache\bin\php.ini

REFERENCES:



No comments:

Post a Comment