Reloading asterisk within PHP?


I’ve set up an Asterisk 1.2beta with Realtime (MySQL). A new registration has to be written to file (sip.conf) and IMHO cannot be written to database. But if I write to file I have to do an “asterisk -rx reload”. With a system("/usr/sbin/asterisk -rx reload") I just get a “Unable to connect to remote asterisk (does /var/run/asterisk.ctl exist?)”. From commandline everything works as expected. Maybe I have to set some environment variables, I don’t know. Can you help me?


I have been running into that issue with the 1.2 beta of Asterisk and have not seen it with other versions before. Have not had a chance to search the mailing lists/bug list to see what it may be.

As for the title of this thread it is possible to use and the php-astmanager library to do a reload within PHP:


Thank you for the reply. Just got a solution, I was really blind…

The thing with saving this part to file is not really good, would like to see it in database like all the other stuff. But who cares, I got it working that’s what I wanted to do :smile:.

The apache user is www-data, so this users isn’t able to use my asterisk (which runs as root - yes I know, user asterisk was better). So just chmod u+s /usr/sbin/asterisk (or whereever your binary resides). Yes, this may be a big security hole, but it works. Better solutions are appreciated :smile:.

And now I can write new carrier to file and reload asterisk:

                                        # Open file for writing
                                        $rHandle = fopen($sURI, "w");

                                        # 1st line: Comment
                                        fputs($rHandle, "; $sComment");
                                        # 2ns line: data as shown above
                                        fputs($rHandle, $sCarrier);

                                        # Close file, freeing ressources

                                        # Reload Asterisk to load the written file :-(
                                        $back=`/usr/sbin/asterisk -rx reload`;