Featured Post

Organize and rename photos by EXIF data with PowerShell

This PowerShell script organizes and renames all photos in a selected folder using EXIF data. It will also create thumbnails of the images i...

Thursday, May 15, 2014

Guide for creating the perfect Windows Apache MySQL PHP (WAMP) Dev machine

You don't need any pre-built dev environment for Windows such as EasyPHP, UniformServer, XAMPP, Z-WAMP, WampServer or any other kind of WAMP that gets spun up, neglected and eventually abandoned.

It is much better to install the components you need and manage them as they were intended rather than rely on some 3rd party tool to re-invent the wheel.

If you're thinking "but I want to save time..." stop right there and realize that this will save you time in the long run and bring you the ability to do anything if not more than what any pre-built bundle can offer.

It really doesn't take long to do this, especially following this guide!

Getting Started

We will install:
  • Apache
  • PHP
  • MySQL
  1. Create a folder to house all the services we are about to install. I create it on the root drive  to ensure a short path with no spaces, preferably a secondary drive with lots of free space. My folder is E:\Services
  2. Create a folder for each service we will install, these folders will house different versions of each service to allow for switching of versions such as PHP4, PHP5, PHP5.5 etc.
    1. E:\Services\Apache
    2. E:\Services\MySQL
    3. E:\Services\PHP
Note: Even though you may be using a 64-bit machine, it is recommended to install the 32-bit versions of both Apache and PHP as some issues may occur otherwise with some modules etc. that do not yet support 64-bit.

