1

First things first: I was given the task to deploy a Drupal website on Azure.

Locally I use OS X running Apache and everything works ok. When I deploy the project to Azure, I get an error. After some debugging I isolated the error to this snippet of code:

private function getToken(){
    $ch = curl_init($this->host . $this->clientId . "&client_secret=" . $this->clientSecret);
    curl_setopt($ch,  CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json',));
    $response = json_decode(curl_exec($ch));
    curl_close($ch);
    $token = $response->access_token;
    dvm($response, $name = NULL);
    return $token;
}

dvm() is a Drupal Devel function, but suffice to say that's sort of print_r for Drupal on steroids.

The problem I'm getting is that for whatever reason, $result is coming back NULL. When I run the same code on my local machine and on a Linux/Debian box, all worked as expected (I get an Object as a result of the curl).

This leads to the conclusion that Azure is not liking something in this piece code. The problem is finding out what. Any ideas?

WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
  • please run phpinfo and check if curl is enabled, test the values of $this-> variables – Lucky Chingi Oct 20 '15 at 16:22
  • Curl is enabled. What do you mean by `$this-> variables`? Pardon my ignorance but I'm not an expert in PHP. – WagnerMatosUK Oct 20 '15 at 18:47
  • @LuckyChingi means you can check whether the variables you set in `curl_init` are not null or right. – Gary Liu Oct 21 '15 at 06:42
  • `$this->variables` are all set as expected. Is there a chance Azure is blocking the curl call to the external API? – WagnerMatosUK Oct 21 '15 at 08:29
  • Azure Web App will not block the curl call, we can test with the following code on Azure: `$ch = curl_init("www.bing.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); print($output); curl_close($ch); `. By the way, you can check your Api server whether has a white list, which may block the HTTP request from Azure Web App. – Gary Liu Oct 21 '15 at 09:19
  • @GaryLiu-MSFT Thanks for your reply. When you say "server whitelist" do you mean in my own code or within Azure configurable options (Unfortunately I don't have access to Azure control panel, which is managed by someone else within our business)? – WagnerMatosUK Oct 21 '15 at 13:21
  • Actually, I mean that your API server may have a white list which do not added your Azure endpoint in it, so the API server may block your request from Azure Web App. Here, the `$this->host` should be the url of you API server – Gary Liu Oct 21 '15 at 15:00
  • That's not applicable in our case (its a public API behind https). Any other ideas? – WagnerMatosUK Oct 21 '15 at 15:09

1 Answers1

3

For a prod environment, display_errors is set off in PHP runtime on Azure Web Apps. We can open the setting for debugging via change the build-in PHP configurations.

Here are simple steps:

1, Add a .user.ini file to your root directory.

2, Add configuration settings to the .user.ini file using the same syntax you would use in a php.ini file. With your demand, your .user.ini file would contain this text:

display_errors = On

3, Deploy your web app.

4, Restart the web app.

You can read official guide for more information.

Furthermore, we can login in the Kudu console of our websites to manage our sites. The URL of Kudu console should be like: https://{your_web_site_name}. scm.azurewebsites.net, and click Tools => Diagnostic dump to download the diagnostic logs.

Additional, we can use WebMatrix to directly modify your code on Azure Web Apps.

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Thanks for your help. Last issue I've got is to do with enabling email via php. Would you have any idea on how to get it to work? The error I'm getting would be resolved if I were to instal `sendmail` on Linux. How could I get it working on Azure? – WagnerMatosUK Oct 22 '15 at 11:36
  • 2
    As this problem is little relative with this thread, I suggest you to open a new thread, which will be benefit for other communities who have similar issue. – Gary Liu Oct 23 '15 at 01:12
  • The question title was "how to debug PHP on Azure", this answers a different question of "how to turn on errors" – pilavdzice Jun 26 '18 at 18:41
  • @pilavdzice, this is simple and general steps to change PHP configuration on Azure, including debug. turn on errors is a way for PHP debug. I don't know which way you'd like to debug PHP on Azure, and I found a post https://hajekj.net/2016/09/06/remotely-debugging-php-on-azure-web-apps-with-ngrok/ maybe can give you a different idea. – Gary Liu Jun 27 '18 at 01:40
  • I meant to turn on debugging you need to add something like this to the .user.ini: zend_extension = ".\bin\php_xdebug-2.2.1-5.3-vc9-nts.dll" xdebug.remote_host="192.168.whatever.whatever" xdebug.profiler_enable=1 xdebug.profiler_output_dir="D:\home\site\wwwroot\bin\xdebug_profiles" xdebug.profiler_enable_trigger=1 – pilavdzice Sep 27 '18 at 18:43
  • 1
    @GaryLiu-MSFT Yes you posted great steps to change PHP config, but the question asked how to enable debugging. PHP has a debugger called XDebug (and others). Debuggers have features that let you follow along the code in real time execution, measure performance, and other things. Displaying errors is NOT debugging. Changing PHP config is not all that is needed to enable debugging either. Since this wrong answer is marked correct no one is posting the more complex correct answer. – pilavdzice Jun 28 '19 at 18:16