Script not running with legacy setup

Hi all,

I am trying to run my legacy setup which used to work earlier. The script starts without the problem. Permissions should be fine. The problem is the script and the web based gui can detect each other. When I kill the script with Ctrl+C I see that it is always hanging in the following place:

Jan 10 2019 00:43:57 Controller debug message: INFO MESSAGE 2: Sensor initialized: pin 15 28A4D7AD0900002B null
Jan 10 2019 00:43:58 Controller debug message: INFO MESSAGE 2: Sensor initialized: pin 15 28A4D7AD0900002B null
Jan 10 2019 00:43:59 Controller debug message: INFO MESSAGE 2: Sensor initialized: pin 15 28A4D7AD0900002B null
^CTraceback (most recent call last):
File “./”, line 455, in
conn, addr = s.accept()
File “/usr/lib/python2.7/”, line 206, in accept
sock, addr = self._sock.accept()

It seems to me they cant establish a socket communication between them. Any idea what might the problem be. I am using a PC under ubuntu instead of Pi.

I just saw this somewhere … there’s a note in socketmessage.php I think about uncommenting a line implementing php_sockets.dll through php.ini. Maybe? If I’m remembering correctly.

That is for Windows. I am running under Linux. It is for sure problem in the following line:

socket_connect($sock, “$GLOBALS[scriptPath]/BEERSOCKET”)

The file is there but I can’t figure out what is the problem.

Is the script path set correctly?
What are the permissions of the socket file?

The script and web interface communicate over a file socket. The script creates this socket and listens for connections from the web interface.

In the web interface, there is a config.php file for the default and a config_user.php.example file to override the default.

Rename that file to remove .example and change the directory if you have not installed the brewpi script repository in /home/brewpi.

Yes, this is correct.

This is also correct:
brewpi-script git:(legacy) ✗ ll
total 308K
-rwxrwxr-- 1 nexy nexy 3.0K Jan 10 00:55
-rwxrwxr-- 1 nexy nexy 3.2K Jan 10 01:00 autoSerial.pyc
-rwxrwxr-- 1 nexy nexy 6.3K Jan 10 00:55
-rwxrwxr-- 1 nexy nexy 5.8K Jan 10 01:00 backgroundserial.pyc
srwxrwxrwx 1 nexy nexy 0 Jan 11 07:47 BEERSOCKET

It has rwx permission. I am running this on Ubuntu on my PC. I am wondering if there is any prevention for apache user so that it cant access freely everything except /var/www/html.

Anything in the apache error logs?

I apologize … I think I read “PC” as “Windows” and that’s why I posted what I did.

Assuming you are running as ‘brewpi’ and have not changed a bunch of things at once, it looks as if your permissions and ownership are not consistent with a default setup:

pi@brewpi:/home/brewpi $ ls -al
total 320
drwxrwsr-x 8 brewpi brewpi  4096 Jan 11 05:u7121: 
drwxr-xr-x 4 root   root    4096 Jan  8 09:09 ..
-rw-rwxr-- 1 brewpi brewpi  2971 Jan  8 09:09
-rw-rwxr-- 1 brewpi brewpi  6410 Jan  8 09:09
srwxrwxrwx 1 brewpi brewpi     0 Jan 11 05:21 BEERSOCKET

You might try to run in the utils directory. While BEERSOCKET is rwx for world, one of the other scripts might not be reading properly. As Elco said, /var/log/apache2 often show us what’s happening. That’s been the source for me figuring out a lot of mistakes I’ve made.

Nothing in apache2 error log except debug prints i added. This is not assumed as a problem because if u cant access the socket it means the script is not running. PHP scripts always die with info which is shown in the web page. I believe the problem is in some apache config. Maybe raspbian distro is different in the sense of security.

I already did run fix permission script.

It looks as if your script path is not standard. Did you follow Elco’s tip to create/update the config.php?

1 Like

Yes. The thing is it used to work some months ago. The path is fine, something else is preventing apache to access.

So, I played a little bit and changed the source code to make a socket inside /var/www/html and it works now. I will update the final answer as soon as I get the answer from stackoverflow.

Are the group memberships correct? brewpi should be a member of www-data, brewpi:brewpi should own script path and www-data:www-data should own /var/www/html

Yes, that’s fine. I am now trying to figure out the following apache configuration:

<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied

<Directory /usr/share>
AllowOverride None
Require all granted

<Directory /home/brewpi/brewpi-script/>
Require all granted

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

Did you rename and change user_config.php to have schripPath /home/brewpi/brewpi-script instead of /home/brewpi as I suggested earlier?

Yes, this is everything correct. Another point, when i changed the user fir apache everything worked. I am quite sure that apache restricts access to arbitrary folders on the machine.