skip to Main Content

I ran into issues with PHPStorm not delivering the website, but returns HTTP 404. I need to setup PHPStorm in a way that it does not serve files from a subdirectory. I know, numerous questions like this have been asked before, so I’ll make quite clear what I have configured and tried.

I’m on Windows 10 1903 and I’m using PHPStorm 2019.3 (latest version at the time asking this question)

  1. I have added an entry in C:Windowssystem32driversetchosts to get a name mapped to localhost

    # localhost name resolution is handled within DNS itself.
    #   127.0.0.1       localhost
    #   ::1             localhost
    
    127.0.0.1   eigener-prozessor
    
  2. I can ping it

    C:UsersT>ping eigener-prozessor
    
    Pinging eigener-prozessor [127.0.0.1] with 32 bytes of data:
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    
    Ping statistics for 127.0.0.1:
        Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
    
  3. In PHPStorm, the debugger is set to port 63342. And I allow unsigned requests (not sure if that really has an effect). I can’t check “external connections”.

    Debugger port

  4. In PHPStorm, I have set up an in-place deployment as default, using the host and debugger port

    Inplace deployment

  5. I made sure the mapping is on the root path

    Mapping

  6. I have renamed my project to match the host name (File / Rename Project …)

    Project name

  7. I have configured a PHP CLI interpreter and made a php.ini available

    PHP interpreter

  8. I have marked the source and resource directory

    Directory configuration

  9. I do make sure that I do not open a local file in a browser but use the buttons for that

    Use buttons

  10. It brings me to the correct URL but with HTTP 404. You can see that it serves from PHPStorm 2019.3.1, which is basically correct

    Resulting HTTP 404 page

  11. In the web developer tools, I see that the IP address is 127.0.0.1

    Web developer tools

I have used the following SO questions as input:

I have also tried:

  • using Chrome instead of Firefox

If I add eigener-prozessor as a subdirectory, the website can be accessed – but the resources cannot be loaded, because they point to /css/something.css, which is exactly why I went through all these steps.

URL with subdirectory

I’m out of ideas. How do I configure the built-in webserver to serve its stuff on the root (/)?

Please do not suggest a workaround like “use Apache” or “change the path to your resources”. I have paid for the software and I expect the built-in webserver to work.

2

Answers


  1. Unless I misunderstood something, a simple way to achieve what you need would be to create a custom Run Configuration of type PHP Built-in Web Server:

    • Type Ctrl+Shift+A (or double shift) and look for Edit Configurations...
    • Hit the + button on the top left to add a new one
    • Select PHP Built-in Web Server
    • Set Host to “eigener-prozessor”, Port to 63342.
    • The Document Root field should default to the root of the project, otherwise set it to that
    • Rename configuration, adjust other values if needed, then click OK

    You should then simply be able to run said configuration with the green triangle/associated hotkey and access the project files directly under http://eigener-prozessor:63342/.

    Login or Signup to reply.
  2. The trick with hosts file doesn’t work anymore, please follow WEB-38141 for updates. So there is currently no way to set up the built-in web server to serve files from root

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search