尝试在Eclipse中运行PHP Hello World时出错

I installed the PDT PhP Development Tool in eclipse in order to run PhP files, but when I click in "Run as > PhP Web Aplication" it shows me a white page with the message:

Not Found

The requested URL /teste/teste.php was not found on this server.

Apache/2.4.23 (Debian) Server at localhost Port 80

Apache is running normally in 127.0.0.1.

I have an info.php file at /var/www/info.php, I tryend to tun http://localhost/info.php but it gives the same Not Found error.

Yes, I'm newbie in PhP, I'm trying to run a simple Hello World Program.

<?php
    echo "Hello!";
?>

My info.php is:

<?php phpinfo(); ?> 

Solved, I created a symlink for my project at /var/www/html, now it works!

Apache/Hosts

When you tried to open http://localhost/info.php direct in your Browser (firefox etc.) and this won't work, the problem is in your apache/hosts configuration.

  • Check in your apache.conf/httpd.conf the DocumentRoot
  • Check your VirtualHost config (in httpd.conf or separate file)
  • Check your /etc/hosts they should contain:

127.0.0.1 localhost.localdomain localhost ::1 localhost.localdomain localhost

When the url works in your browser:

Eclipse You have to create the Run Configurations:

  1. Menu "Run" > "Run Configuration"
  2. Select "PHP Web Application" and click the "New Button"
  3. PHP Server: click on "New"
  4. ServerName: just a name. Tipp: name it after your domain: "localhost"
  5. Base URL: http://localhost
  6. Document Root: path to your source folder
  7. Finish (Back in Run Configuration)
  8. File: your start file (index.php or in your case teste.php)
  9. check if the url is correct, otherwise remove the check on "Auto Generate" and fix it
  10. run > will open the url in the Built-In browser

To open the page in FireFox etc.: Menu "Preferences" > "General" > "Web Browser" > "Use external browser"