Running (and Stopping) a Web Server with Symfony on Windows

Once you have your web application created in Symfony, it isn’t long before you learn you can run a server from the command line - that’s right, no need to install Apache, NGINX, Wamp, Xammp etc. etc. Let’s start up that server right away. Run a command shell:

Windows-Key-R
cmd
Press Enter

Go the root of your application:

> cd c:\myapp

Run the server:

> php bin/console server:run

As you can see, Windows needs a nudge to tell it to use PHP by default. You will now see something similar to:

That shows you which port to connect to - very useful! To end the server, whilst the command window is selected:

Press Control-C

Easy enough, right? If like me, though, you have a habit of running Windows Powershell ISE as your shell, you need to be careful because the server doesn’t play nicely in this situation and you will find you can’t end the server with control-c. In fact, even if you close PowerShell, that pesky server will continue running. If you find yourself in this situation, there is of course the “reboot” method, but if you don’t fancy that, you can use Task manager to end it for you:

Run Task Manager
Control-Alt-Delete
Select Task Manager
Click on Details
Sort by name by clicking on the heading
Find "php.exe"
Right-click on "php.exe", select End task
Click on End process

Do that for any others that you find, depending on how many times you ran the server. Can’t see PHP or are unable to work out which process has opened the port? This really shouldn’t happen but there is a command in Windows which can show you which process has which port open. Go back to the command shell:

Windows-Key-R
cmd
Press Enter

List the open ports:

> netstat -a -n -o

Zip through there looking for anything mentioning your port. So for example, let’s imagine we opened the server on port 8001:

TCP 127.0.0.1:8001 0.0.0.0:0 LISTENING 2676

That final column is the process ID. Now head back to the task manager:

Control-Alt-Delete
Select Task Manager
Click on Details
Sort by PID by clicking on the "PID" heading
Find php.exe
Right-click on "php.exe", select End task
Click on End process

Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com