1

What I was trying to do is, I want to run a local php server and then open http://localhost:8000 in chrome. I made a bat file in my windows 10 OS for this. Here's my first attempt:

php -S localhost:8000 -t C:\User\Projects\Sandbox 
http://localhost:8000

The problem with this was after the first line is executed the cmd get stuck in a loop of listening to the server and the second line never gets execute. Plus, I don't want to open localhost webpage first because it keep showing the error for a few secs untill php does it's thing. Now the solution I found was the following bat file:

start php -S localhost:8000 -t C:\User\Projects\Sandbox 
start http://localhost:8000

This does the job, but I saw a weird behaviour. I expected the first line to open a new cmd window and execute php -S localhost:8000 -t C:\User\Projects\Sandbox, but what it does is, it opens a new cmd window and executes this start php -S localhost:8000 -t C:\User\Projects\Sandbox. This opens php's own shell(which has a php logo) and then goes on to execute -S localhost:8000 -t C:\User\Projects\Sandbox in that new console.

  1. If I do start php in cmd, it opens the php shell. Then, if I go -S localhost:8000 -t C:\User\Projects\Sandbox inside that php shell, it doesn't open local server, why?

  2. When I run the bat file why doesn't start opens a new cmd window and puts php -S localhost:8000 -t C:\User\Projects\Sandbox and keep the cmd window? Instead why does it put start php -S localhost:8000 -t C:\User\Projects\Sandbox in that new cmd window, exits and opens php shell?

  3. Is there any way to keep the server running in cmd window and then somehow open the localhost webpage?

4
  • Please read Start - Start a program - Windows CMD - SS64.com and look at the syntax of start.
    – DavidPostill
    Commented Jan 26, 2020 at 12:17
  • @DavidPostill Yes, I have, this one, START "title" [/D path] [options] "command" [parameters]. I assume it takes php as command to execute with -S localhost... as parameters. But, then if I run php -S localhost... straightaway in cmd why doesn't it open the php shell then?
    – user31782
    Commented Jan 26, 2020 at 13:22
  • I've no idea. I don't use php.
    – DavidPostill
    Commented Jan 26, 2020 at 13:25
  • That's alright, bloke.
    – user31782
    Commented Jan 26, 2020 at 13:34

1 Answer 1

0

Maybe use 1st in backgound?

start "" /b


@echo off

rem :: use cd /d path to php

cd /d "c:\php"
start "" /b php -S localhost:8000 -t C:\User\Projects\Sandbox 
start "" http://localhost:8000

Take a look here about multi session in php

8
  • Could you elaborate on how /b flag stops the php shell, how does it start the server in the background, then switch to second start localhost statement and then brings back the background running server to the main cmd window?
    – user31782
    Commented Jan 27, 2020 at 5:04
  • @user31782 forgive me se. I think you may need a new question, change the scope from original question is not allowed.
    – Io-oI
    Commented Jan 27, 2020 at 11:55
  • Would you be able to answer #1 and #2 of my question?
    – user31782
    Commented Jan 27, 2020 at 14:15
  • @user31782 Well, i'll try for sure...
    – Io-oI
    Commented Jan 27, 2020 at 14:25
  • Maybe not sure also, if will be only bat (100% pure bat), or (hybrid with vbs+bat/powershell+bat )
    – Io-oI
    Commented Jan 27, 2020 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .