Webhook POST to PHP script on own Apache server (Debian OS)

Hi,
the last couple of hours I tried to solve the following problem:
1.Capture data -> 2. Particle.Publish() -> 3. Webhook POST to own local Apache server with PHP 5

1 & 2 are working fine: Console.particle.io achnowledges the Particle.Publish() command and sends out the webhook. According to console.particle.io my server responds with 200 OK, but I cannot work with my $_POST variable in the PHP script:

PHP Code:

$data = $_POST['data'];
$json = json_encode($_POST);
file_put_contents('path/to/file.txt',$data,FILE_APPEND);

I added “file_put_contents” to have a debug option to see if the .php file gets opened by the webhook, but it does not, the file is never written.
The apache server is working fine, I can open webpages on it and execute other php scripts, even from the outside, so closed ports shouldn’t be an issue.

Additional info I just found out:
If I add

echo $json

to the PHP script, console.particle.io receives the data I want to write to a file as a http response, e.g:

But the file won’t be created, there is no trace of it.

I am sorry, but this the first time working with POST, probably this isn’t even a Particle question, but I don’t even know where to start, so I’ll give it a try here :slight_smile:

Thanks for any help!

Marc

Writing to a file might be a permissions problem. A PHP script running within Apache may not have write permissions to the directory that you are writing to when you call it from the command line.

Thank you very much! I just needed to chown the folder to www-data… oh gosh.