I've previously written up my tribulations with (and reasons for) installing Apache HTTP Server on my Mac, and that decision (along with a recommendation from my colleague Cyrille) made my decision on which server-side API to choose - PHP. My first goal was simply to get the 3D viewer PHP sample we've posted on GitHub to work. (Thank you to iUX Labs for allowing us to post the code they wrote at our recent Hackathon in Shanghai). This goal has put me in the uncomfortable position of trying to get a non-trivial sample up and running when I know absolutely nothing about PHP (and I'm still pretty sketchy on Apache setup and general Unix terminal usage). I'm writing this up so that anyone in a similar situation can benefit from my pain - and hopefully will save the half day it took me to get up and running.
I'm still using my AMPPS installation, so installing PHP was easy - its part of AMPPS. I just had to change the PHP version to 5.4 or 5.5 (I chose 5.5). My problem was that, although I could easily get the PHP sample to run, every call from my localhost server to the Autodesk API server was failing - I couldn't even get my AccessToken.
Ok - that should be easy - I can debug the PHP code. How do I debug? Hmm - Not so easy. The most common way to debug PHP is to install Xdebug on your server along with a debugger (Eclipse or NetBeans for example, although I've started out using MacGDBp because it looked a bit simpler to setup).
I started looking into installing Xdebug, which was leading me down the same path as my Apache investigation - I was finding a long chain of stuff I had to install so I could install Xdebug. Here is a nice looking blog post on installing/configuring Xdebug that I found after I'd followed up a lot of dead ends.
Of course, then I realized that AMPPS comes with Xdebug pre-installed. You just have to add a few settings to your php.ini files. This forum post gives some step-by-step instructions. I also added an extra line ('xdebug.remote_autostart=1') to the ini file to ensure Xdebug would immediately start when my PHP ran (and would then break on the first line of code).
Now with MacGDBp running, any PHP code executed on my server automatically attaches to MacGDBp and breaks - waiting for me to step through the code. So far so good.
Now I could debug the code, I could see that my authentication call was returning a null AccessToken. Being new to PHP, it took me way too long to realize that my HTTP call was returning an error:
SSL certificate problem: unable to get local issuer certificate
(Getting to this point is what took most of my time).
Applying the golden rule that if I'm having a problem someone else has probably already posted a solution somewhere, I slipped that error message into a google search, and (as if by magic!) the answer appears.
It turns out that PHP.ini leaves an important line commented out that is required of you're using SSL. The solution is to create or download a list of certificate authorities you want your server to trust and uncomment and complete the line:
to point to your certificate authority list. Here's the StackOverflow post where I found the answer.
And - hey presto - everything is working as expected.
And now I've got the sample to run I have to go back and start pearnign some PHP basics :-).