Skip to content

Gruxi with PHP on Windows

PHP Logo

Gruxi can serve PHP applications on Windows. This is useful for developers who want to run PHP applications on their local machines or host PHP applications on Windows servers. Gruxi's high performance and low latency make it an excellent choice for serving PHP applications, even under high concurrency.

We understand what PHP developers on Windows need (we have been there), and we designed Gruxi to meet those needs. Whether you are developing a simple PHP application or a complex web application, Gruxi can handle it with ease, providing fast and reliable performance.

To Gruxi, PHP on Windows is not a "side quest" but a core use case we have optimized for. We have made sure that Gruxi can efficiently serve PHP applications on Windows, providing a seamless experience for developers and users alike.

Multiple PHP Versions on Windows with Gruxi

Being able to change PHP versions on Windows is important for developers who need to test their applications against different PHP versions or have multiple projects that require different PHP versions. Gruxi makes it easy to switch between PHP versions on Windows, allowing developers to quickly test their applications with different PHP versions without having to manually reconfigure their server or environment.

Learn more about how to set up multiple PHP versions.

How to set up Gruxi to serve PHP applications on Windows

Gruxi focuses on making it easy to get started with serving PHP applications on Windows, without a lot of configuration and complexity.

On Windows, you have a few options depending on your setup.

  • PHP in a Docker environment
  • PHP directly on Windows

Let's assume you want to serve a PHP application located in C:\my-php-app. You can set up Gruxi to serve that application as follows:

  1. Log in to the admin portal and open the configuration.
  2. Add a Site and fill out the hostnames (or keep the default).
  3. Add the rewrite function OnlyWebRootIndexForSubdirs to the site, which is useful for many PHP applications, such as WordPress and Laravel. This allows requests to subdirectories that do not exist on the filesystem to be rewritten to the web root, which is important for many PHP applications that rely on URL rewriting for routing.
  4. Add a Static File Processor Priority 1 under Processors.
    • This handles requests for static files
    • Point the Web Root to C:\my-php-app
  5. Add a PHP Processor Priority 2 under Processors.
    • Follow the directions below for either the Docker setup or the direct Windows setup, depending on your choice.

PHP in a Docker environment

Docker Logo

This setup provides good isolation from the host system and allows you to easily manage multiple PHP versions by using different Docker images. The downside is that it adds overhead due to running Docker, especially when sharing files with a Windows filesystem, and it is not as performant as running PHP directly on Windows. However, for development purposes, the convenience and ease of use can outweigh the performance considerations.

In this setup, you would run PHP in a Docker container in PHP-FPM mode and then configure Gruxi to connect to the PHP-FPM server running inside the Docker container using FastCGI. This allows you to serve PHP applications with Gruxi while keeping the PHP environment isolated in a Docker container. This is essentially the same setup you would have on Linux, but with the added layer of Docker on Windows.

For this setup, you would configure the PHP Processor like this:

  • Set the Served By to PHP-FPM.
  • Set the local web root to the directory where your PHP application is located on your Windows filesystem. For example, if your PHP application is located in C:\my-php-app, set the Local Web Root field to C:\my-php-app.
  • Set the FastCGI IP:Port to <docker-php-fpm-host>:9000, such as php-fpm7:9000.
  • Set the FastCGI Web Root to where the web root is located in the Docker container. This is often /var/www/html for official PHP images, but it can vary depending on the image you are using.

PHP directly on Windows

This setup provides better performance compared to running PHP in a Docker container in most cases, as it eliminates the overhead of running Docker and sharing files with a Windows filesystem. With Gruxi, this setup is straightforward and easy to configure.

Gruxi utilizes the built-in FastCGI support in PHP for Windows (starting from PHP 7.1), where some needed changes were made in PHP. Gruxi uses PHP-CGI and manages the FastCGI processes for you, so you do not need to set up a separate PHP-FPM server. This means Gruxi starts it, stops it, and restarts it as needed, making it easy to manage PHP on Windows.

For this setup, we first need to set up the managed instances of PHP. This is done in the "Managed External Systems" section.

  1. Set up a managed instance for PHP. See our guide on managed external systems for instructions.

  2. For this setup, you would configure the PHP Processor like this:

    • Set the Served By to Windows PHP-CGI (managed).
    • Set the Local Web Root to the directory where your PHP application is located on your Windows filesystem. For example, if your PHP application is located in C:\my-php-app, set the Local Web Root field to C:\my-php-app.
    • Set the PHP-CGI Handler to point to the managed instances of PHP that you set up in step 1. For example, if you set up a managed instance for PHP 8.0, select that instance here.

Save that configuration and reload it in the admin portal. You should now be able to serve your PHP application with Gruxi on Windows. Gruxi will manage the PHP-CGI processes for you, so you do not need to worry about starting or stopping them. You can focus on developing your PHP application, and Gruxi will take care of the rest.

Learn more about the PHP processor

To learn more details about the way Gruxi supports PHP, check out the PHP processor documentation.