4

I want to develop a C# tool which shall be run on an Apache Web Server whenever it is called via PHP (e.g. using the exec-command). Since I am new to this it would be great if you can help me:

1) If I compile the C#-code on my Windows-system using the Mono and the "msc"-command, will this create a file which is also executable in Linux, i.e. on the Apache Web Server? (it's definitely executable in Windows) If not, how do I create Linux-executable files using Mono for Windows?

2) Is there something to consider when trying to call an application on an Apache Web Server via PHP? Permission rights?

tyrex
  • 8,208
  • 12
  • 43
  • 50

1 Answers1

4

1: The first question on the Mono FAQ:

Can Mono run binaries produced by Visual Studio?

Yes, Mono can run binaries produced by Visual Studio, there is no need to recompile.

Use our Mono Migration Analysis tool to check if everything that your application uses has been implemented in Mono or if there are special considerations to keep in mind.

The Mono API today is somewhere in between .NET 2.0 and .NET 4.0 see our Roadmap for details about what is implemented.

2: I can't speak specifically for PHP, but I believe you'll have to run the process using the mono executable (e.g. mono /path/to/exe/SomeTool.exe)

Community
  • 1
  • 1
M.Babcock
  • 18,753
  • 6
  • 54
  • 84
  • Thank you for the quick answer! Unfortunately, I don't understand what is involved in your answer regarding my question no. 2. Specifically, I guess I have to somehow integrate Mono into the Apache Web Server? Otherwise the server wouldn't know about the command "mono"...Now the question is how to do that? The closest link I could find was [link](http://www.codeproject.com/Articles/9407/Introduction-to-Mono-Your-first-Mono-app) this link, but this wasn't helpful either as I am dealing with a shared web server which I rent.. – tyrex Feb 08 '12 at 23:50
  • You're digging to deep into this. Your original plan to run the executable from your PHP application using the `exec` method should still work. The `$command` parameter would look something like `/bin/mono /path/to/exe/SomeTool.exe`. I don't know what kind of problems you might encounter but in principle I don't know why this wouldn't work. – M.Babcock Feb 08 '12 at 23:54
  • The problem is that the "Mono" is not installed on the Apache Web Server and thus calling "/bin/mono ..." leads to an error because there is no "mono"-command. – tyrex Feb 09 '12 at 00:26
  • However, the current state is that the same error occurs when I just call `SomeTool.exe` . I am confused, since when testing on my operating system (Windows) it does work, but not when I upload the corresponding files to the server (Linux). – tyrex Feb 09 '12 at 00:35
  • Sorry I guess I didn't finish reading your last comment. Which flavor of linux are you running on your server? – M.Babcock Feb 09 '12 at 00:42
  • It's **Debian GNU/Linux** according to the support guy – tyrex Feb 09 '12 at 00:45
  • I just noted that when using the command `sh SomeTool.exe` or also `./SomeTool.exe` then I get a step further: the command is accepted but it gives me the error `cannot execute binary file`. Thus, my way of compiling the C#/*.cs code is not working... – tyrex Feb 09 '12 at 01:06
  • 1
    No Mono works on linux and executables compiled on Windows *generally* run on Linux. The problem is still that you don't have Mono installed. It is required in order for your Linux box to know what to do with the `SomeTool.exe`. This is not a programming problem, it is a system admin problem. Your support guy should know how to install packages on your debian box. [Here's] a site that provides precompiled packages for your platform. – M.Babcock Feb 09 '12 at 01:10
  • Thanks for the Info! Can you please regive the link of the site, since it's not included in your post? - or did you exclude for spam/marketing-reasons? – tyrex Feb 09 '12 at 01:19
  • Let me add: I just found [this link](http://stackoverflow.com/questions/8668126/i-have-a-program-in-c-sharp-can-i-compile-it-as-an-executable-for-linux-server) and [that link](http://stackoverflow.com/questions/1321207/how-to-convert-a-simple-net-console-project-a-into-portable-exe-with-mono-and-m) which looks to be pretty much like a solution for what I am looking for. I have plenty of material now to play. THANKS A LOT!!! – tyrex Feb 09 '12 at 01:25
  • If this answer has helped you solved your problem, please be sure to mark it as the answer by clicking on the checkbox under the upvote count above. – M.Babcock Feb 09 '12 at 01:26