How to set a subfolder in your project as the webroot directory.

Hello,

Firstly I'm a new user and currently testing out the 30 day trial. So far I am really liking what I see, but I have one issue that is perplexing me and I need a little help!

Also, before I continue can I point out I have searched these forums for over an hour in the quest for my answer, and whilst I came tantalizingly close, the exact problem I have does not appear to be answered!
I also completely understand (I hope) the feature of marking folders as RESOURCE ROOTS etc.

My issue is that with my project set up, any time I try and open a file or script in my project with the OPEN IN BROWSER option, a spurious extra "www" appears in my URL in the browser causing an obvious 404 error because I can't seem to tell phpStorm that my www subfolder is my actual webroot folder like I could with netbeans.

Eg, instead of phpStorm opening:

http://www.testproject.com/scripts/test.php   it tries to open:
http://www.testproject.com/www/scripts/test.php

Like so many other people here, I have a project that looks like this on my windows machine: (Taken from http://devnet.jetbrains.net/message/5279088#5279088)

D:\projects\testproject.com
    \app -- your application code
        \config
    \library -- 3rd party libraries
        \Smarty
        \Zend
    \www-- your web root
        \css
        \images
        \javascript
        \media -- writable, your product images etc

        \scripts
        index.php
        robots.txt
    \var
-- temp/writable folders
        \cache
        \logs
        \temp
        \uploads



I have marked my www as a RESOURCE ROOT. To help with explaining how I have set things up, here are some screenshots.

I have set up the deployment as follows (I've replaced all my server names with "testserver"):

Connection: Image 1

                    The ftp connection works fine, the web server root URL opens correctly when I press OPEN. When phpStorm logs into my ftp server, it arrives at the / (root) folder. My www directory is directly under root. ie /www/<my html and php files>

Mappings: Image 2
               The local path is the top folder of my project directory. Deployment path is the same as my ftp root folder as that is where the system starts once it logs in. Web path is also / because if I add anything else here I get http://www.testserver.com/xyz which i definately don't want.

Directories: Image 3
                I've set my WWW folder to Resource ROOT, but that doesn't seem to help me in the problem I have (although it does help for autocomplete).

Demo of problem: Image 4

As you can see, in this case I've chosen a file called /www/cron/dilbert.php and tried to open it using the open in browser command. (Image 5)

My browser opens and in the URL I see:

http://www.testserver.com/www/cron/dilbert.php

What do I have to do to make this open with:

http://www.testserver.com/cron/dilbert.php


It seems so simply yet I am going mad trying to fix this! Many thanks if you can help.







This threads were close but didn't seen to answer my questions:
http://devnet.jetbrains.net/thread/287303
http://devnet.jetbrains.net/message/5270657#5270657
http://devnet.jetbrains.net/message/5459952#5459952
http://devnet.jetbrains.net/message/5457716#5457716

Message was edited by: Jon Wilson



Attachment(s):
4.jpg
3.jpg
2.jpg
1.jpg
5.jpg
9 comments
Comment actions Permalink

Hi Jon,

Please try this:

  • Settings | Deployment
  • Find your deployment entry
  • Switch to "Mappings" tab
  • Click on "Add another mapping" button
  • There type the path to your website root in left side (which I assume will be "D:\projects\testproject.com\www" and "/" in second column)


This works for me (just tested) for opening in browser on local server. But if your webserver is remote one (I mean -- FTP/SFTP/FTPS/Mounted Folder), then I do not think that this approach will work well (as actual deployment will most likely be failing -- uploading into wrong location).

Nevertheless, I think this is the ticket to watch after (although I can be wrong): http://youtrack.jetbrains.com/issue/WI-11672

0
Comment actions Permalink

Hello Andriy,

Thank you very much for taking the time to reply. I have followed your instructions exactly and indeed, it appears to work for when I open a file using the OPEN BROWSER command, the extra www path has been removed. However, indeed when I deply my files to a remote server (via FTP) and the new/updated files are being uploaded to the wrong folder.


If my REMOTE web server has the following file structure:

    \bin

    \etc
    \hg
....lots more...
    \www
        \scripts

     ....lots more...


    \var


And I try your solution, a file that was on my local computer in D:\projects\testproject.com\www\scripts\testfile.php now gets uploaded to /scripts/testfile.php!

We've fixed one problem and created another!

Thank you though, that ticket looks fairly like what I'm also hoping to do.

I'm just surprised though that I'm the only one that has a problem with this. How do the rest of you manage this situation - it's very normal to have folders outside the "webroot" folder in your project.....libraries, config files etc. How do other people manage!?
0
Comment actions Permalink
I'm just surprised though that I'm the only one that has a problem with this. How do the rest of you manage this situation - it's very normal to have folders outside the "webroot" folder in your project.....libraries, config files etc. How do other people manage!?

Easy -- very easy (at least the way how I do it).

I just do not use 'Open in Browser" functionality (surprise!):

  1. Proper upload is MUCH-MUCH more important
  2. Nearly every project these days uses nice urls (URL Rewriting) and therefore "Open in Browser" is pretty much useless
  3. But even if I need this functionality -- I have everything local (on my computer, no deployment involved at all -- "In Place" entry type) -- and I can have one entry for local dev/testing and another one (or two) for remote testing/production (I can choose which entry to mark as Default whenever I need + there is separate action that allow to upload to non-default deployment entry). Obviously (since you are using FTP) this one is not applicable to your situation (unless you are happy to have 2 entries defined and every time you need to use "Open in Browser" it will use Default one (with modified mapping) and when upload is required -- you will have to use "Upload to.." chooser everytime).
0
Comment actions Permalink

1) Proper upload is MUCH-MUCH more important


    I agree - I need this very much!

    2) Nearly every project these days uses nice urls (URL Rewriting) and therefore "Open in Browser" is pretty much useless



    I'm not sure that I follow on this example - I haven't mastered things like MVC programming etc. yet, but whilst we all have fancy rewriting enabled - take a standard example similar to above

    If my memory serves me right, someone using a MVC style of programming accesses their entire application through their index.php file? If that index.php file is in the www folder (similar to above) any attempts of even opening that on the remote server will cause phpStorm to try to open the wrong URL? How are people testing their code here? I am overlooking a feature in phpStorm at the moment?

    But even if I need this functionality -- I have everything local (on my computer, no deployment involved at all -- "In Place" entry type) -- and I can have one entry for local dev/testing and another one (or two) for remote testing/production (I can choose which entry to mark as Default whenever I need + there is separate action that allow to upload to non-default deployment entry). Obviously (since you are using FTP) this one is not applicable to your situation (unless you are happy to have 2 entries defined and every time you need to use "Open in Browser" it will use Default one (with modified mapping) and when upload is required -- you will have to use "Upload to.." chooser everytime).

    Indeed, I do not have a local development webserver set up, mainly because I work on projects on multiple computers (laptop and 2x desktops) and so recreating a full webserver on those machines with all the required services running would be an admin headache. I can understand the ability to flick between those profiles, but it seems a bit cumbersome unfortunately.


    I have found a query that was asked on stackoverflow (albeit regarding a different IDE product) that sums up my issue perfectly. The answer provided there does solve my problem, but not on phpStorm! :(
    http://stackoverflow.com/questions/10266736/netbeans-php-project-properties-what-does-web-root-do

    And here's what it looks like in the project settings screen:
    http://netbeans.org/kb/docs/php/project-setup.html#sources





    Anyway, I suppose I have one more question now. If this isn't a feature currently available, where can I go to request it?

    Thanks again Andriy.

    0
    Comment actions Permalink

    I'm not sure that I follow on this example - I haven't mastered things like MVC programming etc. yet, but whilst we all have fancy rewriting enabled - take a standard example similar to above

    If my memory serves me right, someone using a MVC style of programming accesses their entire application through their index.php file? If that index.php file is in the www folder (similar to above) any attempts of even opening that on the remote server will cause phpStorm to try to open the wrong URL? How are people testing their code here? I am overlooking a feature in phpStorm at the moment?

    Please explain how you expect to open such URL if it will be routed through index.php and the actual routing will be done there (in PHP code): myproject.dev/customer/orders/history (there will be no such files under web path -- the only executable file visible to the web is index.php, everything else is outside website root; and you cannot pass path to controller/action via parameter)


    Generally speaking:
    1) Type URL of your project in browser
    2) Bookmark it
    3) Open it via Bookmark (in browser) .. or if preferred to be done so from PhpStorm -- use "Run/Debug Configuration" functionality -- it will open the browser with predefined URL for you (so you can save yourself from making 1-2 extra clicks outside of IDE -- opening browser and clicking on bookmark)
    4) Navigate to URL in question (in case you are testing something that requires login (customer area) or specific conditions met (basket page, checkout process, payment page etc).

    When you debugging something (be it PHP or just CSS/HTML) -- same as above .. just instead of opening URL from scratch (depends on actual page, of course) just refresh the page in browser (F5).

    0
    Comment actions Permalink
    Anyway, I suppose I have one more question now. If this isn't a feature currently available, where can I go to request it?

    1) I'm pretty sure that I gave you the link to the ticket that should address this problem in my first reply.

    2) Use Issue Tracker (if you think that aforementioned ticket does not addresses your problem and you want to submit your own/better on)

    0
    Comment actions Permalink

    Hello, please accept my apologies for the delay in reply, I'm only back in the country after being away with work for  2days.

    You're absolutely right, the choice of MVC in my example above was a silly one, had I thought about it more I would definately not have used it. I should have stuck to my own use case which are scripts in seperate folders under the httpdocs folder that do not require variables or action/controllers to be passed to them when run.

    Your workaround is perfectly reasonable, but a little bit cumbersome. I appreciate you creating it though, it looks like that will be what I will have to use - thank you.

    As regards the ticket you linked in your first post, I read that ticket as someone asking for the ability to set a webroot so that their autocomplete worked in a fashion that suited them. It did not leed me to believe that it would have altered the ability to launch a file in the browser with a modified/changed URL compared to the folder structure in the project.

    Am I wrong in seeing that? I think the ticket is very close to what Im asking for only it doesn't cover the open in browser feature. Perhaps I'll just add the request on that thread/issue.

    Thanks again.

    0
    Comment actions Permalink

    Well -- for me if "this-is-website-root-folder" option will be provided I would extremely surprised if it will not be used when creating URLs for opening in browser as well, but just for resource checking (as this one currently done by marking such folder as resource root). But that is my expectation.

    That's why you have 3 choices here:

    1. Do nothing (leave ticket as is) and hope it will be coded appropriately (that devs will use common sense and will make it work as it should straight away)
    2. Comment the ticket to clarify this moment (in case it is unclear/not so obvious)
    3. Create your own ticket with this particular aspect only (so your ticket related to/depends on that one), This makes perfect sense if you think that this moment can be easily overlooked during original request implementation -- separate ticket ensures that this moment is not lost (it may be forgotten and put on hold till better days, but at least it is on record/todo list) + it's a bit easier for developer as well (bunch of smaller tasks can be done faster/easier than the same but all-in-one -- all least from time management/psychological point of view) .


    In any case the main question is -- will they bother to look at this for v6 .. or will they push it to 7-8-9-xx version again (as with quite a few much more popular tickets) ?..

    0
    Comment actions Permalink

    I've gone for option 3. I think it makes the most sense.

    http://youtrack.jetbrains.com/issue/WI-15169


    (I did borrow some of your very nicely formatted folder structure example here: http://youtrack.jetbrains.com/issue/WI-12345 I hope you don't mind!) Fingers crossed it doesn't turn out to be a version 10/11/12 feature! :)

    0

    Please sign in to leave a comment.