Installing Apache and PHP manually in Windows server 2012/2008

Installing Apache 2.4.x and PHP 5.6.x manually in Windows server 2012/2008 64 bit versions

In this article, I am explaining the steps to install Apache 2.4.x and PHP 5.6.x in Windows Server 2012/2008 Standard 64 bit edition manually from source.

Apache 2.4.x binary versions for windows servers are not available in the original repository and needs to rely on the third party distributions like apachehaus.com. I am using httpd-2.4.20-x64-vc11-r2.zip version downloaded from the URL http://www.apachehaus.com/cgi-bin/download.plx . This version is compiled with VC++ compiler 2012 (VC11). Please make sure that the server is installed with the VC11 64bit. Otherwise, there will be errors like missing modules or Apache will refuse to start. You can download it from direct mirror of Microsoft at the URL http://www.microsoft.com/en-us/download/details.aspx?id=30679 . The PHP binaries can be downloaded from the http://windows.php.net/download/ . I am using php-5.6.22-Win32-VC11-x64.zip which is compiled with vc11.

Installing Apache

First, download the latest version of Apache HTTP Server win32 binary from the URL above and extract it to an easier file location like “C:\Apache”. If Apache is installed in locations like “C:\Program Files\Apache2.2”, the cgi and php scripts may not find the paths correctly due to the spaces in the directory names.

Here we make the directory as Apache. Using a text editor such as Notepad, open the httpd.conf file. This file is found in the /conf sub-directory under the directory “C:\Apache”. Please note that in the Apache configuration files, “/” slashes should be used in path names just like unix systems even though windows uses “\” slashes for paths.

Now we can try installing Apache as a windows service. Open the command prompt and traverse to the “c:\Apache\bin” directory and type in the command httpd -k install .

c:\Apache\bin>httpd -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
httpd: Syntax error on line 39 of C:/Apache/conf/httpd.conf: ServerRoot must be
a valid directory

From the snippet above, we can see that the service has been installed but with an error. The server Root directory needs to be corrected before the service can be started. If the installation directory is changed from the default values (default value is /Apache2.4). In this case, it is /Apache.

Define SRVROOT "/Apache"
ServerRoot "${SRVROOT}"

After changing the server root, double click the Apache Server monitor executable to open the monitor panel or use command line to start / stop / restart the service. Command line examples are in the snippet below.

c:\Apache\bin>httpd -k start

c:\Apache\bin>httpd -k restart

c:\Apache\bin>httpd -k stop
The 'Apache2.4' service is stopping.
The 'Apache2.4' service has stopped.

If we get an error similar like the one in the snippet below while starting the Apache server, check if there is a httpd process already running or if IIS is running and listening to the port 80. IIS is the default web server installed and is configured to listen 80.

c:\Apache\bin>httpd -k start
(OS 10048)Only one usage of each socket address (protocol/network address/port)
is normally permitted. : AH00072: make_sock: could not bind to address [::]:80
(OS 10048)Only one usage of each socket address (protocol/network address/port)
is normally permitted. : AH00072: make_sock: could not bind to address 0.0.0.0:
80
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs

If IIS is running, You can disable it in Service manager. Type “services.msc” in run prompt. Look for the “web publishing platform” services, double click to open its properties and stop the service if its running. To disable it from getting started on next reboot, you can turn change the startup type to manual. Also, if Skype is installed on the server, it also conflicts with the port 80.

Once the Apache is started either through serve monitor or command line and configurations are correct, browsing http://localhost/ on any browser should show a default http page or just a message ” It works”.

Installing PHP

First, download PHP binaries from the URL above and Unzip the PHP files to “C:\php”. We will rename the file c:\php\php.ini-development to php.ini. Open the php.ini we renamed and update a few variables inside.

Update the variable “extension_dir” to “C:\php\ext”. By default, it will be commented or just “/ext”. Also, we can enable required extensions in the php.ini by removing the “;” at the starting of the line like

;extension=php_mbstring.dll
;extension=php_exif.dll 
extension=php_mysql.dll
extension=php_mysqli.dll

We will also need to update the variable sessions.save_path to the Windows temporary files directory (i.e. C:\Temp).

The PHP and Apache directories needs to be added to the Path Environment Variables. Please open Control Panel\System and Security\System location and append “;C:\php;C:\Apache\bin” to the end of the Path System Variables list and Click OK to save it.

Before restarting the Apache service, we need to mention PHP modules in the httpd.conf. Add the following lines to the end of the httpd.conf file below the current “LoadModule” section.

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"

Also, we need to add “index.php” to the DirectoryIndex in the default httpd.conf file just like below.

<IfModule dir_module>
 DirectoryIndex index.html index.php
</IfModule>

Once changes are made, please save the httpd.conf and close it.

Apache service needs to be restarted to make the changes in effect. Restart the service either from Apache service monitor or by command “httpd -k restart”

We need to create a new index.php to test if the PHP works fine. Create a new page “index.php” under the C:\Apache\htdocs with any php codes. For example, I used the code below.

<?php
phpinfo();
?>

Once its saved, browse the URL http://localhost/index.php in the browser and if there is no errors, it will show the phpinfo page.

The Apache and PHP basic installation on Windows 2012 standard has been completed. There are a lot of modules which is disabled or commented in the httpd.conf as well as php.ini. These can be enabled as required by removing the comments and restarting the Apache services. For accessing the websites / pages from an outside network, make sure that the httpd.exe is allowed publicly in Control Panel\System and Security\Windows Firewall\Allowed apps.

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.