Apache behind corporate proxy - php

I'm developing a php application. I'm using wamp and I'm behind a corporate proxy. I'm using cntlm to authenticate NTLM. I need to curl google geocoding api, in order to do this I used the following settings that are working:
curl_setopt($ch,CURLOPT_PROXY, '127.0.0.1:3128');
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
I'd like to find a way to avoid setting those options for CURL. I believe I can play with Apache setting, but I'm not sure. The reasons I need to find this solution are:
In production env there will be no such a proxy (at the moment the above options are used only if the environment variable is set to DEV env, but still: it's not the best solution)
If I want to use 3rd party SDK (such as facebook php sdk), those are internally using CURL but they do not necessarily expose method to change CURL options (for example facebook sdk doesn't). I don't want to change the SDK source code to fit my proxy
What I tried:
So far I turned on proxy_module on apache and I added the following line on httpd.conf, but with no success
ProxyRemote * http://127.0.0.1:3128
I still can't access the internet. I googled a lot, but I couldn't find a solution, any ideas?
I could find many people talking about the same issue, but I didn't find any comprehensive solution, for this reason I raise a bounty.
What I found:
There is this bug in which I found: But I'm not sure if this will work for curl and anyway I can't find how to modify the php.ini
[2010-12-20 14:03 UTC]
jani#php.net
-Summary: changing the default http-wrapper
+Summary: Add php.ini option to set default proxy for wrappers
-Package: Feature/Change Request
+Package: Streams related
-PHP Version: 5CVS
+PHP Version: *
and
[2011-04-05 11:29 UTC] play4fun_82 at yahoo dot com Hi, i have the
same problem. My solution was to pass through proxy server with cntml
tunneling tool. You configure cntml proxy to forward http request
received on local host on a port to destination with proper
authentication.
And in pear u just configure
pear config-set http_proxy 127.0.0.1:3128
3128 - is port configuret in cntlm(it can be any other free port).
Thanks very much

You're saying you want this functionality on WAMP, for your development computer only, right? The SDK's work without modification in production, so you can just take advantage of your Window's Host file to redirect requests.
Here's a walkthrough.

After reading this article I was about to throw in the towel, but there is actually an easy solutiuon. I had to play with windows environment variable, at the end setting a system variable to https_proxy=https://localhost:3128 worked! Before it was not working because I was setting it to 127.0.0.1:3128. Run the command
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | find /i "proxyserver"
then copy/paste the answer in the system variable and now it's working!!

I think you can do it through proxy tools like Proxifier(http://www.proxifier.com).
AFAIK, they can capture traffic from selected applications and redirect to a proxy automatically.
Not a perfect solution but should be useful on dev machine.

Related

connect webpack devserver (HMR) with PHP project running with virtual host

Currently, I developing a WordPress plugin with React frontend.
I tried to connect my backend (PHP) running on a virtual host with webpack devserver with hot module replacement (HMR).
Is there any config how to do it.
note: I tried with devserver proxy but cant figure it out.
Thanks in advance.
Getting HMR is always complicated for custom setup like these. Theoretically, this is pretty simple. You simply need to run the webpack-dev-server with the HMR module. On your PHP file, make sure it uses the JS file generated from webpack-dev-server. The code to refresh is bundled in the JS file so it should work.
However, the devil is in the details. You'll need to make sure the communication between your page and webpack-dev-server works without issue. Monitor your websocket network request and make sure they communicate as expected.
An issue you'll probably encounter is security since the websocket connection is expecting a different host. In this case, you can use config from the following answer: I am getting an "Invalid Host header" message when connecting to webpack-dev-server remotely
Another issue could be that the JS file tries to connect to the wrong location. Eg: It thinks that your host is where the websocket connection is. If this is the case, you can use the public setting. See here for documentation: https://webpack.js.org/configuration/dev-server/#devserverpublic
To me this is akin to running with a reverse proxy. You can see this discussion to understand the problem: https://github.com/webpack/webpack-dev-server/issues/804
There might be other problems. You just need to check the websocket connection and make sure they communicate without problems
How you refer to the generated js file is a separate problem. A simple example would be setting the port to 8081 and bundling the js file into bundle.js. Then in your php code, refer to it as http://localhost:8081/bundle.js

Single PHP page hosting

I am developing APIs in node js and have hosted the application on amazon EC2. In a third party API it is required to host a php page on our server and give its public url back to them. Is there another way to host it apart from a LAMP setup? Anything apart from EC2 is also fine but please take into consideration that this is a single page having some logic and nothing else will be there in PHP.
I work with node and php. I would recommend NGINX. It's configuration files are really simple and it's much lighter-weight than apache.
You can simply create a redirect/rewrite directive in NGINX that will pass your php page to the node server instead and be done. For this usecase, you wouldn't actually even need to install or configure the PHP backend.
http://nginx.org/en/docs/beginners_guide.html#proxy
You might also check AWS domain management tools (AWS Route 53). There may be a way to directly rewrite the incoming PHP request to go to your node app instead without installing any webserver on your EC2.
Yes, there are other web-servers available apart from apache: For instance Nginx plus or Lighttpd, both are fine and lightweight alternatives to host your PHP files on EC2.
Though, it's not clear to me why don't you like the LAMP setup. Maybe Apache+PHP, without MySQL, would be enough for you?

Impossible SSL CAS-certificates with phpCAS and examples. It only works without SSL server verification

I am doing a CAS integration with a project that I am doing with my university. The final integration should be made with symfony2, however first I need to make the example code working.
I finally get working the example_simple.php example with phpCAS 1.3.2 , however the directive:
phpCAS::setNoCasServerValidation();
is the enabled one. I think I should use instead:
phpCAS::setCasServerCACert($cas_server_ca_cert_path);
However when I enable this second one (and disable the other) then the authorization does not work anymore. Here is the relevant output line error of the log:
could not open URL 'https://cas_server.fi/cas/serviceValidate?service=http%3A%2F%2Flocalhost%2Fphpcas2%2Fdocs%2Fexamples%2Fexample_simple.php&ticket=ST-115606-M1Omd1cHWzbLbmxa1nYV-cas' to validate (CURL error #60: SSL certificate problem: unable to get local issuer certificate) [Client.php:2763]
The cas server provided me two .crt files:
MYCASRootCA.crt
MYCASLinuxSUBCA.crt
And they are suppose to be installed in my system (Ubuntu 13.10). They are in different places, such a /etc/ssl/certs/MYCASLinuxSUBCA.pem but also:
/usr/share/ca-certificates/lut/MYCASRootCA.crt
/usr/share/ca-certificates/lut/MYCASLinuxSUBCA.crt
So assuming that the variable $cas_server_ca_cert_path has to have one of these .crt files or .pem dirs (such a /usr/share/ca-certificates/lut/MYCASLinuxSUBCA.crt) I cannot make it work. What I am doing it wrong? My client-server (no the cas server) is in my localhost. Is it a problem? Should I avoid use setCasServerCACert command? Why is it happening?
I've also tried to use the curl-ca-bundle.crt certificate provided by my XAMP instalation (Xampp 1.8.3).
I am a little bit lost with certificates as you can see.
I read about problems with phpCAS and recent Ubuntu versions in https://github.com/Jasig/phpCAS/issues?state=open. However I cannot make this working with the master code, even without certification (by default).
Any ideas would be appreciated...
I have found the solution asking in the github library: https://github.com/Jasig/phpCAS/issues/119
The reason is that the curl binary used by PHP in my xampp installation is different from the system's curl binary. The system one has access to /etc/ssl/certs/ certificates, but the xampp curl does not have (unless you don't indicate it, of course). By default, it searches in a special certificate-bundle-file.
Finally I have found the real certificate for my cas-server and I am using it, however maybe you want to use other proposed solution at the end of the discussion thread if you are having a similar problem.

nginx.conf for a restful api

I'm currently developing a RESTful api as a bridge between my ios/web application and their shared database, and content.
I found my way to implement RESTful api in PHP on this blog.
I started my development on my OVH Apache-based server. Unfortunately, they didn't provide oauth support on web hosting services and there is no way to install it. OVH told me I needed a dedicated server or a VPS server for this.
Now, I'm going to work on dotCloud. It's a great alternative, I think, but their servers (seemingly Amazon EC2's ones), are nginx-based.
This would be the first time I've used a nginx server and I need your help for "translating" this .htaccess to a nginx.conf file.
Before asking for your help, I tried to find a nginx.conf file for this but no one worked.
When I pushed them to my dotcloud app, the http service of my app crashed and dotcloud cli said :
14:55:44 [www.0] WARNING: The service crashed at startup or is listening to the wrong port. It failed to respond on port "http" (80) within 30 seconds. Please check the application logs.
Thanks for any help in advance :)
Thanks to this htaccess to nginx.conf converter, and some tricks and tests I've made, here is the corresponding nginx.conf file.
I hope it will help people. ;)
EDIT: link to my configuration is dead, but the converter is still available. As long as you have a valid Apache configuration you're good to go.

Local Facebook Development Environment using WAMP - how to find localhost port number and work on application

Hi I'm a newbie to web programming and am trying to build an integrated FB application in PHP. I have already some some sample code stored on the heroku servers but for convenience I am trying to set up a local development environment and have installed WAMP (I'm running Windows 7 32-bit). I have three questions:
1) I have been following the instructions on https://devcenter.heroku.com/articles/facebook#working_locally and am in the process of setting up the developer test app. It seems that the localhost url is always 127.0.0.1 for every machine, but how can I find out what port number to put? Or do I simply pick a 4 digit one at random? In another post someone specified a port for Ruby (or Ruby on Rails, I'm not sure), but I can't find any information on the port for PHP.
2) The guide mentions that I need to set the APP ID and APP secret as environment variables - how do I do this in WAMP?
3) Once I have created the test app, how do I actually go about working locally?
Help with any of these questions is much appreciated! Thanks in advance!
You don't need to specify a port, the default is 80 for HTTP which PHP uses.
The guide mentions that I need to set the APP ID and APP secret as environment variables - how do I do this in WAMP?
Hopefully WAMP is like XAMPP so you should find your vhosts file equivalent and enter the following
<VirtualHost *:80>
DocumentRoot /Users/adam/Sites/mycoolapp-dev
ServerName mycoolapp-dev.localhost
SetEnv FACEBOOK_APP_ID 964173273189
SetEnv FACEBOOK_SECRET dcd5d23d003d53cb2b68e01
</VirtualHost>
Something like C:\wamp\bin\apache\apache\conf\extra\httpd-vhosts.conf should be the location. So you'll need to read up on Virtual Hosts for this to work, if you encounter errors
Once I have created the test app, how do I actually go about working locally?
You code and save, and either create a new test app different from the one pushed to Heroku in your app settings or change the URLs in the original app settings to match your localhost URL. If everything is set your app should be able to work locally.
You can use a protocol analyzer like wireshark, to find on which port the packets are being sent and received.
Heroku by default sets the environment variables for you. You can check it by calling phpinfo().
You can do that manually also by
<?php
putenv("APP_ID=$APP_ID");
?>
var_dump($_SERVER); // should give you all the info you need

Categories