Installing PHP FastCGI and Zend OPcache on XAMPP for Windows
Why install PHP + FastCGI?
Mod-PHP comes installed with WampServer, and it is slow.
You also cannot utilise the Zend opcode cache, which is included with PHP itself since PHP 5.5.
Steps to install PHP + FastCGI
Identify the version of Apache server that is running. Tips: visit http://127.0.0.1/xampp/phpinfo.php on your browser. Search for the
SERVER_SOFTWARE
environment variable, which will indicate Apache version. (Example: Apache/2.4.4 (Win32) OpenSSL/1.0.1g PHP/5.4.16 ).Download mod_fcgid binaries for windows. Extract the files and copy “mod_fcgid.so” into the apache modules folder. The default folder path will be
C:\xampp\apache\modules
.- Apache 2.4-VC11 (64-bit): http://www.apachelounge.com/download/VC11/modules/modules-2.4-win64-VC11.zip
- Apache 2.4-VC11 (32-bit): http://www.apachelounge.com/download/VC11/modules/modules-2.4-win32-VC11.zip
- Apache 2.4-VC10 (64-bit): http://www.apachelounge.com/download/win64/modules-2.4/mod_fcgid-2.3.9-win64.zip
- Apache 2.4-VC10 (32-bit): http://www.apachelounge.com/download/win32/modules-2.4/mod_fcgid-2.3.9-win32.zip
- Apache 2.2-VC10 (64-bit): http://www.apachelounge.com/download/win64/modules-2.2/mod_fcgid-2.3.9-win64.zip
- Apache 2.2-VC10 (32-bit): http://www.apachelounge.com/download/win32/modules-2.2/mod_fcgid-2.3.9-win32.zip
Download the latest PHP binaries for windows. (Link: http://windows.php.net/download/). Choose the non-thread-safe (nts) version for fastcgi usage. The default PHP installation in XAMPP is thread-safe (ts) and will be replaced later. Create a folder (eg:
C:\Xampp\php5.5.12-nts
) for your new php installation. Extract and copy all the files into the folder.Edit the Apache configuration file. Open the file
C:\Xampp\apache\conf\extra\httpd-xampp.conf
in a text editor such as Notepad++.Look for the section PHP-Module setup. Disable mod_php by commenting out them as below:
# # PHP-Module setup # #LoadFile "C:/xampp/php/php5ts.dll" #LoadModule php5_module "C:/xampp/php/php5apache2_4.dll" #<FilesMatch "\.php$"> # SetHandler application/x-httpd-php #</FilesMatch"> #<FilesMatch "\.phps$""> # SetHandler application/x-httpd-php-source #</FilesMatch">
Enable mod_fcgid by adding the following lines after the section:
# # PHP-FastCGI setup # LoadModule fcgid_module modules/mod_fcgid.so <IfModule fcgid_module> FcgidInitialEnv PATH "C:/Xampp/php5.5.12-nts;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;" FcgidInitialEnv SystemRoot "C:/Windows" FcgidInitialEnv SystemDrive "C:" FcgidInitialEnv TEMP "C:/Xampp/tmp" FcgidInitialEnv TMP "C:/Xampp/tmp" FcgidInitialEnv windir "C:/WINDOWS" FcgidIOTimeout 64 FcgidConnectTimeout 16 FcgidMaxRequestsPerProcess 1000 FcgidMaxProcesses 3 FcgidMaxRequestLen 8131072 # Location php.ini: FcgidInitialEnv PHPRC "C:/Xampp/php5.5.12-nts" FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 <Files ~ "\.php$"> Options Indexes FollowSymLinks ExecCGI AddHandler fcgid-script .php FcgidWrapper "C:/Xampp/php5.5.12-nts/php-cgi.exe" .php </Files> </IfModule> <IfModule mime_module> AddType application/x-httpd-php .php AddType application/x-httpd-php .php3 </IfModule>
Create a new php configuration file by copying the file at
C:\Xampp\php5.5.12-nts\php.ini-development
toC:\Xampp\php5.5.12-nts\php.ini
.Finally, restart Apache server and PHP should be running in FastCGI mode. Visit http://127.0.0.1/xampp/phpinfo.php and check that ServerAPI is CGI/FastCGI to confirm.
Steps to Enable Zend OPcache
Edit the php configuration file at
C:\Xampp\php5.5.12-nts\php.ini
.Locate the section [opcache].
Add this line before the section:
zend_extension=php_opcache.dll
Uncomment the configuration lines in the section:
[opcache] ; Determines if Zend OPCache is enabled opcache.enable=1 ; Determines if Zend OPCache is enabled for the CLI version of PHP opcache.enable_cli=0 ; The OPcache shared memory storage size. opcache.memory_consumption=64 ; The amount of memory for interned strings in Mbytes. opcache.interned_strings_buffer=4 ; The maximum number of keys (scripts) in the OPcache hash table. ; Only numbers between 200 and 100000 are allowed. opcache.max_accelerated_files=2000 ; The maximum percentage of "wasted" memory until a restart is scheduled. opcache.max_wasted_percentage=5 ; When this directive is enabled, the OPcache appends the current working ; directory to the script key, thus eliminating possible collisions between ; files with the same name (basename). Disabling the directive improves ; performance, but may break existing applications. opcache.use_cwd=1 ; When disabled, you must reset the OPcache manually or restart the ; webserver for changes to the filesystem to take effect. opcache.validate_timestamps=1 ; How often (in seconds) to check file timestamps for changes to the shared ; memory storage allocation. ("1" means validate once per second, but only ; once per request. "0" means always validate) opcache.revalidate_freq=2 ; Enables or disables file search in include_path optimization opcache.revalidate_path=0 ; If disabled, all PHPDoc comments are dropped from the code to reduce the ; size of the optimized code. opcache.save_comments=0 ; If disabled, PHPDoc comments are not loaded from SHM, so "Doc Comments" ; may be always stored (save_comments=1), but not loaded by applications ; that don't need them anyway. opcache.load_comments=0 ; If enabled, a fast shutdown sequence is used for the accelerated code opcache.fast_shutdown=1 ; Allow file existence override (file_exists, etc.) performance feature. opcache.enable_file_override=0 ; A bitmask, where each bit enables or disables the appropriate OPcache ; passes opcache.optimization_level=0xffffffff
Finally, restart Apache web server. Visit http://127.0.0.1/xampp/phpinfo.php and search for Opcache. If it is found, then you have successfully enabled opcode caching!
comments powered by Disqus