roostaamir
roostaamir

Reputation: 1968

Debugging php applications on folders different than 'xampp/htpdocs' with PhpStorm

I know this may be a long and general question but I am struggling with it for the past two days and have achieved nothing.

I am a C# .net developer and I use Visual Studio IDE for my development which does all the back-end work for me when creating projects, setting virtual hosts, publishing the project and etc.

Now for some reasons I have to do a project in PHP and I chose PhpStorm as my IDE. I installed XAMPP and the Apache server is working ok, and I set its' php executable as an php interpreter in PhpStorm.

I don't want all my projects to be in xampp/htpdocs so I choose another location (d:\projects\phpStorm\<name of the project>) as my working space when I first created a project.

I installed xdebug using the tutorial it gave me:

Download php_xdebug-2.4.0rc4-5.6-vc11.dll

Move the downloaded file to C:\xampp\php\ext

Edit C:\xampp\php\php.ini and add the line

zend_extension = C:\xampp\php\ext\php_xdebug-2.4.0rc4-5.6-vc11.dll

Restart the webserver

And I can confirm that it is installed using phpinfo() in a php file located in xampp/htpdocs.

My problem is with the debugging. When I click Run->Run in an opened php file in PhpStorm, it uses a free port and opens the php file with a url like this: localhost:port_number/<name of the project> and everything is ok.

Now I followed this tutorial to configure the xdebug. In step two, when I go to Run->Web Server debug validation, fill the Path to create validation script with d:\projects\phpStorm\<name of the project> and Url to validation script with localhost:port_number/<name of the project> (as mentioned above) and click validate I get this information (and an error in the last line):

Server Name: PhpStorm 10.0.3

Loaded php.ini: C:\xampp\php\php.ini

No debug extension is loaded

Follow this links to configure Xdebug or Zend Debugger. If you have already configured debug extension in php.ini file check possible reasons why it was not loaded:

You forgot to reload web server after changes in php.ini file.

You are configuring debug extension in the wrong php.ini (see the loaded php.ini files below).

There are errors on attempt to load debug extension, e.g. version incompatibility.

I want to know what should I do?

I really really want to set my projects in another location other than xampp/htpdocs to organize them properly, just like I do it in Visual Studio. So please don't suggest solutions involving me changing my working directory.

Thanks in advance.

P.S.: In JetBrain's tutorial, I see that the xdebug's IDKEY is PHPSTORM whereas mine is my pc's username, it it ok?

Upvotes: 2

Views: 722

Answers (1)

mopsyd
mopsyd

Reputation: 1922

I really really want to set my projects in another location other than xampp/htpdocs to organize them properly, just like I do it in Visual Studio. So please don't suggest solutions involving me changing my working directory.

Well you're really going to hate this then, but unfortunately Apache (which is what php runs on) only recognizes htdocs (or public_html, or www, depending on what specific server you are running, but anyhow in your case only htdocs) as a valid directory for php execution. Sooooo...

That doesn't really mean this is hopeless, but you might have to jump through some silly hoops to get it to work this way.

Option 1

You may have some luck creating a symbolic link from .htdocs to your projects folder from the command line:

ln -s C:xampp/htpdocs d:/projects/phpStorm

If you're on windows, this probably won't work. It also likely won't work between drives. It also may not work depending on your Apache configuration in XAAMP.

PROS: If it works, will do exactly what you want.

CONS: Probably won't work, if it does, will require nightmarish levels of config fiddling

Option 2

Use a remote development server, and sync over FTP with your IDE. I'm not super familiar with PhpStorm, but I can pretty easily do this in Netbeans or Eclipse. This is a good option when you need a local archive of a project retained. You might be able to set up an FTP server on your machine and accomplish this, however you are going to wind up with two copies of your project; one in your projects folder and the other in htdocs.

PROS: Your projects stay organized where you want them without much issue.

CONS: File duplication, they will have to be in htdocs anyhow for Apache to run php

Option 3

Accept that the technology is not designed to work this way and just put everything in htdocs where it belongs. Resisting the way technology works because you are used to a different workflow is how design flaws and really bad bugs happen. Use it the way it was meant to work and don't be scared of learning new things.

PROS: No conflicts with the XAAMP stack whatsoever

CONS: You specifically stated you don't want to do it this way, but this is really the best way

Option 4 (Don't do this)

Install PHP as a globally accessible command line utility across your entire system, and consequently get all kinds of crazy viruses and errors that you may not be able to fix ever.

PROS: Minor alleviation of aggravation with foreign workflows

CONS: All of the things. The worst things.

Option 5 (probably not going to work)

Try using VirtualHosts. There's a bunch of caveats with this though. First, doing this between different drives is nearly impossible to configure correctly due to security policies in your operating system that are difficult to overrule. Second, if you're on Windows (I assume you are if you are using XAAMP), you need to do all of the following: -In apache.conf, you need to enable your hosts file. -In the vhosts file, you need to create a new vhost. -In the windows hosts file, you also need to create a host, because for whatever reason windows likes to arbitrarily add redundant steps. On every other OS, this step is not neccessary. Also, you need to run your text editor as administrator to even do this at all. -Restart apache when it's all set up -Pray your machine will let you do this between drives (C: -> D:), or not take a million years to enable.

Upvotes: 0

Related Questions