Apache

  1. Download whichever version of Apache HTTPD Server you want from: Closest Apache Download Mirror but if you are looking for v2.4 you will need to get it from Apache Lounge.
    1. I will be using: Apache 2.4 binaries VC11 IPv6 Crypto apr-1.5.0 apr-util-1.5.3 apr-iconv-1.2.1 openssl-1.0.1g zlib-1.2.8 pcre-8.34 libxml2-2.9.1 lua-5.1.5 expat-2.1.0
  2. BEFORE YOU EXTRACT THE DOWNLOAD be sure to Right-Click on the file, go to Properties and on the bottom if you see an Unblock button, click it (then OK)! This will ensure all files are trusted when you unzip it otherwise you could run into problems later.
  3. Extract the download and move the contents of the Apache24 folder into your Apache services folder, retaining the version number in the folder for future reference such as:
    1. E:\Services\Apache\httpd-2.4.9-win32-VC11
      1. Inside this folder should be many folders such as bin, conf, modules
  4. Now edit the configuration file: E:\Services\Apache\httpd-2.4.9-win32-VC11\conf\httpd.conf
    1. NOTE: Where filenames are specified, you must use forward slashes 
    2. instead of backslashes (e.g., "c:/apache" instead of "c:\apache")
    3. Search for "ServerRoot" and set the value appropriately, for example:
      1. ServerRoot "E:/Services/Apache/httpd-2.4.9-win32-VC11"
    4. Search for "DocumentRoot" and set the values appropriately, for example:
      1. DocumentRoot "E:/Services/Apache/httpd-2.4.9-win32-VC11/htdocs"
      2. <Directory "E:/Services/Apache/httpd-2.4.9-win32-VC11/htdocs">
    5. Search for "ScriptAlias" and set the value appropriately, for example:
      1. ScriptAlias /cgi-bin/ "E:/Services/Apache/httpd-2.4.9-win32-VC11/cgi-bin/"
      2. <Directory "E:/Services/Apache/httpd-2.4.9-win32-VC11/cgi-bin">
    6. Uncomment (remove the # in front) the following line, this will allow for simple management of your project websites (virtual hosts):
      1. Include conf/extra/httpd-vhosts.conf
  5. You can either run httpd.exe whenever you need this version of Apache, otherwise you can install it as a Service and set it to Automatic start if you use it regularly.
    1. Install as service: Open Command Prompt and change directories to the apache bin folder. Run the following command to install it as a service with a unique name:
      1. C:\Windows\System32>E:
      2. E:\>cd E:\Services\Apache\httpd-2.4.9-win32-VC11\bin
      3. E:\Services\Apache\httpd-2.4.9-win32-VC11\bin>httpd.exe -k install -n httpd-2.4.9-win32-VC11
  6. Known Issues:
    1. AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host.example.com] does not exist
      1. This is due to the conf/extra/vhost.conf file we uncommented in the httpd.conf. You will need to configure your vhost.conf file appropriately to point to your project folders as needed. Otherwise you can simply remove or comment out the vhost section until you need it.
    2. AH00558: httpd.exe: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
      1. This can be safely ignored
    3. (OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions.  : AH00072: make_sock: could not bind to address [::]:80
      1. This is due to another service already listening on port 80. Either change your existing service configuration to use another port, or change your new httpd.conf Listen 80 setting to a unique port to run multiple Apache services simultaneously.

PHP

  1. Download whichever version of PHP you want from: windows.php.net
    1. I will be using VC11 x86 Non Thread Safe
    2. Note: x64 versions should be avoided even if you are on x64
  2. BEFORE YOU EXTRACT THE DOWNLOAD be sure to Right-Click on the file, go to Properties and on the bottom if you see an Unblock button, click it (then OK)! This will ensure all files are trusted when you unzip it otherwise you could run into problems later.
  3. Extract the download and move the php folder into your PHP services folder, retaining the version number in the folder for future reference such as:
    1. E:\Services\PHP\php-5.5.12-nts-Win32-VC11-x86
      1. Inside this folder should be folders such as dev, ext, extras
  4. Now copy the example php.ini-development file to php.ini file: E:\Services\PHP\php-5.5.12-nts-Win32-VC11-x86\php.ini and edit the php.ini file:
    1. Search for "extension_dir" and uncomment (remove the leading ;) this line:
      1. extension_dir = "ext"
  5. Now we must tell Apache to use PHP, only we want to use the FastCGI module to do this (recommended) so first download the module:
    1. Download the Apache 2.4 Modules VC11 from Apache Lounge.
      1. I will be using modules-2.4-win32-VC11
    2. BEFORE YOU EXTRACT THE DOWNLOAD be sure to Right-Click on the file, go to Properties and on the bottom if you see an Unblock button, click it (then OK)! This will ensure all files are trusted when you unzip it otherwise you could run into problems later.
    3. Extract the download to a temporary location
    4. Drill down the folder structure to find the mod_fcgid.so file
      1. modules-2.4-win32-VC11\mod_fcgid-2.3.9\mod_fcgid\mod_fcgid.so
    5. Copy the file to your httpd\modules folder:
      1. E:\Services\Apache\httpd-2.4.9-win32-VC11\modules\mod_fcgid.so
  6. Edit the Apache configuration file: E:\Services\Apache\httpd-2.4.9-win32-VC11\conf\httpd.conf
    1. At the end of the file, paste the following (update the PHP paths appropriately):
LoadModule fcgid_module modules/mod_fcgid.so
# Where is your php.ini file?
FcgidInitialEnv PHPRC "E:/Services/PHP/php-5.5.12-nts-Win32-VC11-x86"
AddHandler fcgid-script .php
FcgidWrapper "E:/Services/PHP/php-5.5.12-nts-Win32-VC11-x86/php-cgi.exe" .php

Now, restart the Apache service and you will be able to serve PHP files.

MySQL

  1. Download the manual install ZIP Archive from http://dev.mysql.com/downloads/mysql/
    1. I will be using Windows (x86, 64-bit), ZIP Archive
  2. BEFORE YOU EXTRACT THE DOWNLOAD be sure to Right-Click on the file, go to Properties and on the bottom if you see an Unblock button, click it (then OK)! This will ensure all files are trusted when you unzip it otherwise you could run into problems later.
  3. Extract the download and move the mysql folder into your MySQL services folder, retaining the version number in the folder for future reference such as:
    1. E:\Services\MySQL\mysql-5.6.17-winx64
      1. Inside this folder should be folders such as bin, data, docs
  4. Now copy the example my-default.ini file to my.ini file: E:\Services\MySQL\mysql-5.6.17-winx64\my.ini
  5. Install as service: Open Command Prompt and change directories to the mysql bin folder. Run the following command to install it as a service with a unique name:
    1. C:\Windows\System32>E:
    2. E:\>cd E:\Services\MySQL\mysql-5.6.17-winx64\bin
    3. E:\Services\MySQL\mysql-5.6.17-winx64\bin>mysqld --install MySQL5.6.17 --defaults-file=E:\Services\MySQL\mysql-5.6.17-winx64\my.ini
  6. Finally, start the service:
    1. net start MySQL5.6.17
Note: After MySQL is installed, I recommend using the MySQL Workbench to connect to the service and manage users, databases, queries etc.

Now What?

Now you just need to configure your Virtual Hosts (httpd/conf/extra/httpd-vhosts.conf) to serve content out of your projects folder, wherever that may be. Otherwise you can simply host 1 site at a time out of the httpd/htdocs folder and browse to http://127.0.0.1/

How to test if PHP is working?

Create a file in your htdocs folder with a php extension such as "phpinfo.php"

Paste the following into the file:

<?php
phpinfo();
?>

Save the file, and browse to http://127.0.0.1/phpinfo.php

If you do not see a long output of PHP configuration settings, or you see error messages, check the Apache logs in httpd/logs for more information.
  • For 403 Forbidden message, ensure that your <Directory> configuration in Apache's httpd.conf has ExecCGI added to it's Options, for example:
<Directory "E:/Services/Apache/httpd-2.4.9-win32-VC11/htdocs">
    Options Indexes FollowSymLinks ExecCGI


Virtual Host Configuration

Example:

<VirtualHost *:80>
    ServerAdmin admin@test.com
    DocumentRoot "E:/Projects/test.com/public_html"
    ServerName dev.test.com
    ServerAlias dev.test.org dev.test.net
    
    ErrorLog "E:/Projects/test.com/logs/error.log"
    CustomLog "E:/Projects/test.com/logs/access.log" common
    
    DirectoryIndex index.html index.htm index.php
    
    <Directory "E:/Projects/test.com/private">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
    
    <Directory "E:/Projects/test.com/public_html">
        Options All
        AllowOverride All
        Require all granted
    </Directory>

</VirtualHost>

XDebug

  1. Download XDebug from http://xdebug.org/download.php be sure to get the version that matches your PHP (In my case PHP 5.5 VC11 (32 bit))
  2. Be sure to Right-Click on the file, go to Properties and on the bottom if you see an Unblock button, click it (then OK)! This will ensure the file is trusted otherwise you could run into problems later.
  3. Move the dll into the php\ext folder: E:\Services\PHP\php-5.5.12-nts-Win32-VC11-x86\ext\php_xdebug-2.2.5-5.5-vc11-nts.dll
  4. Edit the php.ini file E:\Services\PHP\php-5.5.12-nts-Win32-VC11-x86\php.ini
    1. Search for "extension=php" and at the end of the extension list, add the following:
; XDebug
zend_extension="E:\Services\PHP\php-5.5.12-nts-Win32-VC11-x86\ext\php_xdebug-2.2.5-5.5-vc11-nts.dll"

; XDebug Recommended settings:
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.default_enable=1
xdebug.auto_trace=on
xdebug.remote_log="E:\Services\XDebug.log"
xdebug.extended_info=1

; XDebug Remote Host/Port is where this server will try to send debug info to
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"

; XDebug These adjust the truncating limits of the var_dump data
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1

Now Restart Apache and use phpinfo() to ensure the XDebug is enabled

No comments:

Post a Comment