Sharing how to run scripts manually

freepbx
development
Tags: #<Tag:0x00007f4f4233bd80> #<Tag:0x00007f4f4233bc18>

(Sholinaty) #1

i struggled with this, but during API work it was helpful. hoping this post will help others in a similar situation.

make a new file, i.e. /tmp/test.php

and you can test out scripts / API calls on demand via
sudo -u asterisk php /tmp/test.php

contents should be similar to:

<?php
include '/etc/freepbx.conf';
$FreePBX = FreePBX::Create();

$user=$FreePBX->Core->getUser("5133");
echo print_r($user);

(Jared Busch) #2

More better, always run it as the apache owner. In the case of FreePBX, that means as Asterisk

sudo -u asterisk php /tmp/test.hhp

#3

+1 to that, seen that confuse so many folks here, you are only asterisk when you tell the OS you are asterisk, when you are asterisk you have your own ‘environment’ which can be wildly diverse to what you thought (env)


(Sholinaty) #4

Absolutely correct. I always forget that I usually “su asterisk” before doing these types of things.


(Simon Telephonics) #5

There are a few examples of PHP command line scripts in the forum archives. Thanks for sharing this. I would love to see more people sharing these kinds of tips and little utilities.