1

I am trying to use Scilab through PHP on my server like described in this document.

I am running Ubuntu 16.04. I have an Apache server running. I installed Scilab with apt-get install scilab. I can successfully write scilab code like:

scilab -nwni -nb -e "m=[1 2 3; 3 4 5];disp(m);exit"

So now I am trying to execute it from PHP. I tried the examples in the document. For instance:

<?php
    exec('scilab -nwni -nb -e "m=[1 2 3; 3 4 5];disp(m);exit;"', $output);
    print_r($output);
?>

But I always get:

Error: Impossible to define SCIHOME environment variable.
SCIHOME not defined.

I don't know what I am doing wrong and how to fix it...

Any help would be greatly appreciated !

Sharcoux
  • 179
  • 2
  • 10

3 Answers3

1

I had the same problem. Try:

exec('sudo scilab -nwni -nb -e "m=[1 2 3; 3 4 5];disp(m);exit;" 2>&1', $output);
print_r($output); 

Run sudo via www-data user is possible, if you add permission, try:

sudo visudo -f /etc/sudoers

and add to the end of file

 www-data  ALL=(ALL)  NOPASSWD:  /usr/bin/scilab, /usr/bin/scilab-cli, /usr/bin/scilab-adv-cli

I'm not sure, if you have to add all these scilab files.. maybe only scilab.

ssemrak
  • 11
  • 1
  • Ok, so it works. Thanks a lot! But why would I need to use sudo here whereas I don't need it if I use scilab from the command line ? – Sharcoux Mar 29 '17 at 09:55
  • When you run scilab in command line, your login is different. From website it's www-data, in command line maybe root, admin, sharcoux... Anyway, your solution below is good! – ssemrak Apr 02 '17 at 16:37
  • Oh, ok. Thanks anyway. I learned something with your post (Didn't know about editing sudoers). Sorry I can't give you more than a +1. I think my final answer is better for further readers regarding the problem I described. – Sharcoux Apr 03 '17 at 18:06
0

I recall something about the possibility of multiple .ini files for php which means that cli execution and gateway execution may work differently or unexpectedly because they use different ini files and / or acquire different permissions due to the user:group executing them. Does the user:group trying to execute in the second instance have permission to write to the environment, and are you getting behaviour governed by the .ini file you think you are getting it from.

Just a thought.

  • About the permissions, correct me if I'm wrong, but on default configuration, an exec command from a php script on apache server should be executed by www-data:www-data. The home for this user should be /var/www/ and this folder belongs to www-data. I'm not sure what could prevent this user to write to the environment. – Sharcoux Jan 09 '17 at 23:06
  • About ini files... I have no idea what you are talking about. apache configuration comes from the conf-enabled and sites-enables folders. What is the .ini file you are mentioning. What is it supposed to be doing ? What is the usual path to this file ? – Sharcoux Jan 09 '17 at 23:08
  • I mean the php.ini file - which in my environment has /etc/php/cli -a config file which determines function under the command line environment - as well as /etc/php/fpm - which in my case determines function under the fpm manager. But looking at the actual issue- what process is returning the error message: PHP or SCILAB? When did the process try and set the environment variable? did it fail at this execution, or at a prior time? Are there any SCILAB execution logs that help? – Cammi Mitchell Jan 12 '17 at 09:26
  • I find the error message in apache2/error.log. For what I understand, it means that it comes from php process. I don't find any scilab logs. It fails at each request on the webpage that contains the php code I posted in my question. – Sharcoux Feb 01 '17 at 09:44
  • But PHP would have no reason to try and define that vairiable, so it has to be coming from SCILAB via php's execution environment. You may be able to 'cheat' and pre-define the environment variable using `putenv("SCIHOME=/the/path/to/working/folder");` with the requisite limitations on putenv? – Cammi Mitchell Feb 13 '17 at 13:51
0

Ok, I finally solved the issue. I'm just stupid. You just need to set the variable manually. I already tried it this way but made a mistake in the variable name...

exec('SCIHOME=/var/www/ scilab -nwni -nb -e "m=[1 2 3; 3 4 5];disp(m);exit;" 2>&1', $output);
Sharcoux
  • 179
  • 2
  • 10