Running Freepbx as www-data

I’m trying to run FreePBX as Apache user, I already added asterisk user to www-data group and I was able to access the webGUI but when I click on admin panel and enter my credentials http:// pbx.local/admin/config.php is a blank page. Running apache as asterisk user is not an option

Ubuntu Server 14
FrePBX 12.0.43
Asterisk 13

Apache Error log:

PHP Fatal error: Uncaught exception ‘Exception’ with message ‘Trying to edit user asterisk, when I’m running as www-data’ in /var/www/pbx.local/public_html/admin/libraries/BMO/Cron.class.php:50\nStack trace:\n#0 /var/www/pbx.local/public_html/admin/libraries/BMO/Self_Helper.class.php(116): Cron->__construct(Object(FreePBX))\n#1 /var/www/pbx.local/public_html/admin/libraries/BMO/Self_Helper.class.php(36): Self_Helper->autoLoad(‘Cron’)\n#2 /var/www/pbx.local/public_html/admin/libraries/BMO/FreePBX.class.php(84): Self_Helper->__get(‘Cron’)\n#3 /var/www/pbx.local/public_html/admin/modules/sipstation/Sipstation.class.php(30): FreePBX::__callStatic(‘Cron’, Array)\n#4 /var/www/pbx.local/public_html/admin/modules/sipstation/Sipstation.class.php(30): FreePBX::Cron()\n#5 /var/www/pbx.local/public_html/admin/libraries/BMO/Self_Helper.class.php(116): FreePBX\modules\Sipstation->__construct(Object(OOBE))\n#6 /var/www/pbx.local/public_html/admin in /var/www/pbx.local/public_html/admin/libraries/BMO/Cron.class.php on line 50, referer: http:// pbx.local/admin/config.php

I think you are backwards. You want to add the www-data user to the asterisk group

I already did it, same result…any idea?

I am having the same problems trying to run with a non-asterisk web user (in my case user is called ‘pbx’). I’ve also tried adding the web user to the asterisk group but this makes no difference as a user isn’t allowed to edit the crontab of another user.

Here is the error I am getting despite both AMPASTERISKWEBGROUP and AMPASTERISKWEBUSER in /etc/amportal.conf being set to ‘pbx’:

[01-Jul-2015 22:09:04 UTC] PHP Fatal error:  Uncaught exception 'Exception' with message 'Trying to edit user asterisk, when I'm running as pbx' in /home/pbx/public_html/admin/libraries/BMO/Cron.class.php:50
Stack trace:
#0 /home/pbx/public_html/admin/libraries/BMO/Self_Helper.class.php(116): Cron->__construct(Object(FreePBX))
#1 /home/pbx/public_html/admin/libraries/BMO/Self_Helper.class.php(36): Self_Helper->autoLoad('Cron')
#2 /home/pbx/public_html/admin/libraries/BMO/FreePBX.class.php(84): Self_Helper->__get('Cron')
#3 /home/pbx/public_html/admin/modules/sipstation/Sipstation.class.php(30): FreePBX::__callStatic('Cron', Array)
#4 /home/pbx/public_html/admin/modules/sipstation/Sipstation.class.php(30): FreePBX::Cron()
#5 /home/pbx/public_html/admin/libraries/BMO/Self_Helper.class.php(116): FreePBX\modules\Sipstation->__construct(Object(OOBE))
#6 /home/pbx/public_html/admin/libraries/BMO/Self_Helper.class.php(60): Self_Helper->autoLoad('Sipstation')
#7 /home/pbx/public_html/admin/libraries/BMO/OOBE.class.php(125): Self_Helper->injectClass('Sipstation' in /home/pbx/public_html/admin/libraries/BMO/Cron.class.php on line 50

Several other users have reported similar problems while trying to run the web interface with anything other than asterisk as the user [put http:// on these as I can’t post links as new user]:

The Asterisk service itself is running as asterisk user. FreePBX is 12.0.43 running on Ubuntu 14.04.

Looking at the code I found

 //file: Cron.class.php
public function __construct($var1 = 'asterisk', $var2 = 'asterisk') {
    	// Lets figure out if we were given a FreePBX Object, or a user.
    	if (is_object($var1)) {
    		$this->freepbx = $var1;
    		$user = $var2;
    	} else {
    		$user = $var1;
    	$this->user = $user;
    	// If we're not root, we can only edit our own cron.
    	if (posix_geteuid() != 0) {
    		$userArray = posix_getpwuid(posix_geteuid());
    		if ($userArray['name'] != $user)
    			throw new Exception("Trying to edit user $user, when I'm running as ".$userArray['name']);
    	} else {
    		$this->uoption = "-u ".$this->user." ";

setting $var1 to www-data should do the trick but this will break on future updates…

1 Like

Thanks for finding that.

I think the problem is in admin/modules/sipstation/Sipstation.class.php on line 30:


The constructor for the Cron class is being called without any arguments, which is why it defaults to ‘asterisk’ value that you have highlighted.

So we need to change Sipstation so that it calls the Cron() constructor with the name of the web user. I’ll have a crack at this myself but do post here if you have any luck in the meantime!

Errrr, actually the Sipstation module isn’t open source, and is only in the FreePBX distribution because Schmooze Com, Inc sponsor the project. So probably best to disable the Sipstation module via the command line:

amportal a ma disable sipstation

This works for me and stuff actually loads.

1 Like

Well noted, and actually not just the distro, many published recipes here include the inappropriate and fateful “amportal a m installall” this can actually “get in your way” later if you are not Centos based or are concerned in any way about being actually truly “Open Source” so please “caveate emptor” . . . . :smile:

I can now access the menus but trying to ‘Apply config’ now generates another cron error:

Tried to run Dashboard->doDialplanHook(), it threw an exception. I received Trying to edit user asterisk, when I'm running as pbx
Continuing. This is a bug
Please update your modules and reload Asterisk by browsing to your server.

doDialPlanHook() is trying to do doing Cron maintenance, but again doesn’t specify a username so the ‘asterisk’ default applies:

public function doDialplanHook(&$ext, $engine, $priority) {
        // [removed irrelevant bits of function]

        // Also, while we're here, we should check that our cronjob is
        // still there.

        $file = __DIR__."/".$this->sched;
        $cmd = "[ -e $file ] && $file";

        if (!$this->Cron->checkLine("* * * * * $cmd")) {
                // It's not!
                $this->Cron->addLine("* * * * * $cmd");

Searching the code with grep it looks like it’s only Dashboard and Sipstation classes which are affected.

Is it best to fix Sipstation and Dashboard … or change the Cron class so that it defaults to edit cron as the web user specified in AMPASTERISKWEBUSER?