skip to Main Content

Update: by redirecting stderr from php exec, I can now see that running maxima produces a segmentation fault, increasing the likelihood that this is in fact a bug.

Important note: this used to work perfectly on older versions of PHP/Ubuntu.

I’m trying to get PHP exec() (or shell_exec() ) to redirect the output (stdout) of a maxima call to a text file. All I get is an empty file.

I have tried the simplest of commands:

exec( "maxima -b /var/www/tmpIn.txt > /var/www/tmp/tmpOut.txt"); 

(tmpIn.txt just contains the text "1+1;", all permissions are set properly).

If I paste this command in the terminal it will work fine, php’s exec() will only produce an empty file. However, this is the case only for the maxima binary; cat/echo/ls etc. redirect just fine.

To me this seems exceedingly strange especially as this code used to work well as mentioned. Is there any workaround for this "bug"?

System info:
ubuntu 20.04
PHP version 7.4 on Apache2
Maxima 5.43.2
bash

2

Answers


  1. Chosen as BEST ANSWER

    I have finally resolved the issue by changing the Apache 2 user from www-data to another user on the machine, so that user was restricted in some way. I believe this should still be considered a bug as the Segmentation Fault message should have been replaced by an actual error message in case those restrictions were intentional.

    Update: the new apache2 user (set from envvars file) must have a home directory (e.g. added through adduser and not useradd) otherwise the problem will persist. If you set this to an active user the server might shutdown if that user is logged in/out externally. Those findings might point to a bug in maxima assuming a user directory or similar. I'm not sure if going the other way around (adding a home directory for www-data) would resolve this bug or not.


  2. assuming that the path of installation is /usr/local/maxima5.43.2

    please try using the following:

    exec( "/usr/local/maxima5.43.2/maxima -b /var/www/tmpIn.txt > /var/www/tmp/tmpOut.txt"); 
    

    Please adjust the path according to your own installation path . In addition, please add read and execute permission of maxima to apache , and also try using sudo to run

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search