Getting our PHP Samples Running on Windows
As I said in my introduction, I’m a Zend Certified PHP Engineer. I may not have mentioned that, like many developers, I tend to trust my abilities probably more than I should, jump into projects head first, and only start to read the fine manual when something doesn’t work as expected.
Setting up my Avalara laptop, one of the first things I did was install a basic WAMP stack (like LAMP but with Windows). That may be sacrilege to some, but it works.
Yup, there’s no
vendor folder in there. Where did that come from? What had I missed?
Step 1: You have to install our PHP samples
It will set up Composer and make sure it’s in your Windows path. If you had any command windows open, they will not know about the changes to the Windows path. You’ll need to open a new one in the directory you downloaded our samples to. I recommend this handy shortcut:
In the File manager, hold down SHIFT while right-clicking the directory where your copy of the Avalara code is. You’ll see an option to “Open a command window here.” Choose it.
You can then run “
composer install” in the command window.
After that, you should be able to run the sample code… as long as you’ve set up your PHP installation with the proper root certificates so you can negotiate secure connections with HTTPS hosts. We provide a recommendation on where to get and how to install the proper SSL root certificate to communicate with our servers.
But I am a certified PHP developer and I know what I’m doing, right? So I installed the Mozilla root certificate bundle, saved it as
cacert.pem in my PHP installation directory, and linked it up in my PHP installation by adding the following to the end of my
I downloaded a copy of Google’s homepage via a cURL call in PHP to test it. Boom. Ready to go.
I ran the PingTest sample again and it failed with multiple warnings like this:
Step 2: Make sure you install our recommended root certificate
A little debugging showed that despite having the root certificate bundle, I didn’t have the root certificate Avalara recommends. D’oh! I was getting that error because the HTTPS negotiation failed and there was no JSON response being returned.
So I went back to our instructions, added the recommended certificate to the bundle (cut and pasted the text into the end of the
cacert.pem file), and tried again.
Step 3: Put your data in configuration.php
The configuration.php file is in the Samples directory like the PingTest sample. You should have received an email with your account number and license key. If you didn’t or lost it, you can get a new key from the settings tab of your Developer Console.
And you’re on your way.