Installing Apache, PHP, and Postgres on Windows 7 64 Bit

Installing Apache on 64-bit Windows

0. Download

Go to http://www.microsoft.com/en-us/download/details.aspx?id=30679 and download Visual C++ Redistributable for Visual Studio 2012 (VC11) which is needed for the next step. Double-click and install it.

1. Download

Go to http://www.apachelounge.com/download/and download the 64-bit version (httpd-2.4.12-win64-VC11.zip)

2. Unzip
Unzip the Apache24 folder to c:/Apache24 (that is the ServerRoot in the config).
Default folder for your your webpages is DocumentRoot “c:/Apache24/htdocs”

When you unzip to another location, change ServerRoot, Documenroot, Directories, ScriptAlias in httpd.conf. Also, when you use the extra folder config files, change to your location there as well.

3. Install Apache as a service
Start > cmd (Run as Administrator)
c:\Apache24\bin>httpd.exe -k install

4. Install ApacheMonitor
Right-click on c:\Apache24\bin\ApacheMonitor.exe, Run as Administrator,
Make a shortcut of ApacheMonitor and put it in your Startup folder.

4. Test Setup
Go to http://localhost and you should see “It works”.

5. If you already have configuration files from a previous installation that you would like to apply to this new installation, do the following:
– rename C:/Apache24/conf/httpd.conf to httpd-original.conf
– rename C:/Apache24/conf/extra/httpd-vhosts.conf to httpd-vhosts-original.conf
– rename C:/Apache24/conf/extra/httpd-ssl.conf to httpd-ssl-original.conf
– rename old C:/Windows/System32/drivers/etc/hosts file to hosts-original

6. copy and paste the config files from your old installation into the new installation
C:/Apache24/conf/9264078_local.dev.XXXX.com.cert (SSL cert)
C:/Apache24/conf/9264078_local.dev.XXXX.com.key (SSL key)
C:/Apache24/conf/httpd.conf
C:/Apache24/conf/server.crt (SSL cert)
C:/Apache24/conf/server.nopassword.key (SSL key)
C:/Apache24/conf/extra/httpd-vhosts.conf
C:/Apache24/conf/extra/httpd-ssl.conf

7. Some useful (necessary) settings to have in httpd.conf

  • LoadModule php5_module “C:/php-5.6.5-Win32-VC11-x64/php5apache2_4.dll”
  • LoadFile “C:\php-5.6.5-Win32-VC11-x64\libpq.dll”
  • PHPIniDir “C:\php-5.6.5-Win32-VC11-x64”
  • DirectoryIndex index.html index.php
  • AddType application/x-httpd-php .php
  • Include conf/extra/httpd-vhosts.conf
  • Include conf/extra/httpd-ssl.conf

Installaing PHP on Windows

1. Download
Go to http://windows.php.net/download/and download VC11 x64 Thread Safe
(php-5.6.5-Win32-VC11-x64.zip)

Since we installed the 64-bit version of Apache, we have to install the 64-bit version of PHP. You can’t mix 32-bit with 64-bit.

2. Unzip
Create folder c:\PHP and extract the PHP zip file to c:\PHP. I’m extracting the files to c:\php-5.6.5-Win32-VC11-x64 because that folder name is more descriptive.

3. If you already have configuration files from a previous installation that you would like to apply to this new installation, do the following:
– copy php.ini from old installation to c:\PHP (or c:\php-5.6.5-Win32-VC11-x64)

4. Update Path
Append to PATH environment variable C:\PHP (or c:\php-5.6.5-Win32-VC11-x64). Use PathEditor to make editing the PATH variables easier.

5. Test Setup
Restart Apache from the command line

TO START
c:/Apache24/bin>httpd.exe

TO STOP
Control + C

If you get errors, do a diff between original and modified config files and update original file one line at a time.

7. OpCode Caching

As of PHP 5.5, Zend OpCache has been included in PHP so there’s no need to install APC. However, you still need to enable Zend OpCache.

In php.ini, add the line

zend_extension=C:\php-5.6.5-Win32-VC11-x64\ext\php_opcache.dll

after your other extensions and then restart Apache. To verify OpCache has been enabled, run php -v from the command line and check for Zend OpCache.

C:\>php -v
PHP 5.6.5 (cli) (built: Jan 21 2015 16:30:08)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

If you want to install APCu, you can do that manually.

8. Test Again

9Some useful (necessary) settings to have in php.ini

  • zend.multibyte = On
  • zend.script_encoding = UTF-8
  • max_execution_time = 120
  • memory_limit = 246M
  • extension_dir = “C:\php-5.6.5-Win32-VC11-x64\ext”
  • extension=php_mbstring.dll
  • extension=php_mysql.dll
  • extension=php_openssl.dll
  • extension=php_pdo_mysql.dll
  • extension=php_pdo_pgsql.dll
  • extension=php_pgsql.dll
  • zend_extension=C:\php-5.6.5-Win32-VC11-x64\ext\php_opcache.dll
  • mbstring.internal_encoding = UTF-8
  • mbstring.func_overload = 7
  • mbstring.strict_detection = On

Installing Postgres Database

1. Download
Go to Postres’ website and download
postgresql-9.2.3-1-windows-x64.exe

2. Install
Double-click the installer

3. Create password

4. Update Path
After installation, append to PATH environment variable C:\PostgreSQL9.4\bin

5. Test
Open PgAdminIII and to connect to database