Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Visual Studio Development Server to work with PHP?

I'm a .NET specialist working with a PHP/Flash programmer to deliver an app via IIS. After jumping through 17 hoops of fire and defeating a gargoyle in a gruesome battle to the death, I managed to get my IIS 7.5 server to cooperate with PHP, and now if you browse to my public web site, you can see the Flash objects happily doing their behind-the-scenes stuff with PHP, whatever that may be.

But... when I'm debugging my app using the VS Development Server, that still apparently doesn't know how to cope with PHP: I'm getting the same HTTP 405 (Method Not Allowed) errors that I was getting on IIS before aforementioned gargoyle breathed its last ("The HTTP verb POST used to access path '/php/blah.php' is not allowed.").

So, what do you have to do to get the VS Dev Server to play nice with PHP?

like image 377
Shaul Behr Avatar asked Jan 26 '11 17:01

Shaul Behr


3 Answers

My PHP Debugging Setup

I'm a .NET developer who has been swimming in the PHP pool for the past few months.

Spoiled by the VS.NET IDE, debugger, and strongly typed platforms, I was determined to create a PHP development environment that closely resembles my .NET debugging experience.

NOTE: It may be easy to setup PHP debugging in IIS for new PHP applications. However, the steps listed below break down some very involved steps as I found required to debug in WordPress and Joomla. Only follow these steps if you aren't having any luck with getting debugging to work.

Disclaimer: The full set of steps to complete this setup are quite involved. I'm throwing this together ad hoc in hopes it will help others in need of setting up a professional development environment with little background in Linux based systems.

These steps are not guaranteed to work and may be very sensitive to environment settings. I spent a lot of time going through the effort of trial and error until I got this working.

Along the way, I have to give credit to a few good online resources you should review to get started. These do not address debugging or development setup. I'll provide details below.

Step by Step Guide: Installing XAMPP and WordPress on Windows

Since I'm new to posting here, I can't add more than one link. Just Google the following references: - Google: sixrevisions tutorials web-development-tutorials using-xampp-for-local-wordpress-theme-development

Securing Your XAMPP Installation

  • Google: robsnotebook xampp-builtin-security

DEVELOPMENT SETUP

WAMP Stack vs IIS for PHP:

First, I did not use IIS to host my PHP application. I wanted to keep these web servers separate and use one of the available WAMP Stacks to develop against. This allowed me to manage and study configuration settings that would be used on Apache and Linux. If I was deploying the PHP App to a Windows host, I would have chosen an IIS setup. Again, this was a choice based on creating similar configured environments with a Linux host.

What is WAMP Stack?

For those unfamiliar, a WAMP Stack stands for a distribution package of Apache, MySQL, and PHP running on Windows. Other flavors include LAMP (for Linux), MAMP (for MAC), and others. There are several flavors within the community that provides WAMP Stacks to work with. I originally found BitNami interesting to work with. However, I was not happy with the Control Panel used to manage the different services within the Stack.

Selecting XAMPP for Windows

At the end of the day, I went with a package called XAMPP (Cross Platform Apache, MySQL, PHP, and PERL). The second P in XAMPP provides PERL support that is lacking in the other WAMP Stacks (WAMPServer, bitnami, and a few others). I also like XAMPP because it has what appears to be a more active community and the stack has been very stable for me. Additional standout features of XAMPP to consider is support for hosting an FTP Server, apache based mail server. The option to run MySQL and Apachi as services or local running app is easily toggled with a click of a button.

Setting Up XAMPP for Development

Setup of XAMPP is straight forward. My experience is with the previous release 1.7.3. They just released 1.7.4. Go to:

  • Google: apachefriends xampp-windows

and scroll down the page till you see the install links. If you want to work with a release that has matured with some time, you can still find 1.7.3 at the following link:

  • Build Link: www (dot) apachefriends (dot) org (/) download (php) ?xampp-win32-1.7.3.exe

Installing XDebug for PHP Debugging

This applies to installing PHP on WAMP with Apache or on IIS. Selecting the correct version of this dll isn't straight forward.

First, go to:

  • Google: xdebug org download (php)

and review the various versions available. The versions are not very intuitive to parse. Follow this guide to understand it: Breakdown of XDebug Name: [php_xdebug-2.1.0-5.3-vc6.dll]

