I have started to develop an HTTP/1.0 web server under Java(not for commercial purpose, just for fun). Hope this will increase my confidence. Initially, I just wanted to include PHP support(only rest API). I have almost done the request parsing and now I have stuck on executing the request. That's why I would like to know how actually web server like Apache communicates with PHP. It would be appreciable if you please share your experience, knowledge in details regarding this.
Thanks in advance
it is good to know how things works, it will help you understand the deep aspect of development and servers.
In regards to your question, the APACHE knows that the files ends with .php must be sent to PHP interpreter to execute it and provide the results, check this anatomy of a request.
Step 1
The user enters https://stackoverflow.com into their browser and taps/hits 'enter'.
Step 2
The browser sends the page request over the Internet to the web server.
Step 3
The web server gets the request and analyzes the request information. Apache realizes that we didn't specify a file, so it looks for a directory index and finds index.php.
Step 4
Since Apache knows to send files that end with the .php file extension to the PHP interpreter, it asks PHP to execute the file.
This knowledge of Apache is specified in the httpd.conf file, it tells Apache exactly what to do when it find the .php files.
Step 5
PHP Interpreter is executing the code contained in the index.php file from the request. During this step, PHP may interact with databases, the file system or make external API calls, amongst other things.
Step 6
After PHP Interpreter has finished executing the index.php file, it sends the output back to Apache. Note that the output will be HTML.
Step 7
Apache receives the output from PHP and sends it back over the Internet to a user's web browser. This is called the response.
Step 8
The user's web browser receives the response from the server, and renders the web page on a computer or device.
Hope this will shed the light on where you should focus, please visit https://httpd.apache.org/docs/2.4/ and check what modules the Apache use to find the PHP interpreter, also note you will need to install PHP separately to achieve this.
Related
I have android app, that makes http request to get files on my server,
I had to migrate all my data to new server, but i still see many get requests on old server, which mean someone stole my links, or my app it self.
I'm currently using NGINX (I can change to Apache) to serve these files,
My question: Is there a way to allow accessing these files from only a single mobile app, based on package name for example ?
Currently, I'm serving files as hot link, example : www.xxx.com/abc.mp4
I read about setting a new user-agent in requests, so that i can allow/deny access based on that value, but if someone tries to reverse engineering my app and re-build it, he can use same user-agent.
So, Please advise if there is an optimal or better solution.
Thanks,
You could disable direct file access and expose some services that send files in their response. By this way you could add some logic to protect your files. I don't know if your app uses some authentication process, you may add some certificate or something else
I'm trying to consume the external web service, and I'm able to do it using soapUI with xml.
And apparently I'm sending something else from my code, is there a way I can monitor all outgoing requests, inspect them and then forward them to the actual service?
Update:
The webservice is not on my machine, it sits somewhere on the internet.
Update II:
I downloaded wireshark, there are like milion things popping on my screen, I can't see what's what. Any better tools out there? I've used tcpMon before
I would recommend using the Fiddler tool, provided you're running Fiddler and the website on the same machine you should be able to see the requests being fired.
There is some extra setup required to capture the service calls, have a look at this Blog for more details.
The parameters should be available in the headers when you inspect the request.
Here's what I would like to do.
I have a PHP file in my server where I would like to call java applet. The applet function will send a get request to read a page from third party server. Now I want page read from applet function to be sent to PHP script. To simply put ,i want the return value of the applet request function in a PHP variable. Is it possible to do?
I want to do this way because I already have the code to parse the page information in PHP, so I don't want to rewrite that in java again.
I wanted the Java applet because the request has to be sent using the client information like IP. So I don't want to use proxies.
Note: I am not trying to hack anyone's server. I am not a advanced programmer of either Java or PHP. Please reply me in a descriptive manner possibly with pseudo code.
I already have the code to parse the page information in PHP, so I don't want to rewrite that in java again.
PHP should be able to get that page more easily than can a Java applet. The applet would need to be trusted or in communication with a site that uses the 'cross-domain resources' file that explicitly allows hot-linking.
Searches on 'php proxie' seemed to spill out around 7.32 million hits. I'd start there.
I'm connection to web servers using HttpURLConnection.
Is there a way to ask to the server to send the language that the page is built (PHP, Java, Python, Ruby, etc) and the web server that is running (Apache, ISS, etc.)?
As web servers just deliver whatever the end content is (html/javascript/a mp3 -- whatever), they are only obligated to tell you what the content they are giving you is, not how they created it. Often you will find a Server header that tells you the Apache/PHP version, but most people see that as as security vulnerability and a lot of people will disable it.
The two headers you'll want to look for are Server and X-Powered-By.
http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
As far as I know, no servers have any kind of built in API for asking what the server is. If you own the server you're wondering this about, you could of course make an API with JSP or PHP or whatever. I'm assuming that's not the case though or you'd already know :).
How to establish a way for Java application to listen to data being sent by php ? Sockets or Http POST ?
Essentially, I have Java application running on another server waiting for certain string data sent by PHP script running on other server.
Any library suggestions or example codes will be appreciated.
I suggest implementing a REST api. If you can't or don't want to, using sockets is the most secure way...
If you are sending FROM php, I recommend using a RESTful API with authentication. Send JSON data, get JSON data back. It allows for better future expansion too.
Your best bet is probably going to be to set up a java servlet "container" (server), such as tomcat (you can pay a lot of money for something else, if you have to for corporate reasons).
http://tomcat.apache.org/
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getReader()
or
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getInputStream()
Be aware there is a bit of work up front, just to set up and host "hello.jsp", but adding the mapping for the "myservice" servlet in web.xml is not too bad.