Connecting to another Server on a LAN via PHP - php

I've got two Linux servers set up at the same datacenter. They're hooked up through a private switch, and they respond to each other on local IP addresses (192.168.0.N and 192.168.0.M).
Currently, I have a PHP file on Server N calling a PHP file on Server M via (basically) file_get_contents("http://$domain/$folder/$filename.php");, and that file runs a PHP script on the destination server. The problem with this, of course, is that it goes out over the internet, chewing up bandwidth in both the send and the reply. This is why I hooked them up with the private switch.
How can I set it up so that I can call the other file by replacing the $domain with the 192.168.0.M address? What settings do I have to change on Server N (Centos 6.6, running WHM and CPanel) in order for it to recognize that 192.168.0.M will shortcut to $domain's home folder on Server M?

This is commonly handled with split horizon DNS, where internal DNS queries get answered differently than external ones.
It's best to do this via a proper internal DNS server, but if you can't, you can adjust the hosts file on your servers (in Linux, /etc/hosts) to override the IP for the domain name.

Related

How do I set up a proxy server behind a proxy server?

I'm running XAMPP on Windows and know that I could set up a proxy server by adding a few lines in httpd.conf and httpd-proxy.conf, but I wonder if there's a way to set up a proxy server that runs behind another proxy server, since my ISP cache files from some websites and I usually don't get the up-to-date data.

How is it possible to run an ftp server, using php?

I would like to host az FTP server on: mywebsite.domain/ftpserver.php
The XAMPP server runs on my computer.
The php is important, because I would like to authenticate the users using their passwords in the mysql database, and their directory's name is also stored in the database.
Or if there is a free ftp server, then how could I create ftp users from the php?
I know that this question is some years old, but for my opinion, the accepted answer is not correct.
You can omit the webserver (XAMPP / Apache) and run a PHP script from command line. This PHP scripts can listen to a tcp port (e. g. port 22, https://www.php.net/manual/en/function.socket-listen.php) and so it can receive (FTP) requests directly from a client. You will reach the server via mywebsite.domain. mywebsite.domain/yourscript.php is not necessary because PHP will listen directly to the given port.
But there's a big backdraw: You have to implement the complete FTP protocol by yourself in PHP. And that's a quite big task and you have to know what you do.
This can not easily be done. PHP works, almost always, with a webserver, serving HTTP and HTTPS request, not FTP requests. You could configure it to answer to FTP requests on port 22, as said in the other answer, but then you still have to process all the FTP requests.
A second point would be; Why FTP? You can serve files with the HTTP and HTTPS protocol as well. The only limitation is that users cannot use a custom client, they have to use a browser.

run .exe file from web application

I have application called unistat installed on my pc. I want to pass an argument from a web page and retrieve output from that program.
Is this possible?
How i can connect the website based on PHP to a remote desktop? ask to run .exe file by passing data and send output to specific location?
In order to access your local machine from the remote server, you're going to have to open up your router configuration settings and port forward all incoming port 80 traffic to your local web server's IP.
On your local machine, install PHP and set up an endpoint that runs the exec command, calling the .exe you wish to run.
You'd be wise to put this behind an authentication system, as it will be exposed to the www.
On the remote site, just fire a request off to the local machine's endpoint and the exec command will be run. Of course, if you have a dynamic IP, it's going to require constant maintenance.
See the following link about setting up custom protocols on Windows:
https://support.shotgunsoftware.com/entries/86754-launching-external-applications-using-custom-protocols-rock-instead-of-http
The idea would be that your web site could direct the browser to a special URL, i.e. unistat://my-data-goes-here and the application would be triggered with this data.
edit: better, MSDN link on the subject. http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
edit2: Just realized you want to pipe the output from the EXE back to the webserver.... You may be better off building a browser extension. That, or writing a wrapper around unistat which can trap the output and submit it to a web service.

Moving PHP site from one server to another

I have no idea about PHP.
I have PHP site hosted on Server A. Now I want to transfer the hosting to another company having Windows hosting on Server B.
Can I just transfer all the contents of WWWROOT folder of Server A to Server B? Will the site work that way? Or I do have to get the source, compile and publish it?
Thanks!
the process is this:
copy the content from server A to B (also db dump)
make sure your site is working on server B correct
set a redirect on server A to server B (usually in .htaccess file)
edit DNS entries to point to server B
wait that DNS changes have been picked up (note: as suggested by Emil you can reduce this time by lowering TTL setting on the DNS entries)
remove content from server A (end hosting)
PHP is not (usually) compiled, you should be able to simply copy the files and directories over and they should at least run. You may have to set up a database and connections to it, change some configuration in the scripts and you may or may not run into incompatibilities between different PHP versions and/or UNIX/Windows problems though, depending on how portable the scripts were written.
you don't need to compile anything. it's enough to copy project directory from one server to another. one thing can cause your project not working on ohter hosting, if there will not be installed some php-extensions that are required for you project.
and of course, if your project uses some databases, they must be created on new server
PHP scripts are source code and are compiled when needed. Simply moving the files is enough. Problems may occur if it is a package that has been isntalled on that server and may have some properties in various files about absolute paths to other files.
Also, issues will occur if the files are talking to a local SQL server or the such.
Many hosting companies offer a free (or sometimes payed) service to copy your website accross including any databases. Ask your hosting company for help.
No need to compile, however you have to make sure that the new server meets all the requirements of your application (e.g. server modules) and that paths are correctly configured. Also under some circumstances the PHP version can matter as well. Only one way to find out!

Write transparent HTTP Proxy script in PHP

Is there an easy forwarding/transparent php proxy script that I can host on my web server? These are my conditions:
I'm using free web hosting, so I have pretty much no control over my machine. Otherwise I could use Perl's HTTP::Proxy module. This means no root password. It does run php though.
I already have a server running on port 80. What I mean is I would like to put a php script as index.php on my server that will forward all requests.
I don't want a script like PHProxy or Glype where I go to the site, then enter a URL. I want a server so I can enter proxy.example.com:80 in Firefox's or IE's or whatever's proxy settings and it will forward all requests to the server.
Preferably (though not fatal if not possible) I would like for it to pass on the USER_AGENT environmental variable (That's the browser) instead of setting itself to be the USER_AGENT
I can't start a new Daemon. My server won't allow it.
Is there a script that will do this? If so, which?
No, I'm fairly sure this is not possible on shared hosting. It will fail your condition number 3. This needs support on web server level (e.g. using Apache's mod_proxy)
For this to work, you would have to set up the remote server to be able to deal with proxied requests. No sane web server will offer that possibility.

Categories