In Windows, Apache1.3 runs PHP in FastCGI mode. after reading Apache1.3 runs PHP in FastCGI mode, I have been running PHP in ISAPI mode for a long time. The biggest disadvantage of this mode is poor stability, when a PHP error occurs, the Apache process also dies. Later, I saw P
I have been running PHP in ISAPI mode for a long time. The biggest drawback of this method is poor stability. When PHP fails, the Apache process also dies. Later, I saw an introduction to PHP running in FastCGI mode on the Internet, and I decided to try the advantages (stability, security, and high performance) I mentioned.
However, things are far less smooth than expected. Google hasn't found a document on how to use Apache + FastCGI to run PHP in Windows countless times. IIS + FastCGI ran a lot of PHP. One article mentioned that Zend also recommends running PHP () in FastCGI mode ().
After several hours of exploration, we finally succeeded in running PHP with Apache 1.3 + FastCGI.
Preparations:
First, access and download mod_fastcgi for Apache. I am using a mod_fastcgi-2.4.2-AP13.dll. Copy the downloaded file to the modules directory of Apache.
Download PHP (my PHP-5.0.4), decompress it, and modify the php. ini file as needed. Note that you do not need to copy any files from the PHP directory to the Windows directory.
Modify configuration:
Modify the httpd. conf file and add the following lines:
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP13.dll
ScriptAlias/fcgi-php5/"d:/usr/local/php-5.0.4 /"
FastCgiServer "d:/usr/local/php-5.0.4/php-cgi.exe"-processes 3
# Note: Here-processes 3 indicates to start three php-cgi.exe processes,
# For detailed FastCgiServer parameters, see The FastCGI document.
AddType application/x-httpd-fastphp5. php
Action application/x-httpd-fastphp5 "/fcgi-php5/php-cgi.exe"
# Note: modify the above two italics based on the location of your PHP file.
After modification, restart Apache.
FAQs:
According to my many experiments, the most common problems are caused by paths. Therefore, first check whether all paths in the php. ini and httpd. conf files are correct. Second, if PHP has been installed in the system before, change the name of C: Windowsphp. ini or delete it.
Second, check whether the directory where the PHP file is located has sufficient permissions (I set it to Everyone-full control, so there is no need to consider so many security restrictions for the development machine ).
Advantages of running PHP in FastCGI mode:
There are several main advantages of running PHP in FastCGI mode. First, Apache will not be destroyed when PHP errors occur, but PHP's own processes will be destroyed (but FastCGI will immediately restart a new PHP process to replace the failed process ). Second, FastCGI runs PHP in better performance than ISAPI (I used apacheloud for testing, but forgot to save the results. if you are interested, you can test it on your own ).
Finally, you can run PHP5 and PHP4 at the same time. Refer to the following configuration file to create two virtual hosts, one using PHP5 and the other using PHP4.
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP13.dll
ScriptAlias/fcgi-php5/"d:/usr/local/php-5.0.4 /"
FastCgiServer "d:/usr/local/php-5.0.4/php-cgi.exe"-processes 3
ScriptAlias/fcgi-php4/"d:/usr/local/php-4.3.11 /"
FastCgiServer "d:/usr/local/php-4.3.11/php.exe"
Listen 80
NameVirtualHost *: 80
DocumentRoot d:/www
Options Indexes FollowSymlinks MultiViews
ServerName php5.localhost
AddType application/x-httpd-fastphp5. php
Action application/x-httpd-fastphp5 "/fcgi-php5/php-cgi.exe"
IndexOptions FancyIndexing FoldersFirst
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow, deny
Allow from all
Listen 8080.
Namevirtualhost*: 8080
DocumentRoot d:/www
Options Indexes FollowSymlinks MultiViews
ServerName php4.localhost
AddType application/x-httpd-fastphp4. php
Action application/x-httpd-fastphp4 "/fcgi-php4/php.exe"
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow, deny
Allow from all
With the above configuration, PHP5 is used for access, and PHP4 is used for access. Therefore, different virtual hosts can use different versions of PHP.
Some disadvantages of FastCGI mode:
Let's talk about the advantages and disadvantages. In my practical use, FastCGI is more suitable for servers in the production environment. But it is not suitable for development machines. When Zend Studio is used to debug a program, FastCGI considers that the PHP process times out and returns error 500 on the page. This is annoying, so I switched back to the ISAPI mode on the development machine.
Finally, a potential security vulnerability exists in FastCGI mode in Windows. Because I have not found a way to implement SuEXEC in a Windows environment, PHP processes always run with the highest permissions. this is obviously not good news from the security perspective.
Conclusion:
The application of FastCGI in this article is still at a very early stage. it is only used as an example and we hope to see more mature solutions.