I want to configure so that jetty runs PHP files, but have been unsuccessful so far. I have Jetty WTP tools installed in my Eclipse IDE.

When I start up the Jetty server. I got the exception: java.lang.ClassNotFoundException org.mortbay.servlet.CGI: org.mortbay.servlet.CGI and javax.servlet.UnavailableException: org.mortbay.servlet.CGI. I put a simple php file(index.php) under my WebContent folder. I also downloaded this library and added it to the classpath(Eclipse: build path and add external jar). I have no clue now what I've done wrong. I also compiled php with:

./configure --with-fastcgi=/usr/local
sudo make install

And my web.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
    <display-name>Sample PHP Application</display-name>


    </welcome-file-list> </web-app>

It could be my php-cgi-fix file, I got the followig text i terminal when i open it:

$ /usr/local/bin/php-cgi-fix ; exit;
/usr/local/bin/php-cgi-fix: line 3: /usr/bin/php-cgi: No such file or directory

Shouldn't be /usr/local/php-cgi instead? Ok I tried that now, but still I got the same ecxeptions when I launch the server.

(I really don't like to use maven too

  • add output "ls -al /usr/bin/php-cgi" – ooshro Feb 25 '11 at 14:05

Install php-cgi(contain /usr/bin/php-cgi).


sudo apt-get install php5-cgi

CentOS/Red Hat/Fedora:

yum install php-cli

In Mac OS try create symlink:

sudo ln -s /usr/bin/php /usr/bin/php-cgi
  • you have missunderstood me. I want jetty to be able to run php code not only java – einstein Feb 25 '11 at 12:51
  • For run PHP code you need install PHP – ooshro Feb 25 '11 at 12:53
  • yeah I've already done that. But configuring the servlet and server is the next step which I'm in – einstein Feb 25 '11 at 12:55
  • add output "ls -al /usr/bin/php-cgi" and what your OS? – ooshro Feb 25 '11 at 12:57
  • I'm conifguring the server on my mac. but the php is working I think. It is the server who isn't – einstein Feb 25 '11 at 13:05

If your php-cgi-fix script comes from Jetty and PHP then it is no longer required, you can just call php-cgi directly.

22 days after you asked the question but if you are still not there then I'd suggest getting this running outside of Eclipse first. Enable debugging and look for lines in the log containing "CGI" and also set init_param "ignoreExitState" to "true".

Questions about Jetty and PHP come up about once a year on the mailing list so my guess is very few people are doing this. You may well be the first to do this on a Mac with a particular version of Jetty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.