Install PHP in FastCGI in Windows (APACHE mod_fcgid)

Source: Internet
Author: User

When upgrading the local PHP to version 5.3.3, I found that the php5apache2_2.dll library was not found in the ETS version package. I thought PHP had fallen out of this important library. After Google, I learned that it was the FastCGI Installation Method for PHP. Install FastCGI mod for Apache and configure it. reference the original installation configuration.

I 've run php on windows in every way imaginable. I 've run it through IIS and Apache. I 've run it as SAPI, CGI, FastCGI. heck, I 've run it from the command line to automate tasks (during my pre-Python days ). but I hadn't tried mod_fcgid until recently. setting it up isn' t terribly straight forward and most of the online tutorials I found were for various flavor of Linux, so I thought I 'd go over how to do it here.

Everybody that has worked with PHP For A While knows that using it inline with your web server will, at random points, eat your web server. this has been true authentication ss php versions forever. there are always legends of people that have just the right release with just the right libraries and just the right modules loaded that it just works and if you're one of those people () I hate you and (B) for pete's sake don't touch anything. from my personal experience, trying to pinpoint and fix the problem will turn your life into a furious ball of nothing.

So most people end up with a cgi or FastCGI solution.

Mod_fcgid is a FastCGI solution, that being basically CGI with the ability to persist a process or processes and manage them from the server. that gives you the performance benefits of ISAPI (or pretty close) with the process isolation of CGI. mod_fcgid is Binary compatible with FastCGI, but offers improved control over process spawning. it also runs well on multi-threaded Apache and lets you fairly easily run different PHP versions and configurations on the same Apache instance. plus, running PHP under Apache with mod_fastcgi has proven problematic in practice.

Assuming you already have Apache 2.x up and running, we're re going to grab a couple of things. first, you'll want to grab the non thread safe release of PHP. this will massively increase performance of PHP, as the PHP process doesn' t have twiddle its thumbs waiting on thread synchronization. the next thing you'll need to grab is mod_fcgid, which you'll dump into your Apache modules folder. we'll assume you dumped the PHP folder at c: \ PHP, so change your paths appropriately.

Next, you'll need to load the mod_fcgid module in your Apache httpd. conf file.

 

  1. Loadmodule fcgid_module modules/mod_fcgid.so

Now for the hard bit-locking ing mod_fcgid. There are all kinds of mod_fcgid settings you can read about on the doc site, but these shoshould cover most of your needs.

<Ifmodule mod_fcgid.c>

Addhandler fcgid-script. fcgi. php
# Where to look for the php. ini file?
Fcgidinitialenv phprc "C:/PHP"
# Set php_fcgi_max_requests to greater than or equal to fcgidmaxrequestsperprocess
# To prevent PHP-CGI process from exiting before all requests completed
Fcgidinitialenv php_fcgi_max_requests 1000
# Maximum requests a process shoshould handle before it is terminated
Fcgidmaxrequestsperprocess 1000
# Maximum number of PHP Processes
Fcgidmaxprocesses 15
# Number of seconds of idle time before a PHP-CGI process is terminated
Fcgidiotimeout 120
Fcgididletimeout 120
# Path to PHP-CGI
Fcgidwrapper "C:/PHP/php-cgi.exe". php
# Define the mime-type for ". php" files
Addtype application/X-httpd-PHP. php
</Ifmodule>

<IfModule mod_fcgid.c> AddHandler fcgid-script .fcgi .php # Where to look for the php.ini file? FcgidInitialEnv PHPRC        "c:/php" # Set PHP_FCGI_MAX_REQUESTS to greater than or equal to FcgidMaxRequestsPerProcess # to prevent php-cgi process from exiting before all requests completed FcgidInitialEnv PHP_FCGI_MAX_REQUESTS      1000 # Maximum requests a process should handle before it is terminated FcgidMaxRequestsPerProcess       1000 # Maximum number of PHP processes FcgidMaxProcesses             15 # Number of seconds of idle time before a php-cgi process is terminated FcgidIOTimeout             120 FcgidIdleTimeout                120 #Path to php-cgi FcgidWrapper "c:/php/php-cgi.exe" .php # Define the MIME-Type for ".php" files AddType application/x-httpd-php .php </IfModule>

Note the two hard paths to PHP-change those as needed. last, we'll need to tell Apache to include execcgi in its options for a particle directory. supposing your document root is c: \ www, you 'd have something like this:

<Directory "C:/www">
Options indexes followsymlinks execcgi
Order allow, deny
Allow from all
AllowOverride all
</Directory>
<Directory "C:/www"> Options Indexes FollowSymLinks ExecCGI Order allow,deny Allow from all AllowOverride All </Directory>

Now PHP files in your document root and subsequent directories will be served by mod_fcgid. Restart Apache, make a test PHP file (<? PHP phpinfo () ;?> ), And give it a whirl. You shoshould see a php-cgi.exe process started that mod_fcgid is managing.

It's tricky to set up the first time, but mod_fcgid is the best way to run php on Apache I 've found.

Original article address:

Http://fuzzytolerance.info/code/apache-mod_fcgid-and-php-on-windows/

 

 

 

 

 

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.