Which PHP mode? Apache vs CGI vs fastcgi,apachefastcgi_php tutorial

Source: Internet
Author: User
Tags configuration settings cloud hosting drupal plesk

Which PHP mode? Apache vs CGI vs fastcgi,apachefastcgi


Which PHP mode? Apache vs CGI vs FastCGI

There is multiple ways to execute PHP scripts on a Web server. We ' re often asked about the difference between these modes and so here it is!
We offer the three more common PHP handlers across our Linux Cloud Hosting range:

    • Apache Module
    • Cgi
    • FastCGI

Each of these have its own advantages and disadvantages.

Apache Module (mod_php)

Using mod_php to execute PHP scripts on a Web server are the most popular method used by our customers and until recently W As the default mode we set when you create a new webspace.

When using mod_php the PHP interpreter are embedded in each Apache process that's spawned on the server. This-to-every Apache worker is able to handle and execute PHP scripts itself removing the need-deal with any external Processes Unlike CGI or FastCGI. This makes it very useful for sites that is ' PHP heavy ' where lots of requests is likely to contain PHP code (such as Wo Rdpress, Drupal, Joomla, etc.) Because all the requests can is handled by Apache.

As the interpreter is started along with Apache, it allows it to run very quickly as it can cache certain information and doesn ' t need to repeat the same tasks each time a script is executed.

The downside to this is, the footprint for each Apache process was larger as it requires more system resources with the PHP interpreter embedded. Even when serving static content such as images, text and style sheets where no. PHP code needs to be executed, the process Still contains the PHP interpreter.

Pros

    • PHP code executed by Apache.
    • No external processes required.
    • Very good performance on PHP heavy sites.
    • PHP configuration settings may be customized within. htaccess directives.

Cons

    • Makes each Apache process footprint larger–meaning more RAM used.
    • Loads PHP interpreter for non-php content.
    • Files created by PHP scripts is usually owned by the Web server so you cannot edit them via FTP later.

Cgi

Executing PHP scripts with a CGI application is the legacy a-to running applications on a Web server, it ' s highly ineffi Cient and rarely used. It is originally introduced in the 1990 's but is deemed to being too inefficient to use on anything other than very small s Ites.

A benefit of running applications on CGI are that it keeps the code execution separate from the Web server, which allows fo R some added security benefits. For example, a buggy or insecure PHP script executed via FastCGI cannot corrupt or affect security of any other files outs IDE of the domain it ' s hosted on. It also means that the PHP interpreter was only called when required, thereby allowing static content to be served solely B Y the Web server.

The inefficiencies of running PHP with CGI support Spawn from requiring a new process to BES created each time any PHP code needs to be executed. As can imagine, on busier sites or PHP based applications it can be very resource intensive.

Very few Layershift customers use this mode, and we don ' t recommend it!

Pros

    • Better security than mod_php (above) as PHP code execution is isolated from Web server.

Cons

    • Legacy the running applications.
    • Very poor performance.

FastCGI

FastCGI was introduced as a middle ground between the PHP Apache Module and the CGI application. It allows scripts to being executed by a interpreter outside of the Web server and includes the security benefits of CGI but Doesn ' t include any of the inefficiencies of CGI.

When executing PHP scripts with FastCGI each request was passed from the Web server to FastCGI via a communication socket. This allows for much greater scalability as the Web server and the PHP interpreter can is split into their own individual server environments if necessary. However a similar end result can also be achieved using nginx in front of Apache (such that Nginx handles basic requests I Tself and passes dynamic requests to Apache) so this point alone doesn ' t determine the ideal choice for a given Scena Rio.

In a Plesk environment, FastCGI is executed as the domain FTP user and are the default PHP handler we offer on all our Linu X services running the latest versions of Plesk Panel.

The downside of running PHP with FastCGI support is, any PHP directives defined in a. htaccess won't be used. as a workaround, it is possible to set PHP directives on a per domain basis with a custom php.ini file on any Plesk Pa Nel server.

Pros

    • Improved security as PHP code execution is isolated from Web server.
    • Static content is not being processed by PHP interpreter.
    • Allows files to is managed by your FTP user without altering permissions afterwards.

Cons

    • Cannot use PHP directives in. htaccess. This was expected by many popular scripts.
    • Requires PHP requests to is passed from Web server.

Which should I use?

On smaller sites, it usually comes down to personal preference when deciding which mode of PHP support for you want. We often see customers that is running CMS applications (such as WordPress, Drupal, Joomla, etc.) tend to prefer FastCGI As it allows FTP and PHP scripts equal access, meaning file upload and edit functionality within the CMS works as Advertis Ed without any special file permission configuration.

This is a overview of a very complex and in-depth issue. I have presented some of the main considerations to inform your decision, but each site is a unique so please contact our SU Pport Team If you need further guidance. For a guide detailing how to change the PHP handler using Plesk, see our accompanying Knowledgebase article.

Original: http://blog.layershift.com/which-php-mode-apache-vs-cgi-vs-fastcgi

http://www.bkjia.com/PHPjc/1066213.html www.bkjia.com true http://www.bkjia.com/PHPjc/1066213.html techarticle which PHP mode? Apache vs CGI vs fastcgi,apachefastcgi which PHP mode? Apache vs CGI vs FastCGI there is multiple ways to execute PHP scripts on a Web server. Were often asked a ...

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