How can I run a php without a web server?

How can I run a php without a web server?

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

Stefan Bogdanescu

Founder & Senior Architect

Running PHP Without a Web Server: CLI vs CGI and Configuration Pitfalls

You can absolutely execute PHP scripts without installing a web server like Apache or Nginx, but doing so requires shifting your mindset from HTTP request handling to command-line scripting. The core distinction lies in how the engine is invoked. When you need PHP to run outside of a browser environment, you are typically interacting with the CLI (Command Line Interface) binary, not the CGI variant designed specifically for web server integration.

Choosing the Right Binary

The confusion often stems from mixing up the different executables provided during installation. On Windows systems, this is particularly evident with DLL files like php5ts.dll. If you are trying to run a script via command line and encounter a "missing php5ts.dll" error, it usually means the CLI binary cannot locate its required threading support library.

When installing PHP, you must ensure that the specific CLI package is selected. In modern distributions, this is often a separate file from the Apache module version. If you installed a standard installer, look for an executable named php-cli.exe or simply php.exe. This binary is self-contained and does not rely on a web server daemon to function. You do not need to configure any preferences within the installation wizard specifically for "CGI" mode unless your explicit goal is to make PHP act as a CGI daemon (e.g., running via FastCGI with Nginx), which is a different architecture entirely from standard CLI execution.

Resolving DLL and Configuration Issues

The specific error regarding php5ts.dll indicates a threading library dependency issue, common in older PHP versions like the 5.3.x series mentioned in your inquiry. Placing this DLL manually into the ext folder is incorrect; dynamic link libraries belong in the system's load path or alongside the main executable, not inside an extensions directory.

To resolve this without a web server:

  1. Verify the Binary Location: Ensure you are calling the script using the full path to the CLI binary (e.g., C:\php\php.exe myscript.php).
  2. Check PATH Variables: Add the directory containing php.exe and your DLLs to your system's environment variable PATH.
  3. Inspect php.ini: You may need a valid php.ini file in the same directory or referenced via -c. In PHP 5.3, ensure that the extension=php_pdo_sqlite.dll (or similar) entries are uncommented only if the corresponding DLLs exist in the ext folder.

Regarding your question about version suitability: PHP 5.3.3 is quite old and lacks support for modern extensions and security patches. While it can technically run scripts from the command line, relying on such an old version introduces significant stability risks. The threading model changes between PHP versions (from Zend Engine to Zend Engine MM in later versions) often break DLL compatibility if you try to mix binaries from different installation contexts.

Execution Workflow

Once the environment is stable, running a script is straightforward. You bypass the web server entirely by using the terminal or PowerShell:

C:\php\php.exe "C:\path\to\your\script.php"

If you need to pass variables or handle input streams, PHP's standard I/O functions work identically whether the script is invoked via CLI or CGI. However, remember that certain SAPI-specific modules (like apache2handler or specific session handlers optimized for web daemons) might behave differently or be unavailable in a pure CLI context.

If your workflow involves generating dynamic content that needs to serve HTML to a browser without a full server stack, you can still use the CLI binary to generate the output and pipe it directly into a browser window or save it to a file. This approach is useful for headless testing or automated reporting tasks where setting up a full LAMP/LEMP stack is overkill.

For more robust development environments, consider upgrading to a modern PHP version (8.x) where CLI and web server binaries are clearly separated by architecture rather than relying on obscure DLL swapping. This separation ensures that the php5ts.dll type errors vanish, replaced by cleaner module loading mechanisms found in current distributions.

Our network