Stop running PHP server, command line

Stop running PHP server, command line

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Stop running PHP server, command line

You just launched php -S localhost:8000, and now your terminal is occupied with a process that isn't quite doing what you think it is. The prompt is gone, replaced by a listening status indicator, and port 8000 is bound to a local server instance created by the PHP CLI daemon. While this is an excellent way to quickly test a script or a specific route without setting up a full web stack, the moment you decide you need that port back for another application, or simply want to free up your terminal session, you have to know exactly how to terminate it cleanly.

The command php -S localhost:8000 starts an internal PHP server built directly into the PHP interpreter. It is not a separate daemon running in the background like Nginx or Apache; it is a foreground process attached directly to your current shell session. This architectural detail is crucial because it dictates how you stop it. Unlike system services managed by systemctl, this process dies when its parent shell dies, but it will also die immediately if you send it the correct termination signal.

To stop the server instantly, look for the control characters in your terminal output. When the server starts successfully, it usually displays a message indicating that it is listening on the specified port. At the very top of that output block, or sometimes at the bottom depending on the PHP version, you will see a prompt like [Sat Oct 26 12:34:56 2024] PHP Development Server started. More importantly, if you scroll up in your terminal history before the server started, or check the documentation for the specific PHP build you are using, you might find instructions to press Ctrl + C.

However, relying solely on memory isn't enough for a professional workflow. The most reliable way to stop this process is to send an interrupt signal. In Unix-like systems, the standard signal for stopping a running foreground process is SIGINT, which corresponds to the keyboard combination Ctrl + C. When you press this key while the server is active, the PHP interpreter receives the signal and immediately halts execution, unbinding the port and returning control to your command prompt. This is the intended behavior for CLI tools designed for development environments.

If you cannot find a visible process indicator or if the terminal has scrolled past the startup message, you can verify the running processes using system tools. Run ps aux | grep "php.*-S" to list all PHP processes that match the server pattern. This command filters the process list to show only those spawned by the -S flag. You will likely see a line with a high process ID (PID). Note this number carefully. Once you have the PID, you can force the termination using the kill command:

kill <PID>

For example, if your process ID is 12345, the command becomes kill 12345. If the standard kill doesn't respond immediately, which happens if the PHP script holding the port is stuck in a specific state, you may need to send the stronger SIGKILL signal:

kill -9 <PID>

While kill -9 is forceful and does not allow for graceful cleanup, it is rarely necessary for the built-in server unless the process has become unresponsive. The default behavior of the PHP built-in server is to handle signals gracefully by design.

There are scenarios where simply pressing Ctrl + C might not be enough. If you have configured your application to listen on a port that is also used by another service, or if you are running multiple instances of the PHP server simultaneously in different shells, ensuring the correct process is killed becomes vital. Always double-check the output of ps aux | grep "php.*-S" before sending a kill signal to avoid terminating unrelated processes.

If you are working within a larger development environment where port conflicts are a frequent issue, consider using a tool like fswatch or a dedicated process manager that can handle restarting these services without manual intervention. However, for quick testing and ad-hoc debugging, the built-in server remains a powerful utility provided by Laravel itself and other PHP frameworks. Remember that once you stop it, the port is immediately available for your next application, such as an API running on Node.js or a database service like MySQL.

For those looking to streamline their local development setup further, resources like https://laravelcompany.com offer insights into modernizing PHP workflows, including how to manage these server instances more efficiently alongside full-stack deployment strategies.

Our network