Howto: Setting Up Apache, PHP (NTS) and Guard 7 Loader on Windows

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

Important note about WAMP stacks:

There are packages just for Apache web server, and also full WAMP stack packages, like WAMP / BITNAMI / XAMPP, which includes PHP and MySQL and some Control applications.

Now, If you wish to use, or already using a full WAMP stack which does not come from Zend (i.e Zend Server), you will be running PHP as Apache multithreaded module, which means Thread Safety Enabled (PHP TS).

I'm using VC14 builds, which have minimal modules in Apache lounge. Both Apache Lounge and Apache Haus are currently providing VC11 builds, which is also the state of PHP and Guard Loader. However, since Apache and PHP + Loader are not running under the same process, and VC14 builds are better for new OS versions, I'm using the latest and "greatest". If you need Apache modules which only exists in VC11 builds (they are old...), you can get the Apache and FCGI module from VC11 page, with any other Apache module you also need:http://www.apachelounge.com/download/VC11/

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

In this article, I'm assuming you have no service listening on port 80. In real life, you might already have Zend Server, Another Apache or IIS, even Skype is known to hog on port 80 and make new web service fail when trying to hook on port 80.

If you need alternative port, such as 81/82 etc., find one that is free and use it from this point on.

To check if there is a process listening on port 80, just try to load "http://127.0.0.1" in your web browser, or run telnet lookup (following is a sample output when something IS listening on port 80, and you need an alternative port):> netstat -a -b -n | find ":80" TCP 0.0.0.0:80 0.0.0.0:0 LISTENING

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!

(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:

> C:\srv\Apache24\bin\httpd.exe

To stop Apache, press CTRL+C (beautiful memories of MSDOS... ahhh).

To install Apache as a service

open 'cmd' and run:

> C:\srv\Apache24\bin\httpd.exe -k install

> C:\srv\Apache24\bin\httpd.exe -k start

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.

127.0.0.1 zend

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):

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:

Hello PHP Info!

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

Comments

Alexander Mitev
April 14, 2016 09:12

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