Sharing how to run scripts manually

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);
2 Likes

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

+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)

1 Like

Absolutely correct. I always forget that I usually ā€œsu asteriskā€ before doing these types of things.

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.

2 Likes

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.