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

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

mRemoteNG: Better Than Plain Putty for SSH

I can’t stand using Putty for SSH on Windows. It’s ugly and very non user-friendly. I even got a Mac laptop which I often use for just SSH using Mac Terminal. But, yesterday I discovered mRemoteNG from a coworker, which is a wrapper to Putty, supports tabs, and offers a much better overall SSH experience from Windows. If you need a terminal on Windows, I’d recommend Putty + mRemoteNG. Learn more and download at

http://www.mremoteng.org/

In addition, to fix the ugly color scheme that comes with Putty, use one of these custom themes.

http://www.igvita.com/2008/04/14/custom-putty-color-themes/

Setting Up PHP to Support UTF-8 / i18n International Characters

Instead of specifically writing string manipulation code that is multibyte-safe, e.g. mb_substr() instead of substr(), you can configure PHP to do this automatically.  Just update the following lines in your php.ini.

mbstring.internal_encoding = UTF-8
mbstring.func_overload = 7
mbstring.strict_detection = On
zend.multibyte = On
zend.script_encoding = UTF-8

mbstring.func_overload will automatically cause any non-multibyte-safe functions to use their multibyte-safe counterparts.

URLs with UTF-8 / Non-ASCII Characters

When determining the URL for a web page, you often want to use keywords that accurately describe the page’s content. Sometimes, these keywords aren’t in English and contain accented characters. One thing you can do is choose one URL to be the canonical URL and create a redirect to that URL from another that contains the ascii-equivalent version of the words, e.g.

Canonical: http://www.somedomain.com/nǐhǎo

Redirects:

  • http://www.somedomain.com/nihao
  • http://www.somedomain.com/你好

Sublime Text 2 Shortcuts

Show PHP function list
  • CTRL+r
Clean up code
  • CTRL+ALT+t : HTMLTidy
  • CTRL+ALT+E : Encode special characters
Tag completion, folding
  • CTRL+. : close tag
  • CTRL+SHIFT+[ : Fold Code
  • CTRL+t : Fold Tag Attributes
  • <tag + TAB = autocompletion, e.g. <a + TAB = <a href=””></a>
  • <tag> + ALT + . = autocompletion, eg. <a> + ALT + . = <a></a>
Find in file(s)
  • CTRL+F : Find in file
  • CTRL+SHIFT+F : Find in files (or right click on folder and click Find in Folder)
  • CTRL+H : Find and replace in file

HOSTS File: Change an External Domain to Point Somewhere Else

If you update your hosts file to point a domain to another location, accessing that domain will take you to your new destination. For example, in Windows, your hosts file is at

C:WindowsSystem32driversetchosts

If you add the following:

127.0.0.1 www.google.com

and then open your browser and go to www.google.com, you will not see Google’s home page but rather your local host index page.  This can be handy when you want to disable one javascript include in a page that you don’t have access to. By pointing the external javascript domain to your local host, a 404 not found will be triggered which will prevent the code from running. Everything else, including other references to external javascript files,  in the page will still continue to execute.