Summary
This article will help you set up a new PHP Web Service for testing or running Zend Guard encoded applications. I will be using Windows 7 64-bit, Apache 2.4 64-bit with FCGI module, PHP 5.6.10 NTS 32-bit, and Guard Loader for PHP 5.6.
Option 1: The Fastest setup
Download the final package, move to 'C:\' and double click to extract to 'C:\srv'.
Then, jump to Dora the Explorer's all time favourite quote: "Let's Go!!!" :)
If you take the blue pill (ready to run package) - you should probably need to edit php.ini (described in Setting up PHP section below) and change the date.timezone to match your geo location.
Option 2: The 10 steps
Read through this article, without going through the "Notes:" parts - they are here for clarifications and more info.
Option 3: Slow and Steady
Read everything, twice, send me all the typos you find and improvement suggestions, and hopefully you will not fall asleep before the article ends :)
Prerequisites
Apache packages built with VC11 / VC14 can be downloaded from Apache Lounge, or Apache Haus, or other known hosts of Apache builds for Windows (See master list here).
Guard Loader DOES NOT LOAD in PHP TS builds, so in order to use Guard Loader within existing WAMP stack, you will have to replace the PHP with NTS build. See this quick article on how to achieve that on XAMPP for Windows:
https://commaster.net/content/installing-php-fastcgi-and-zend-opcache-xampp-windows
For a new setup, I will use the following packages.
Apache + FCGI module
Step 1: Download and extract to 'C:\srv\Apache24'
http://www.apachelounge.com/download/VC14/binaries/httpd-2.4.12-win64-VC14.zip
Step 2: Download, extract and copy 'mod_fcgid.so' to 'C:\srv\Apache24\modules'
http://www.apachelounge.com/download/VC14/modules/mod_fcgid-2.3.9-win64-VC14.zip
http://www.apachelounge.com/download/VC11/
Microsoft VC runtime - download and install
VC14 64-bit: Visual C++ Redistributable for Visual Studio 2015 RC
VC11 64-bit (ONLY NEEDED IF YOU USE VC11 APACHE): Visual C++ Redistributable for Visual Studio 2012 Update 4
PHP 5.6 NTS 32-bit
Step 3: Download and extract to 'C:\srv\php-5.6.10-nts-Win32-VC11-x86'
http://windows.php.net/downloads/releases/php-5.6.10-nts-Win32-VC11-x86.zip
Guard Loader for PHP 5.6 NTS
Step 4: Download and extract to 'C:\srv\zend-loader-php5.6-windows-x86'
http://www.zend.com/en/products/loader/downloads#Windows
At this point, I would WARMLY RECOMMEND to rename 'php_opcache.dll' in 'C:\srv\php-5.6.10-nts-Win32-VC11-x86\ext', so it will not be loaded instead of the Guard Loader packaged dll.
Setting Up Your Environment
Setting Up PHP with Guard Loader
Step 5: Copy 'C:\srv\php-5.6.10-nts-Win32-VC11-x86\php.ini-development' to 'C:\srv\php-5.6.10-nts-Win32-VC11-x86\php.ini' and edit the new file.
Add the following section to the end of php.ini:
zend_extension="C:\srv\zend-loader-php5.6-windows-x86\ZendLoader.dll"
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
Fixing Timezone: Find and modify ';date.timezone =' to reflect your actual Timezone, e.g.:
You can also configure at this stage memory_limit, error_reporting etc.
Once php.ini is all set up to your preference, save the file and exit the text editor.
Step 6: Testing Guard Loader from CLI
Click start, type "cmd" and Enter - you will get a nice console window.
Run the following to check if Guard Loader and OPCache are loaded correctly in your PHP. If you don't see those components, verify if you have done everything properly (or, use the "Fastest setup" Package above).
Sample Output:
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
Setting Up Apache
Step 7: Edit 'C:\srv\Apache24\conf\httpd.conf' in a simple text editor
> netstat -a -b -n | find ":80"
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
Locate 'ServerRoot' directive and change its value to "C:/srv/Apache24" (including double quotes)
Locate 'ServerName' directive, uncomment the line (remove the leading #) and replace the value with <computer_name>:80 (or alternative port, see above).
Use your real computer name or make up something nice!
Locate 'Listen' directive and modify, in case you need alternative port.
Find and Replace all occurrences of 'c:/Apache24' with 'C:/srv/Apache24' (I found 5, out of which 1 was in a comment).
Locate '<Directory "C:/srv/Apache24/htdocs">' and in that directory section, add ' Includes ExecCGI' to the 'Options Indexes FollowSymLinks' line.
Find and Replace all occurrences of 'AllowOverride None' with 'AllowOverride All', so you can set .htaccess and actually use the filesystem (I found 3).
Locate 'ServerAdmin' directive and replace with your own email (not mandatory).
Locate 'DirectoryIndex index.html' directive and add ' index.php' to this line.
Finally, add the following section, which is the heart of loading PHP under FCGI module, to the end of httpd.conf:
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
FcgidInitialEnv PATH "C:/srv/php-5.6.10-nts-Win32-VC11-x86;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 1000
FcgidMaxProcesses 50
FcgidMaxRequestLen 8131072
# Location php.ini:
FcgidInitialEnv PHPRC "C:/srv/php-5.6.10-nts-Win32-VC11-x86"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
<Files ~ "\.php$>"
AddHandler fcgid-script .php
FcgidWrapper "C:/srv/php-5.6.10-nts-Win32-VC11-x86/php-cgi.exe" .php
</Files>
</IfModule>
Save the file and exit the editor.
Step 8: Test your Apache + FCGI module + PHP + Guard setup
To run Apache as application
(This is great for troubleshooting when Apache service doesn't start normally, combined with checking the logs at 'C:\srv\Apache24\logs')
open 'cmd' and run:
To stop Apache, press CTRL+C (beautiful memories of MSDOS... ahhh).
To install Apache as a service
open 'cmd' and run:
The above commands will install, then start the Apache service if properly installed.
Now, when you open services.msc (Start Menu -> Run), you can find a new Apache2.4 service there (hopefully, started). Check 'httpd.exe /?' for more options, such as stop/restart/uninstall (for removing the service).
Windows will probably alert you at this stage that the new HTTPD process requests access to your network - allow it! - including checking "public networks" (unless you have any rejects of course).
Once Apache starts (and stays up) - Browse to http://127.0.0.1 and you should see some silly phrase: "It works!" (which means... you know.)
If you wish to give your local website a meaningful (or short) name, instead of using IP/localhost for default website, you can add a new line to Windows hosts file, which is located at 'C:\Windows\System32\drivers\etc\hosts', and use it on your browser. For example, I wish to call it 'zend' (I wonder why) - so browsing to http://zend will bring me to... my local server on port 80.
Testing a bit further
You can rename index.html in 'C:\srv\Apache24\htdocs' to see directory tree when browsing to http://127.0.0.1.
Step 9: Create a simple text file in 'C:\srv\Apache24\htdocs' called info.php, and add this code in it, then save:
<?php phpinfo(); ?>
To load the new test and see PHP Information of your new setup, browse to http://127.0.0.1/info.php, or http://<your_site_name>/info.php
You should see OPCache and Guard Loader in the 2nd table where PHP engine information is (under the build configuration table):
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
You can create a shortcut / link on your desktop, or your start menu for the ApacheMonitor.exe which is in 'C:\srv\Apache24\bin'. Apache Monitor sits in the Systray (opposite side of the Start Menu) where you can control Apache server(s) easily without using the command line. You can also make it start on boot if you place the link under Start Menu -> All Programs -> Startup.
The Big Q: Can I Run Encoded PHP Now, Please?
Step 10: Well... Duh! Lets test encoded file, shall we?
If you extracted the srv.exe package provided above, you already have the Guard simple test. If not, download the attached zip, extract to 'C:\srv\Apache24\htdocs'.
Open your browser at 'http://127.0.0.1/Simple/encoded56/'.
Now click on one of PHP scripts to open encoded / obfuscated PHP script. If all goes according to plan, you will see the output of the simplest, but most beautiful, script you ever seen:
Game, Set and Match!
Closing Notes
For this article, I was using 3rd party Apache and PHP to load Zend Guard Loader runtime PHP module. Zend does not support 3rd party components within the scope of Guard Loader (free download). If you are not a Zend Guard customer with active SLA, please contact your Guard software maintainer to get assistance with your Guard Loader issues. If you are a Guard customer with active SLA, please open a support ticket with any technical issues or questions regarding Guard and its Loader PHP modules.
For a fully supported WAMP stack by Zend which also includes the Guard Loader, please check Zend Server (available for development, production and cloud).
This line "zend_loader.obfuscation_level_support=3" causes PHP 5.6 to crash (even PhpMyAdmin) with the extremely helpful message "mod_fcgid: get overlap result error", no matter which subversion of Apache and PHP I use. It took me 3 bloody days to figure this out... Pls remove it from this site and from the distro files.
I want to start phpmyadmin and mysql too with this installation. I already did this tutorial and when I install phpmyadmin and mysql, there are some errors. Can you please give the tutorial about how to install phpmyadmin and mysql after I did the tutorial above?
Thank you..