The resulting program worked properly on my Ubuntu machine again, as I could see the correct output in the terminal.

But when I tried to execute it on my webserver using PHP's shell_exec() or passthru(), there was simply no output! According to ldd, the program is statically linked so it should really work, shouldn't it?

I've been testing and debugging for weeks now and I can't find any reason why this is so. Can you help me?

(I guess this is no programming question, as my problem is just: How to get that program running on my webserver?)

System I want to compile the program on:

Linux ubuntu 3.0.0-12-generic #20-Ubuntu x86 GNU/Linux

This is the newest Wubi (32-bit) release of Ubuntu.

ldd --version outputs ldd (Ubuntu EGLIBC 2.13-20ubuntu5) 2.13

System I want to run the compiled program on (webserver):

Linux 2.6.37-he-xeon-64gb+1 i686 GNU/Linux

ldd --version outputs ldd (GNU libc) 2.7

Note:

Errors on the server side can be excluded as everything works fine if I just replace my own Linux program by the pre-compiled one.

Update #1:

I've tried running the program (that works fine under Ubuntu 11.10) in my VirtualBox under Ubuntu 5.10 - and it didn't work, either. Good news, so it's definitely not the server's fault. Ubuntu 5.10 just said: floating point exception. Does this help? Why is there an exception but not under Ubuntu 11.10?

Update #2:

Now compiled with Ubuntu 5.1 using GNAT 3.4. But all hope for nothing - still no output, ldd says statically linked (as I've compiled it that way) and strace gives the same error message. What does it mean? Is there any file missing? Is this the reason why it is not working?

Does program execute? Are the environment settings between your shell and shell escape from PHP the same?
–
KarlsonApr 4 '12 at 13:34

It seems that the program does not execute on my webserver as I can't see any output in PHP. But on my Ubuntu machine, it does execute. How can I check if these environment settings are the same?
–
Marco W.Apr 4 '12 at 13:53

The weird fact is that the pre-compiled version runs on both systems but my self-compiled program does only on the Ubuntu machine, not on the webserver.
–
Marco W.Apr 4 '12 at 23:35

Are you unable to login to the box to execute this program on the command line? Perhaps you are forgetting to echo the output of the command (e.g. <? shell_exec('...'); ?> instead of <? echo shell_exec('...'); ?>.)
–
kwarrickApr 8 '12 at 6:15

You don't specify — what flavour of UNIX is your webserver running and on what architecture? If it's not Linux (there are many other UNIXen out there) or isn't of a compatible processor architecture, static linking doesn't help. Also, if the webserver is running an older Linux kernel, you may need to link with an older Glibc, as the newer code might not run on it.
–
ephemientApr 8 '12 at 7:20

3 Answers
3

When you execute anything as a shell escape from the webserver or any other program the environment settings quite likely don't get applied. For example variables like: PATH, LD_LIBRARY_PATH, etc have their default settings or no settings whatsoever so when you are doing the shell escape you should at least do the following:

Call the program by full path: e.g. /usr/local/bin/gnatmake or /usr/local/bin/words

get the output of /usr/bin/env to make sure that in the shell escape it has proper settings. Check the same settings in your terminal shell.

If you have control of the webserver try to make it execute as your UID to avoid permissions issues.

Check which libraries are required for the program if any ldd /usr/local/bin/words

ADDITIONAL POSSIBILITY

Instead of executing the program directly use the following script:

#!/bin/sh
. /etc/profile
/usr/bin/env
pwd
./words 2>&1

and post the output. This will tell you if the program executes and if it crashes.

One more thing to check is whether or not user www-data or whatever is running the ./words is capable of accessing the database that ./words needs if any.

Thank you for these suggestions! In my webserver's log file, there's no entry that belongs to the program. Only the call of the PHP file is mentioned. And in the error log file, there's nothing which belongs to my program as well. When I created a Python script with #!/usr/bin/python print "Hello World\n" import os; os.system("./words"); and called it via PHP, it produced exactly the same results as calling the Linux program directly in PHP.
–
Marco W.Apr 8 '12 at 23:21

@ephemient: Sorry, "Hello World" did work. I was just refering to the output of the Linux program. So I had "Hello World" and then no output from the Linux program. @poige: Unfortunately, I don't know any python so I don't know how to check if os.system works correctly. I just thought I had to use Python or some other scripting language different from PHP.
–
Marco W.Apr 9 '12 at 11:13

Yes, that would be the easiest solution :D Thanks, in most cases it would work, I'm sure. But on my webserver (shared hosting), GNAT/GCC is not available as it is not needed on webservers in most cases. And I have no possibility to install it. So I have to compile the program elsewhere. Unfortunately.
–
Marco W.Apr 11 '12 at 23:51

hmmmm.. if you really can not install gcc into the webserver, maybe best solution is to simulate this: create a virtual machine on your compiler machine with a similar configuration you use on webserver, then compile the code inside virtual machine... just my 2 bits...
–
H_7Apr 11 '12 at 23:54

Yes, this is what I've just done. Please see the update in my question above. But it didn't work, either. Because there seems to be a file missing (SIGSEV - segmentation fault?). Is this the reason?
–
Marco W.Apr 12 '12 at 0:01