0

I have meshlab installed in my machine running Ubuntu 14.04 OS. I can access it from command line using meshlabserver command. But problem arises whenever I try to call it from a php script using the command

<?php
system('meshlabserver 2>&1');
?>

It shows the error meshlabserver: cannot connect to X server. After going through a few websites I did the following things:

I moved the meshlabserver executable from /usr/bin to /usr/local/bin and gave it executable permissions using

sudo chmod a+x meshlabserver

But when I ran the whoami command from my php script (calling the meshlabserver), it showed www-data. So I gave executable permissions for all users to the meshlabserver using

sudo chmod 777 /usr/local/bin/meshlabserver

But still it is showing the same meshlabserver: cannot connect to X server error. meshlabserver comamnd is working fine when ran from the command line.

I really need to call meshlab from the php script for my website. Thus any help would be highly appreciated. Thanks in advance.

Koustav
  • 733
  • 1
  • 6
  • 21

2 Answers2

0

It seems the php script can't access your display variable. If you logged in via ssh remember to tunnel your X-server via 'ssh -X ...' Your second option is to create a virtual frame buffer using Xvfb and redirect the display variable to it:

export DISPLAY=:100.0 Xvfb :100 &

Note the ampersand for the second command as Xvfb needs to be running in the background.

  • It didn't work. However I found an alternative command to perform the task and need not invoke Meshlabserver any longer. Thanks for your reply. – Koustav Nov 25 '14 at 05:10
  • Unfortunately, `meshlab` requires an OpenGL context, which `Xvfb` apparently cannot supply. Consequently, the second option does not work. – David Zwicker Jan 10 '18 at 14:30
0

a combo of prior answers works for me: ssh -X, as well as export DISPLAY=:0.0 (on remote)

nd34567s32e
  • 148
  • 1
  • 7