I am pretty new to Java for Web and my question is if I can use Java and PHP together? I know I can use them together, let's rephrase the question, is there a way to access them at the same port?
Java uses Tomcat, can PHP use tomcat also?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
Tomcat does not do PHP, and (unless something happend in the recent past) there's no "mixed" application server that supports java and php all at once. However what you can do is have an Apache server installed and configured for PHP. This way you get a PHP application server configured on some port. Then you configure this Apache to redirect certain URL patterns to a Tomcat server (like all url with prefix /java/app/* go to Tomcat, all others are treated by Apache directly). Now effectively if you deploy web applications done in PHP in the Apache server and Java web apps in the Tomcat server, they will all "answer" to the same port.
As an adjunct to Andrei's suggestion, install a standard Apache+PHP combo listening on [your-ip]:80 and/or [your-ip]:443 and then install Tomcat, listening on localhost:8080. Then just do this in the normal Apache config:
<Location /myjavapps> order deny,allow allow from all ProxyPass http://localhost:8080/ ProxyPassReverse http://localhost:8080/ </Location>
You can use mod_jk or proxy_pass within your apache config to interact with your tomcat application on port 80
ProxyPass /servlets ajp://localhost:8009/servlets ProxyPassReverse /servlets ajp://localhost:8009/servlets
This would mean /servlets - apache is sending requests to tomcat
PHP is a compiled module and is defined to where you want it to be within your virtual host