How to set up/view PHP server pages in Eclipse with the PDT plugin (for php)

17,719

Solution 1

I'm afraid I don't have an answer to you're question, but I wanted to share...

I never was a fan of running PHP on IIS or Apache. So I built a portable, no-install-required copy of nginx that I could move around with me or use on my Windows machines. (Just download the flavors of PHP, Nginx, and MySQL you want and start it). One of the reasons is that most production sites run nginx anyway, so this way I'm closer to what my server actually uses (unless you are on "shared-hosting" which still uses the Apache).

Second, I'm not sure why you need to "run" it from Eclipse. When you write PHP you usually are dealing with a lot of variables to get pages setup. I would say you need to worry more about adding Unit Tests to make sure things work right, and using a browser like Firefox (with firebug) for testing any requests you might be making. Things like AJAX, or dealing with session cookies often require more control than what Eclipse can give you.

Bottom line, I'm not sure why you think you need to do this.

Solution 2

If you download PHP 5.4.x you will be able to use the built-in web server for all of your development needs.

In your php folder, you would run:

php -S localhost:3030

Now you will be able to browse to http://localhost:3030/index.php

If you were using the Aptana IDE (or anything comparable), you would set this up like so:

External Web Server Configuration

Your run configuration would be:

Run Configuration

I don't personally use Aptana (I did a few years ago); however, I thought it would be interesting to try this to find out if the integration would be seamless or not. I have to say, I am pretty impressed at how Aptana gets out of your way so you can do just about whatever you want.

Finally, if you are wondering about the "$HOME/local/php/versions" listed in my "Start command", I drive multiple PHP versions with a tool called php-version. Please be aware that this tool targets Linux/Mac users; however, if more people are interested, I may do a windows/powershell port (NOTE: I am the author).

Share:
17,719
Ozzy
Author by

Ozzy

React Developer (currently) React, Redux, Babel, JSX, Webpack, SCSS Testing: Mocha, Cucumber, Cypress Also: NPM, Docker, Jenkins, Concourse, CI/CD Previously: Python Django, PHP, Java, MySQL MSc Data Science & Machine Learning, UCL BSc (Hons) Comp. Sci., Queen Mary, University of London

Updated on June 05, 2022

Comments

  • Ozzy
    Ozzy almost 2 years

    I am trying to set up a PHP server on my localhost to run with the Eclipse PDT. I want to be able to view the PHP site I am developing on something like http://localhost/MySite/index.php so that I can Run it straight from Eclipse.

    I am using IIS 7.5 (windows 7 home premium) for the PHP server.

    So far I have followed these instructions, but have not been able to get it to work:

    • Install CGI option in Windows Features
    • Install IIS Manager in Windows Features (so I can run inetmgr.exe)
    • Download the NTS-version of php and extract the zip to C:/php
    • Rename php.ini-development to php.ini and set the extension_dir variable
    • Run inetmgr and create a new website to run PHP applications (I removed the DefaultSite):
      • Site Name: My Site
      • Physical Directory C:/dev/MySite
      • Application Pool: DefaultAppPool
      • Bindings:
        • Host:
        • IP Address: All Unasigned
        • Port: 80
    • In inetmgr: Click on handler mappings and add a new Module Mapping:
      • Request Path: *.php
      • Module: FastCGIModule
      • Executable: C:/php/php-cgi.exe

    Now I have many problems:

    1. In IIS Manager, when I click Edit Site > Test Settings, there is a yellow exclamation-mark warning: Authorization: Cannot verify access to path (C:/dev/MySite):

      The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify whether the built-in account has access. Make sure that the application pool identity has Read access to the physical path. If this server is joined to a domain, and the application pool identity is NetworkService or LocalSystem, verify that \$ has Read access to the physical path. Then test these settings again.

    2. When I try to load any .php file directly from the webroot (C:/dev/MySite) it displays as plain-text in my web browser

    3. When I try to Run my project in Eclipse, it goes to http://localhost/MySite/index.php and there is a 404 Error: Website Not Found

    4. When I go to http://localhost/ in my web browser, I also get a 404 Error.

  • Ozzy
    Ozzy about 12 years
    I think you're right about php pages needing a lot of variables to be set up. Actually I was just trying to find a quicker way to develop in PHP because at the moment i'm writing it in the web hosts text-editor (no syntax highlighting, etc), saving, then I have to switch tabs to refresh and check the site. I know this is totally the wrong way, thats why I thought using an IDE like Eclipse would be better. I wanted to develop it with something that wouldn't allow me to make typos and basic errors which occur often when you use a plain text editor.
  • Ozzy
    Ozzy about 12 years
    Okay I got this started! PHP 5.4.0 Development Server started... Any info on getting the setting right in eclipse? & Where should index.php be stored?
  • Xeoncross
    Xeoncross about 12 years
    @Ozzy, I use to use Ecplise PDT for everything when I was still on windows. It's an awesome IDE, and like I said, works great when combined with a full-featured browser like FF or Chrome that can provide request headers, AJAX info, and DOM information. I think my point is that you don't gain anything (and infact lose things) by running PHP through PDT instead of using a regular browser.
  • Xeoncross
    Xeoncross about 12 years
    On another note, did you know that you can edit your "hosts" file (C:\windows\system32\drivers\etc\hosts) to add fake domain names that point to your server? So instead of using http://localhost/MySite/index.php you can use a fake TLD like loc for things like http://mysite.loc/index.php. Just add a line with the domain 'mysite.loc' pointing to your IP address. Oh, and you need to create a "Virtual host" (vhost) file in your server to know to listen for that fake domain name.
  • Ozzy
    Ozzy about 12 years
    Okay, so yeah FF with Firebug would be much better to run the site. I didn't understand what you said about a vhost. Now I'm planning to develop in eclipse/PDT, and use the php built-in server on localhost like @wilmoore said, so I'll just leave the whole hosts thing and develop the site on my PC first (view it in FF), then upload it to the webserver when I'm done.
  • Ozzy
    Ozzy about 12 years
    Nevermind! I ran it like this: php -S localhost:3000 -t "C:/dev/mysite/" and now it runs from 'mysite'! Thanks
  • Xeoncross
    Xeoncross about 12 years
    @Ozzy, see my answer about including files here. Basically, you don't need to alter or use set_include_path() for anything. Just specify the full path to each file when you go to include it - it's faster that way anyway since PHP won't have too look through the include paths.
  • Ozzy
    Ozzy about 12 years
    thanks. I wish I could split the bonus between you both 100/100 but I don't think thats possible, and Xeoncross' answer was better, so I've accepted his. But thanks again for the info of the built-in server.
  • Wil Moore III
    Wil Moore III about 12 years
    @Ozzy not a problem. Given you like Xeoncross' answer better, it makes much more sense to award him the bounty. Glad my answer was somewhat helpful anyhow.
  • Ozzy
    Ozzy about 12 years
    +200, Thanks. Wonder if you know how to solve this one stackoverflow.com/q/10420831/1031312
  • Dan Chase
    Dan Chase over 5 years
    I know this answer was a long time ago, but don't forget developers are users as well. I've grown tired of spending all day troubleshooting just so that I can develop, and just switched to a good IDE like PhpStorm or Visual Studio with Php Tools.