Even though apacheis also called to execute php using php-cgi.exe, why must apache be installed?

Source: Internet
Author: User
Tags php web server
Even though apacheis also called to execute php using php-cgi.exe, why must apache be installed? Why should I directly send the request to php-cgi.exe and go through apache? Even though apacheis also called to execute php using php-cgi.exe, why must apache be installed?
Why should I directly send the request to php-cgi.exe and go through apache?

Reply content:

Even though apacheis also called to execute php using php-cgi.exe, why must apache be installed?
Why should I directly send the request to php-cgi.exe and go through apache?

The timing diagram of a php address request is like this. php-cgi is a fastcgi communication Guardian program with apache and cannot be removed.
Of course, apache also has a way to call php without fastcgi, that is, apache module mode:

LoadModule php5_module /usr/lib/apache/libphp5.so

At this time, the Sequence Graph does not contain the php-cgi entity. apache directly calls php.

Apache implements the http protocol and related content, while php can only be used as an extension of it.
If you use php to implement http-related content, you do not need apache.

You can also:

php -S 0.0.0.0:8080 -t /www

Directly use the built-in php web server without installing apache.

PHP is integrated into the Apache process (httpd) for running as a module (libphp5.so) of Apache. This mod_php running mode is the most common. At this time, PHP running has nothing to do with php-cgi. the configuration of mod_php is as follows:

LoadModule php5_module modules/libphp5.soAddHandler application/x-httpd-php .php

You can configure extra/httpd-mpm.conf to control the number of Apache processes.

If you use mod_fcgid in Apache to run PHP, you need to use php-cgi. Apache manages php-cgi as a FastCGI Process Manager and configures it in httpd. conf:

# Load the mod_fcgid module (cannot be used together with php5_module) LoadModule fcgid_module modules/mod_fcgid.soAddHandler fcgid-script. php # php-cgi process count FcgidMaxProcesses 5 # specify php-cgi to process php requests FcgidWrapper/png/php/5.4.39cnt/bin/php-cgi. php # Add Options + ExecCGI to the Directory where php-cgi needs to be executed, for example:
  
   
Options + ExecCGI
  

In addition, there is a very common combination in Linux, that is, Nginx is used with php-fpm, where php-fpm has nothing to do with php-cgi, php-fpm itself is integrated with the PHP interpreter. php-fpm has its own process manager that only processes PHP requests forwarded by Nginx and returns the results. It is loosely coupled with Nginx.

Php-cgi.exe is not an http server and it accepts a different protocol than apache. To remove apache, you must use php to implement the http protocol, which may cause many useless code bugs.

In addition to the dynamic content generated by php, a website consists of other parts, such as static content. If php delivers these static content, the efficiency is naturally less efficient than the web server specially optimized for this kind of work.

In addition to static content, there are many things related to access logs, url rewrite, and http. If there is no web server in the world, we can develop websites in whatever language we use, you must write these items once. Separating these items into web servers saves a lot of repetitive work, and you can directly deploy them to web servers regardless of the language used by the backend. In fact, it is the same reason that we encapsulate some specific logic in the design of the system.

If you don't talk about anything else, you can do it if the backend is directly exposed to the public network ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.