- XDebug version 2.1.0

- Compatible with PHP 5.3

- VC6: Use for Apache ver 1 or 2

    - VC6 indicates compiled with legacy Visual Studio 6 Compiler

- VC9: Use for IIS

    - VC9 indicates compiled with Visual Studio 2008. 

- NTS (not listed in the name above) indicates Non Thread Safe.

    - The version listed is thread safe.

PHP.ini Config Setting

NOTE: Since I've not set this up on IIS, I'm not sure what the specific settings are to apply. However, this is document throughout the web.

For WAMP/XAMPP:

  • Locate \php\php.ini file.

    • Comment out line by adding semi colon to start of line.

    ;zend_extension = "php\ext\php_xdebug.dll"

  • Locate [XDebug] Section

    • Use settings similarly listed below and set to your path:

    [XDebug]

    ;Common Settings

    zend_extension = "P:[Fully Qualified Path]\xampp\php\ext\php_xdebug-2.1.0-5.3-vc6.dll"

    xdebug.profiler_enable = 1;

    xdebug.profiler_output_dir = "P:[Fully Qualified Path]\xampp\tmp"

    xdebug.profiler_output_name = "xdebug_profile.%p";

    xdebug.remote_enable = 1;

    xdebug.remote_host = "127.0.0.1";

    xdebug.remote_port = 9000;

    ;Make sure your IDE setup on port 9000. Some will default to 7870.
    

    xdebug.trace_output_dir = "P:[Fully Qualified Path]\xampp\tmp";

    ;************ ;Needed for IDE Support ;************

    xdebug.idekey = "vsphp";

    ;This value can be arbitrary or may require something specific for your IDE.
    

    xdebug.remote_autostart = 1;

    xdebug.var_display_max_depth = 5;

Debugging with IDE

I use 2 IDEs to develop in PHP:

  • phpDesigner7

    • Google: mpsoftware phpDesigner
  • VS.PHP (a PHP plugin for VS.NET 2010).

    • Google: jcxsoftware vsphp

I want to love VS.PHP in VS.NET 2010, however, it's not the greatest experience in step through debugging. phpDesigner7 has been much better for debugging and access to local variables, intellisense, and using running eval commands during debugging. VS.PHP is so close to being great, but you will be frustrated if you have little patience. I still prefer it as my development editor of choice, even for PHP.

Regardless of IDE, most IDEs provide internal debugging support without any of the extra steps I listed above. However, these applications will launch the php app in a private webserver using IDE specific php.ini settings.

I'm doing a lot of custom integration with WordPress, Joomla, and .NET applications. Therefore, I need the debugger to use the php.ini settings for my various platforms. For me to debug these platforms, I configure my IDEs to essentially run in remote debug mode. The IDE and web server coordinate run time execution with the help of XDebug acting as a broker and providing the necessary debugging symbols to the IDE debugger.

Configuring IDE for Debugging

Final step is to configure your IDE so the debugger can connect to the web server.

The 3 settings to look for are as follows:

  • PHP-CGI: P:[Fully Qualified Path]\xampp\php\php-cgi.exe
  • PHP.INI: P:[Fully Qualified Path]\xampp\php\php.ini
  • Listen Port: 9000

Different IDEs may label these settings differently and require additional settings. These should be the most important ones to look for.

NOTE: Use [php\php-cgi.exe], not [php\php.exe] for debugging. The php-cgi.exe is required to run php.exe on windows.

I hope this gets you started with attaching your IDE to the web server, setting breakpoints, and doing a lot with line by line debugging.

like image 127
David Carroll Avatar answered Nov 09 '22 01:11

David Carroll


You will not be able to make Visual Studio Development Server work for PHP. However you can easily use IIS Express (http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx) which will not only give you PHP, but also install WinCache, URL Rewrite and other features that are super important for PHP development.
Also, note that other platforms like Classic ASP are supported as well, where in Cassini they are not.

like image 26
Carlos Aguilar Mares Avatar answered Nov 09 '22 00:11

Carlos Aguilar Mares


One option is to not run cassini and instead just get IIS installed on your dev box and run everything through there.

like image 31
NotMe Avatar answered Nov 09 '22 02:11

NotMe