简体   繁体   中英

How Apache communicate with PHP

I have started to develop an HTTP/1.0 web server under Java(not for commercial purpose, just for fun). Hope this will increase my confidence. Initially, I just wanted to include PHP support(only rest API). I have almost done the request parsing and now I have stuck on executing the request. That's why I would like to know how actually web server like Apache communicates with PHP. It would be appreciable if you please share your experience, knowledge in details regarding this.

Thanks in advance

it is good to know how things works, it will help you understand the deep aspect of development and servers.

In regards to your question, the APACHE knows that the files ends with .php must be sent to PHP interpreter to execute it and provide the results, check this anatomy of a request.

Step 1 The user enters https://stackoverflow.com into their browser and taps/hits 'enter'.

Step 2 The browser sends the page request over the Internet to the web server.

Step 3 The web server gets the request and analyzes the request information. Apache realizes that we didn't specify a file, so it looks for a directory index and finds index.php .

Step 4 Since Apache knows to send files that end with the .php file extension to the PHP interpreter, it asks PHP to execute the file. This knowledge of Apache is specified in the httpd.conf file, it tells Apache exactly what to do when it find the .php files.

Step 5 PHP Interpreter is executing the code contained in the index.php file from the request. During this step, PHP may interact with databases, the file system or make external API calls, amongst other things.

Step 6 After PHP Interpreter has finished executing the index.php file, it sends the output back to Apache. Note that the output will be HTML.

Step 7 Apache receives the output from PHP and sends it back over the Internet to a user's web browser. This is called the response .

Step 8 The user's web browser receives the response from the server, and renders the web page on a computer or device.

Hope this will shed the light on where you should focus, please visit https://httpd.apache.org/docs/2.4/ and check what modules the Apache use to find the PHP interpreter, also note you will need to install PHP separately to achieve this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM