When developing a PHP application for Web, the typical approach is to embed PHP code into one or more standard HTML documents using special “tags”, or delimiters.Here’s an example:
<html> <head></head> <body> <div> <?php echo "Welcome to PHPGurukul"; ?> </div> </body> </html>When such an HTML documents is requested by user, a PHP aware Web server can recognize and execute the PHP code blocks and interpolate the resulting output into the HTML documents before returning it to the requesting user. The result: a Web page or application that almost seems alive, responding intelligently to user actions by virtue of PHP program logic embedded within it. Fig 1-1 illustrates the process, showing the four elements of the LAMP framework, described later in this section Here’s what’s happening in fig1-1:
- Joe pops open his Web browser at home and types in the URL to a Web site. After looking up domain, Joe’s browser(the client) sends an HTTP request to the corresponding server IP address.
- The Web server handling HTTP request for the domain receives the request and notes that URL end with a .php suffix. Because the server is programmed to automatically redirect all such requests to the PHP layer, it simply invokes the PHP interpreter and passes it the contents of the named file.
- The PHP interpreter parses the file, executing the code in the special PHP tags. Within these tags, you can perform calculations, process user input, interact with a database, read and writes files… the list goes on! Once the script interpreter has completed executing the PHP instructions, it returns the result to the browser, clean up after itself, and goes back into hibernation.
- The results retuned by the interpreter are transmitted to Joe’s browser by the Web server.
- A base operating system(OS) and server environment(usually Linux).
- A Web server(usually Apache on Linux or IIS on Windows) to intercept HTTP requests and either serve them directly or pass them on to the PHP interpreter for execution.
- A PHP interpreter to parse and execute PHP code, and return the results to the Web server.
- A database engine(such as MySQL) that hold application data, accepts connections from the PHP layer, and modifies or retrieves data from database.