• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to run PHP file on Tomcat server?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to PHP.
I am using Eclipse Juno IDE, Tomcat server, mysql database on Mac OSX.
I created a dynamic web project and created some web pages. In one of the pages, I created login form... To display the error message on the same page by comparing the username and password with the database, I need to use PHP.. but I am unable to use PHP in my dynamic web project. Can anyone help me how can I run the PHP files on Tomcat server or suggest can I achieve this using any other javascript like AJAX.

Please help me.. I am really struggling with this.
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know... there are thousands if not millions of websites around the world which make people log in, and not all of them are written in PHP. So your statement that you need to use PHP isn't all that convincing. Your later suggestion that you could use AJAX is a better idea, if you are forced to use Tomcat. But if you're more comfortable with PHP you could discard the Tomcat idea and write your website all in PHP. After all there are plenty of websites around the world which are written in PHP too.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If what you have now is pure HTML pages, and if you intend to implement your complete web app (including database access ) with PHP as server side language, then Tomcat isn't the right server; what you need instead is apache httpd (which is commonly called simply "apache server"). You can optionally install either the PHPclipse plugin or download the PDT distribution of eclipse; they are targeted at PHP developers and facilitate deployment of PHP webapps on apache server. For the error display, you can use a javascript framework like jquery to send ajax requests to server and reply to those requests from PHP scripts.

On the other hand, if you have already implemented your pages and database access using JSP/servlets and already deployed on tomcat, then you don't need PHP at all. Just use a javascript framework like jquery to send ajax requests to server and reply to those requests from a servlet.

PHP can't execute on tomcat; or more accurately, it can probably be coaxed to run with lots of deployment gymnastics and patience, but nobody does so because it's not the right tool for the job. Apache httpd is the right server for PHP.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat is servlet/JSP container not a PHP container. If you need to run PHP then Apache web server is needed.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and specifically something like the mod_php module for enabling PHP support in Apache.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to run PHP applications in Tomcat. For example, you could use the open source PHP/Java Bridge to do this.

But unless you have a need for Java applications to be running at the same time, you are probably better off running an Apache HTTPD server. Even if you need both, I would normally recommend using the Apache HTTPD server for static content, PHP files, access controls - things that it is great at, and that Tomcat is not really designed for.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still questioning the need for PHP at all.
 
kumar sapan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I don't know... there are thousands if not millions of websites around the world which make people log in, and not all of them are written in PHP. So your statement that you need to use PHP isn't all that convincing. Your later suggestion that you could use AJAX is a better idea, if you are forced to use Tomcat. But if you're more comfortable with PHP you could discard the Tomcat idea and write your website all in PHP. After all there are plenty of websites around the world which are written in PHP too.




Yes, I agree with you. But my question is while using html... Or JSP which is the best option for server side checking. Now, I am using servlets. But in servlets we need to add new page to display the errors. I want to display the errors in the same page... I try to use AJAX. But the AJAX is internally using php. (May be I am wrong) but when I search on google. I found that.) I don't know whether I can use only AJAX to achieve this. If it is possible, can you suggest me which is the site to learn AJAX.
Thank you for the reply.
 
kumar sapan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:If what you have now is pure HTML pages, and if you intend to implement your complete web app (including database access ) with PHP as server side language, then Tomcat isn't the right server; what you need instead is apache httpd (which is commonly called simply "apache server"). You can optionally install either the PHPclipse plugin or download the PDT distribution of eclipse; they are targeted at PHP developers and facilitate deployment of PHP webapps on apache server. For the error display, you can use a javascript framework like jquery to send ajax requests to server and reply to those requests from PHP scripts.

On the other hand, if you have already implemented your pages and database access using JSP/servlets and already deployed on tomcat, then you don't need PHP at all. Just use a javascript framework like jquery to send ajax requests to server and reply to those requests from a servlet.

PHP can't execute on tomcat; or more accurately, it can probably be coaxed to run with lots of deployment gymnastics and patience, but nobody does so because it's not the right tool for the job. Apache httpd is the right server for PHP.




Thank you very much for your explanation. I already implemented my pages and database access using JSP and servlets. But when I search on google with AJAX, it is again internally using PHP file. So, I thought PHP is mandatory for server side checking. And also one more thing... We can use Java code inside the JSP, right. But why it is not recommended... (I somewhere read that using java inside the JSP is not recommended.)
Can you suggest me whether W3SCHOOLS best to start with jQuery. Can you suggest me any other website also.
Thank you once again for your answer. I completely understand now.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajax does not require PHP. Ajax makes a request to the server, and it can call any type of resource: PHP, servlets, or anything else. You do not need to use PHP in order to use Ajax.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP is HTML + java code. This java code can be included either as scriptlets with raw java code, or as custom JSP tags which include java code indirectly.
Which one to use is a subjective preference. Some people like including java code directly as scriptlets; others prefer custom tags.

