Wednesday 3 November 2021

 

Setup your own WAMP stack – Part II

In our previous post “Setup you own WAMP stack – Part I”, we installed and setup Apache server in our Windows 10 PC.

We already know what is the WAMP stack. Now we will put (install & setup) PHP in the stack.

Download and extract PHP

Step1:

Now download PHP 7.x from http://windows.php.net/download/; you need this file: VC15 x64 Non Thread Safe

(related to the latest stable version number).

Please download the VC11/14 x86/x64 ‘Non Thread’ Safe OR VC11/VC14/VC15 x86/x64 Thread Safe if you need to run PHP as module.

I downloaded the php non thread safe zip file. As a ‘non thread’ safe php increases the performance a lot while a thread safe php uses much memory in synchronizing the thread.

Step 2:

Extract the contents of this zip file and move the contents to where you intend to use PHP such as C:\php7.

Step 3:

Now navigate the folder C:\php7 and find the php.ini-production file. It is a pure text file. Open it with editor like Notepad++ for ease. Find there the extension_dir directive and change it so that it can properly locate full path.

extension_dir = "C:\php7\ext"

To enable the mysqli change the following extensions by removing the comment character.

extension=php_mysqli

extension=mbstring

extension=pdo_mysql

 

Now enable the opcache:

zend_extension=php_opcache.dll

Now search for opcache:

opcache.enable=On

opcache.cli_enable=On

To hide php from Apache response header:

expose_php = Off

Search the pathinfo inside the script:

cgi.fix_pathinfo=1

To set your timezone. Find your zone at http://php.net/date.timezone:

date.timezone = “Asia/Kolkata"

Now check whether all of the modules have loaded properly:

At the command prompt, write: >php – m

It will display all the modules loaded.

save this file as php.ini.

Step 4:

Go back to C:\Apache24\conf and open httpd.conf text file.

Now, to be able to access the php, change the httpd.conf file inside the C:\Apache24\conf directory.  The httpd.conf file is also a pure text file. Open it with Notepad++ for ease. There, make sure it contains the code block mod_fcgid. (mod_fcgid is an additional download).

First, uncomment the following LoadModule:

LoadModule fcgid_module modules/mod_fcgid.so

Now add the following fcgid module. If it is already present inside the httpd.conf file modify it accordingly[uncomment it].

The mod_fcgid code is as following:

<IfModule fcgid_module>

   FcgidMaxProcesses 300   

   FcgidMaxProcessesPerClass 300   

   FcgidOutputBufferSize 65536   

   FcgidConnectTimeout 10   

   FcgidProcessLifeTime 0   

   FcgidMaxRequestsPerProcess 0   

   FcgidMinProcessesPerClass 0   

   FcgidFixPathinfo 0   

   FcgidProcessLifeTime 0   

   FcgidZombieScanInterval 20   

   FcgidMaxRequestLen 536870912   

   FcgidIOTimeout 120   

   FcgidTimeScore 3   

   FcgidPassHeader Authorization   

FcgidInitialEnv PHPRC "C:\\php7"   

FcgidInitialEnv PATH "C:\\php7;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"   

<Files ~ "\.php$">      

      Options Indexes FollowSymLinks ExecCGI      

      AddHandler fcgid-script .php      

      FcgidWrapper "C:/php7/php-cgi.exe" .php   

</Files>

</IfModule>

 

Now save the httpd.conf file

Step 5:

Now install Apache service in your system. To do that:

C:\Apache24\bin>httpd -k install ß[Enter]

This will install the Apache service in our system.

We can check this in services window from the search box in the status bar(for Windows 10).

To restart Apache, we need to give the following command:

C:\Apache24\bin>httpd -k restart ß [Enter]

Window 10 automatically sets the path for php7. For Windows 2000, XP, vista, we need to restart the computer.

 (Apache for Windows contains the ability to load modules at runtime, without recompiling the server. If Apache is compiled normally, it will install a number of optional modules in the \Apache2.4\modules directory. To activate these or other modules, the LoadModule directive must be used. For example, to activate the status module, use the following (in addition to the status-activating directives in access.conf)

For example: LoadModule status_module "modules/mod_status.so"  

To stop the Apache serviece we need to write the following at the command prompt: C:\Apache24\bin>httpd -k shutdown ß [Enter]

Rather doing a shutdown we should do a restart whenever we make a change in the httpd.conf  configuration file. So, we need to do: C:\Apache24\bin>httpd -k restartß [Enter]

This will restart the apache services.