0

Im making a simple web-based control panel, and i figured the easiest way for me to accomplish it would be to have PHP on the 2 machines (one being the web facing machine, the other being behind a VPN), basically I need it so when I press a button on the site on the externally facing IP of machine 1, it sends a request to the internally facing IP (eg 192.168.100.1) of machine 2 and runs the PHP file (test.php plus some $_GET data) without actually redirecting the end user to 192.168.100.1, because obviously that will time out as there is no access to it.

1
  • Just for some extra input, it seems like everyone thinks I want the files on Machine 2 displayed to the end user through machine 1, This is not what I want. I want machine 1 to make PHP code run on machine 2. Commented Nov 6, 2013 at 11:15

3 Answers 3

2

If all you want is to make certain internal PHP pages accessible on the external server, you should consider setting up a reverse proxy instead of manually proxying requests with PHP.

See the Apache documentation for an example: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Of course this won't work if you do your authentication on the external server and/or need to execute additional PHP code on the external server before/after the internal PHP code. In that case refer to Mihai's or Louis's answer.

Sign up to request clarification or add additional context in comments.

2 Comments

I dont want them externally accessible, the PHP pages on machine 2 act as nothing but methods of controlling data and running shell commands, they dont have their own UI or feedback as thats all handled by the site on machine 1.
In this case refer to the other answers.
1

You can use cURL to send or forward HTTP requests from machine 1 to machine 2 and to receive the responses machine 2 gives you and (if needed) process those responses to show them to the user.

You could also use (XML-/JSON-)RPC or SOAP which would be a bit more elegant and extensible (more commonplace than using cURL) but it would have a higher learning curve with a bigger setup time/work.

Comments

1

You should also be able to use file_get_contents (normally supporting the http protocol) or http_get, a function designed for simple http get requests.

It might not be the most ideal way, but should be fairly easy to do.

4 Comments

+1 file_get_contents slipped my mind. It's way easier than cURL, not to mention RPC or SOAP. It has its (many) limitations but for small tasks it should do well.
Why? Both of your solutions are bad compared to server proxying, like solymosi answered. Neither file_get_contents or cURL should be used for this. Every single server software out there has some sort of proxying built in for purposes like those of the OP. I'm not downvoting because it's not wrong answer, however there are much better approaches.
Of course that's true - It just depends on what he really wants.
all I want is for when a button is pressed on machine 1, it runs a PHP script on machine 2. I dont need any feedback from machine 2 back to machine 1 as of yet, or anything like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.