I prefer customs tags and strongly dislike scriptlets for the following reasons:
1. Better Readability and "Codeability": To my eyes, this snippet with custom tags


is easier to type, read,and understand, than this scriptlet version:

Look at how the scriptlet has so much more verbose code, extra keystrokes and scope for mismatched braces!

2. Compiler error checking support: If there is a syntax or semantic problem in the above JSP scriptlet, we usually don't get to know it until the page has been deployed on server,
because most default configurations go for on-demand runtime JSP compilation, instead of build time compilation.
On the other hand, a custom tag library is like any other piece of pure java code and needs to be compiled first before deploying. So it's easy to find out
most syntactic or semantic faults.

I started to frame more reasons, but then guessed that some angel here would have already written a comprehensive FAQ, and indeed they have! Go through it.



Can you suggest me whether W3SCHOOLS best to start with jQuery. Can you suggest me any other website also.


In order to appreciate why frameworks like jquery are useful, you first need to understand what exactly are the problems when using plain javascript.
If you are not familiar with javascript, then my suggestion is learn plain javascript first and implement ajax and basic DOM manipulation using it for your current app (learn-by-doing). There are ajax and DOM manipulation examples on w3schools.
Also check out this site's own javascript FAQ.
Once you have understood the problems with that approach, learn jquery to appreciate how it makes life easier. The FAQ above has links to good resources.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:JSP is HTML + java code.


Not since 2002. JSP is a template to create a text response, which is usually HTML (bit can be any text). Java code is no longer used in JSP, but rather the JSTL and EL.
 
kumar sapan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Karthik Shiraly wrote:JSP is HTML + java code. This java code can be included either as scriptlets with raw java code, or as custom JSP tags which include java code indirectly.
Which one to use is a subjective preference. Some people like including java code directly as scriptlets; others prefer custom tags.

I prefer customs tags and strongly dislike scriptlets for the following reasons:
1. Better Readability and "Codeability": To my eyes, this snippet with custom tags


is easier to type, read,and understand, than this scriptlet version:

Look at how the scriptlet has so much more verbose code, extra keystrokes and scope for mismatched braces!

2. Compiler error checking support: If there is a syntax or semantic problem in the above JSP scriptlet, we usually don't get to know it until the page has been deployed on server,
because most default configurations go for on-demand runtime JSP compilation, instead of build time compilation.
On the other hand, a custom tag library is like any other piece of pure java code and needs to be compiled first before deploying. So it's easy to find out
most syntactic or semantic faults.

I started to frame more reasons, but then guessed that some angel here would have already written a comprehensive FAQ, and indeed they have! Go through it.



Can you suggest me whether W3SCHOOLS best to start with jQuery. Can you suggest me any other website also.


In order to appreciate why frameworks like jquery are useful, you first need to understand what exactly are the problems when using plain javascript.
If you are not familiar with javascript, then my suggestion is learn plain javascript first and implement ajax and basic DOM manipulation using it for your current app (learn-by-doing). There are ajax and DOM manipulation examples on w3schools.
Also check out this site's own javascript FAQ.
Once you have understood the problems with that approach, learn jquery to appreciate how it makes life easier. The FAQ above has links to good resources.




Thank you for your suggestion. This is really helpful. I will do that.
Thank you.
 
kumar sapan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Karthik Shiraly wrote:JSP is HTML + java code.


Not since 2002. JSP is a template to create a text response, which is usually HTML (bit can be any text). Java code is no longer used in JSP, but rather the JSTL and EL.



Thank you. Even I thought that we can use java inside the JSP. When I read that this is not good way to approach then I did not know the reason. Now I got it.
 
Ranch Hand
Posts: 71
PHP Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To run PHP in Tomcat, take a look at Quercus: http://www.caucho.com/resin-3.1/doc/quercus.xtp
You could also try using phpservlet: http://phpservlet.sourceforge.net/
I've used both with JBoss AS 4.2.x and 5.x; since those versions of JBoss AS use a variant of Tomcat you should also be able also use Quercus and phpservlet on Tomcat.
Personally, once I started using Quercus I never bothered with phpservlet any more.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic