Skip to content

PHP on Linux

Gruxi supports serving PHP applications on Linux using PHP-FPM. This setup allows you to run PHP applications efficiently and with good performance. Gruxi can also serve PHP applications on Windows using PHP-CGI, and we have optimized the experience for that as well. See our PHP on Windows example for more details on that.

With Gruxi, you can have multiple PHP versions installed and easily switch between them for different sites or applications. This is useful for testing applications against different PHP versions or hosting multiple applications that require different PHP versions on the same server.

How to set up Gruxi to serve PHP applications on Linux

On Linux, you might have one of these setups.

  • PHP in a Docker or another container environment
  • PHP-FPM running directly on Linux

However you have PHP set up, if it is based on PHP-FPM, Gruxi can connect to it using FastCGI and serve your PHP applications.

Let's assume you want to serve a PHP application located in /var/www/html. 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 /var/www/html
  5. Add a PHP Processor Priority 2 under Processors.
    • Set the Served By to PHP-FPM.
    • Set the local web root to the directory where your PHP application is located on your Linux filesystem. For example, if your PHP application is located in /var/www/html, set the Local Web Root field to /var/www/html.
    • Set the FastCGI IP:Port to <docker-php-fpm-host>:9000, such as 127.0.0.1:9000.
    • Set the FastCGI Web Root to where the web root is located in the Docker container or local path, depending on your setup. This is often /var/www/html for official PHP images, but it can vary depending on the image you are using.

Save that configuration and reload it in the admin portal. You should now be able to serve your PHP application with Gruxi on Linux.