Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow Glassfish and PHP to work together in the same server using Apache

Tags:

java

php

apache

It's possible make a bridge from Java to php file?

I've got an application written in Java and I need execute http://piwik.org/ that is written in PHP. In the server I have PHP running but I cannot access from the browser to the php directory because all incoming traffic is redirected by apache to glassfish Application server.

So my idea is to use Java servlet to execute php files with:

Runtime.getRuntime().exec("php /path/to/file/file.php");

Then write the PHP output as java servlet response.

The only problems to accomplish this are:

How can I execute PHP cli that act like a browser?

Which parameters I need to pass to PHP to allow PHP to read or write cookie and session?

like image 306
Andrea Catania Avatar asked Dec 25 '22 10:12

Andrea Catania


1 Answers

If you're using Apache anyway to proxy the traffic, I'd just exclude all traffic to Piwik and serve those directly from the file system / mod_php / php-fpm / whatever you normally use.

You could also use php-cgi and pass the appropriate environment variables, but that complicates a lot of stuff, like you'd have to proxy the response back to the browser, too. Apache has already support for this, so don't implement another proxy in your application, do it directly in Apache.

You can exclude a directory from being proxied:

ProxyPass /piwik ! 
ProxyPass / 127.0.0.1:8080 
ProxyPassReverse / 127.0.0.1:8080
like image 140
kelunik Avatar answered Dec 28 '22 10:12

kelunik