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:
- Log in to the admin portal and open the configuration.
- Add a
Siteand fill out the hostnames (or keep the default). - Add the rewrite function
OnlyWebRootIndexForSubdirsto 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. - Add a
Static File ProcessorPriority 1 underProcessors.- This handles requests for static files
- Point the
Web Rootto/var/www/html
- Add a
PHP ProcessorPriority 2 underProcessors.- Set the
Served BytoPHP-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 theLocal Web Rootfield to/var/www/html. - Set the
FastCGI IP:Portto<docker-php-fpm-host>:9000, such as127.0.0.1:9000. - Set the
FastCGI Web Rootto where the web root is located in the Docker container or local path, depending on your setup. This is often/var/www/htmlfor official PHP images, but it can vary depending on the image you are using.
- Set the
Save that configuration and reload it in the admin portal. You should now be able to serve your PHP application with Gruxi on Linux.