7
$\begingroup$

Since Mathematica is contained in Raspberry Pi 2, I can do the following in the terminal:

echo "2+2" | /usr/local/bin/math -batchinput -batchoutput

It outputs 4 correctly. But when I try it with php:

<?php
$math="echo '2+2' | /usr/local/bin/math -batchinput -batchoutput";
$handle = popen($math, "r");
$str=fread($handle,200);
echo $str;
?>

It says that

Mathematica cannot find a valid password.

I find the license for Mathematica, in

/opt/Wolfram/WolframEngine/10.0/Configuration/Licensing/mathpass

Does this mean that Mathematica needs another license for interface with php?

UPDATE

I have solved this by adding an active key and password for the user www-data, which will stored in /var/www/.WolframEngine/Licensing/mathpass.

$\endgroup$
  • 6
    $\begingroup$ Under what user account does the php interpreter run? You may need to add this account to the video group. $\endgroup$ – ilian Nov 10 '15 at 3:39
  • $\begingroup$ @ilian how to check the user for php interpreter? $\endgroup$ – van abel Nov 11 '15 at 9:03
  • $\begingroup$ I find the problem, when I login with sudo su www-data then math 2+2 ask me to active the product. $\endgroup$ – van abel Nov 11 '15 at 9:11
  • $\begingroup$ On a standard RPi install, the CLI version of Mathematica is wolfram not math. $\endgroup$ – bobthechemist Nov 11 '15 at 12:32
8
$\begingroup$

Mathematica on the Raspberry Pi already comes with a license preinstalled, however running it as a user with insufficient access privileges may result in a prompt for activation or a password.

Here is a slightly more detailed explanation of what is happening, which is also discussed on Wolfram Community.

Early in the kernel (or FrontEnd) startup, as part of a series of hardware checks, Mathematica needs to talk to the Broadcom VideoCore chip. The default permissions for device should be similar to

crw-rw---- 1 root video 250, 0 Oct 27 22:17 /dev/vchiq

For example, if the user is not a member of the video group, opening the device will fail, resulting in a different $MachineID which no longer matches the preinstalled password. Hence, the product will not be activated.

A good way to resolve this issue is to check the device permissions are as above, and add the non-privileged user to the video group

sudo usermod -a -G video www-data

I have solved this by adding an active key and password for the user www-data

Yes, this will also work, but is more expensive: it requires the Pi owner (or his organization) to have purchased a Mathematica license. That is not necessary on the Raspberry Pi.

$\endgroup$
  • $\begingroup$ It seems that if I add the user www-data to group video as you said, then I can execute math 2+2 for the user www-data without invalid passward warning, but to the web php code, it still returns the invalid password warning. $\endgroup$ – van abel Nov 12 '15 at 2:49
  • $\begingroup$ I missed Mathematica on the Raspberry Pi already comes with a license preinstalled, however running it as a user with insufficient access privileges may result in a prompt for activation or a password. Now everythins is fine, thank you very much. $\endgroup$ – Valery Feb 23 '18 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.