Fixing OpenSSL on WordPress Windows PHP 5.6+

Background:

i ran into OpenSSL errors during the Disqus plugin setup.
there’s tons of hits suggesting various solutions, below is the very simple solution that worked for me…

Sample error messages:

SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Failed to enable crypto in ...

TL;DR:

  1. download latest cacert.pem
  2. place it in a pertinent folder (e.g. $\wp-includes\certificates)
  3. edit your php.ini > openssl.cafile={full path to cacert.pem}

PHP SQL Server blob hosting

from here
see this post for sql server driver downloads
 

downloadPDF.php

<?php
header('Content-type: application/pdf');
// leave this out to open directly in browser: header('Content-Disposition: attachment; filename="my.pdf"');
include("SQLConnect.php");
$sql = "select InvoiceDocument from SalesInvoicePDF where InvoiceID = '123'";
$stmt = sqlsrv_query($conn, $sql);
if ( sqlsrv_fetch($stmt) )
{
    //this pulls the first field via "0"
    $data = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
    // write binary sql stream directly to http response
    fpassthru($data);
}
?>

SQLConnect.php

<?php
// DB connection info
$host = "servername";
$user = "user";
$pwd = "pwd";
$db = "database";
// Connect to database.
try {
  /*
  $connPdo = new PDO( "sqlsrv:Server= $host ; Database = $db ", $user, $pwd);
  $connPdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    */

  $conn = sqlsrv_connect($host, array("Database"=>$db, "UID"=>$user, "PWD"=>$pwd));
}
catch(Exception $e){
   die(var_dump($e));
}
?>

SQL Server PDO PHP7

  1. get the DLL – grab latest x64.zip
  2. add to your php.ini extension list:
    [ExtensionList]
    extension=php_pdo_sqlsrv_7_nts.dll
    
  3. here’s sample call code:
    <?php
    
    try {
         $conn = new PDO( "sqlsrv:Server= ip_address; Database = mydb ", $user, $pwd);
         $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    }
    catch(Exception $e){
         die(var_dump($e));
    }
    
    $stmt = $conn->query($qry);
    $result = $stmt->fetchAll();
    $row = $result[0];
    $colval = $row["fieldname"];
    ?>
    

PHP7 Debugging under Visual Studio 2015

  1. I suggest installing PHP7 through the IIS Web Platform Installer so it does the Handler Mapping vs having to mess with that manually (i.e. assigning PHP extension to php-cgi.exe) – but there’s a lot of guides out there for doing that yourself if you want.
  2. That’ll probably leave you with a slightly older version so then just go install latest PHP7 bits over the top – we want the non-thread-safe (NTS) builds when running under IIS FastCGI (supposedly the most performant approach)
  3. Ideally you don’t mind springing for PHP Tools for Visual Studio… this package provides comforts like Intellisense and PHP project templates… and I also noticed that PHP Tools automatically configures XDebug debugging bits for us which is nice vs figuring that out manually (at least the first time)… turns out its just some php.ini settings (see below).
  4. so basically you just launch site in Visual Studio debug (F5) and PHP Tools will ask you if you want it to configure debugging for you… the brief wrinkle here is that it then went off and installed/configured PHP5.x… hence the main reason I’m posting this – to affirm we can then indeed just go copy the pertinent settings from the PHP5.ini to our PHP7.ini…
  5. if you go look at the php5.ini that PHP Tools set up you’ll see the following settings added at the bottom (for me it went under: C:\Program Files (x86)\iis express\PHP\v5.6):
    [XDEBUG]
    zend_extension=”C:\Program Files (x86)\IIS Express\PHP\v5.6\ext\php_xdebug.dll”
    xdebug.remote_enable = on
    xdebug.remote_handler = dbgp
    xdebug.remote_host = 127.0.0.1
    xdebug.remote_port = 9000
    xdebug.remote_mode = req
  6. so then we need to go get xdebug for php7 (again, the non-thread-safe version, i believe) and drop that DLL it in your PHP7\ext folder (mine was here: C:\Program Files\PHP\v7.0\ext)
  7. and lastly just copy/paste those same settings into php7.ini and tweak the xdebug path

Now you can go set breakpoints and step debug.
 

Check out your web project properties page and you can see how PHP5 vs PHP7 is chosen as the runtime, easy peasey!

 

Last note: I had some screwy behavior where certain files wouldn’t take breakpoints but would still step thru if I broke in a different file earlier in the call stack… I think this went away after restarting VS and/or making sure i had a clean rebuild.