Since Apache is also the PHP parser php-cgi.exe to execute PHP, why must install Apache it?

Source: Internet
Author: User
Since Apache is also the PHP parser php-cgi.exe to execute PHP, why must install Apache it?
Why not give the request directly to Php-cgi.exe, but also to go through Apache around a bit?

Reply content:

Since Apache is also the PHP parser php-cgi.exe to execute PHP, why must install Apache it?
Why not give the request directly to Php-cgi.exe, but also to go through Apache around a bit?

The sequence diagram of a PHP address request is such that php-cgi is a bailiffs program that fastcgi communication with Apache and cannot be removed.
Of course, Apache also has a way to invoke PHP without fastcgi, that is, the Apache module:

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

There is no php-cgi this entity on the time series diagram, and Apache calls PHP directly.

Apache implements the HTTP protocol and related content, and PHP can only be used as an extension of it.
If you use PHP to implement HTTP protocol-related content, you can also eliminate the need for Apache.

Of course you can do the same:

php -S 0.0.0.0:8080 -t /www

Use PHP's built-in Web server directly, without having to install Apache.

PHP as a module of Apache (libphp5.so) integrated into the Apache process (httpd) run, this mod_php run mode is the most common, then PHP operation and php-cgi have nothing to do. The configuration of mod_php is this:

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

Extra/httpd-mpm.conf can be configured to control the number of Apache processes.

If you run PHP in Apache in mod_fcgid mode, you need to use PHP-CGI, when Apache has a FASTCGI process manager to manage php-cgi, in httpd.conf configuration:

#载入mod_fcgid模块(不能和php5_module同时使用)LoadModule fcgid_module modules/mod_fcgid.soAddHandler fcgid-script .php#php-cgi的进程数量FcgidMaxProcesses 5#指定php-cgi来处理php请求FcgidWrapper /png/php/5.4.39NTS/bin/php-cgi .php#在需要使用php-cgi来执行PHP的Directory加上Options +ExecCGI,比如:
  
   
    
       Options +ExecCGI
  
   

In addition to Linux also has a very common combination, is nginx with PHP-FPM use, wherein PHP-FPM with php-cgi no relationship, PHP-FPM itself integrates the PHP interpreter, PHP-FPM has its own process manager, Only handle the PHP request sent by Nginx and return, and the nginx is loosely coupled.

Php-cgi.exe is not an HTTP server, it accepts protocols that are completely different from Apache. If you need to remove Apache, you have to implement the HTTP protocol with PHP, which can lead to a lot of useless code and possibly bugs.

The composition of a Web site, in addition to the dynamic content generated by PHP, there are other parts, such as static content, if the static content is issued by PHP, the efficiency is not as efficient as specifically for this work optimized Web server.

In addition to static content, there are a lot of things related to logging access logs, URL rewrite, HTTP protocols, and assuming there is no such thing as Web server in the world, we must write these things out no matter what language we use to develop our website. By making these things stand out as a Web server, you save a lot of repetitive work, and you can enjoy these conveniences directly from deploying to Web server, regardless of the backend use of any language. This is actually the same as when we were designing the system to encapsulate some logic specifically.

The other does not say, the back end directly exposed to the public network you really dare to do it.

  • 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.