What is the correct way to run an application on a linux server using PHP? [closed]

1

Good afternoon, I need to run a natively built application for linux servers using php.

I have a php script that runs an application on the linux server creating some files needed to continue the application.

When running the script through the terminal the program runs correctly generating the necessary files. However when running it through the browser the same script does not run the application.

I have already used the system, exec, shell_exec, passthru functions but none properly executed the application. I would like to know what is the correct way to run applications through php and how to get and handle the respective returns.

Example I'm using:

<?php
   exec('/home/dados/controll/ncolinux');
?>
    
asked by anonymous 25.08.2016 / 23:03

1 answer

4

Hello! When you run the script through the browser, it is the web server user who runs this script. For example: If you are using an Apache server, it runs with a user named apache. So you need to give enough privileges so that this user can run the application.

To get the return of what was executed, use the function shell_exec() , it returns a string, which is the result of the executed command.

I hope I have helped.

    
25.08.2016 / 23:16