I have a php file with an exec() function that executes some unix commands when I do this: php file.php on terminal, but now I need to do the same from URL on the browser, that is: localhost/file.php
So, how can I achieve this?
It sounds like you need a web server. It's a huge topic so it can't be covered here.
However. If you just want to run a simple PHP server, try
$ php -S localhost:8000
From the root directory of your PHP application. It should be accessible in your browser by going to localhost:8000. Or to make it accessible on any interface:
$ php -S 0.0.0.0:8000
Note that this only work for newer versions of PHP (>=5.4).
Thanks for your answers. The problem was that the files which I used in the commands inside exec() were outside of the /var/www/html directory and apache was complaining about permissions and after I had to give them permissions with the chown command.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.