How to change PHP mode in FastPanel
FASTPANEL allows you to choose one of four PHP operating modes for each site:
-
PHP as an Apache module
-
PHP-FPM
-
FastCGI (FCGI)
-
CGI
To select PHP mode, open “Settings” menu in Site card. Please note: any mode other than “Apache module” allows you to use an alternative version of PHP - provided it is installed in the panel.
Which mode is better to choose?
The choice depends primarily on whether the site uses .htaccess, and whether an alternative version of PHP is needed.
-
If the site does not use .htaccess, it is recommended to choose PHP-FPM.
-
If the site uses .htaccess and the main (system) version of PHP is suitable, choose PHP as an Apache module.
-
If the site uses .htaccess, but you need an alternative version of PHP, FastCGI is the best option.
-
The CGI mode should be considered as a backup option - if for some reason the site does not work correctly in other modes.
Below is a short and to the point description of each mode.
PHP as an Apache module
This mode uses the system default PHP version. The scheme of operation is as follows: Nginx acts as a frontend server, and Apache acts as a backend, and PHP scripts are processed through the module mod_php.
Apache runs in MPM ITK mode, so each site can be executed by a separate user, which is convenient from an isolation point of view.
FastCGI
This mode allows you to switch between PHP versions. As in the previous version, Nginx remains the frontend server and Apache the backend server, but PHP scripts are handled via mod_fcgid.
A feature of FastCGI is that PHP processes can remain in memory and handle multiple requests in a row. Thanks to this, the startup overhead is reduced, and the processing of PHP scripts becomes faster, which has a positive effect on the speed of the site.
The FastCGI mode is usually recommended when a site requires an alternative version of PHP.
PHP-FPM
The PHP-FPM mode also supports selecting different PHP versions, but the architecture is different: the backend part is performed by PHP-FPM, and Nginx remains the frontend server.
It is important to consider a nuance: in PHP-FPM mode, .htaccess files are not processed, so all rules and settings from .htaccess must be transferred to the Nginx configuration.
CGI
This mode also allows you to use alternative versions of PHP, but it works differently: Apache acts as a backend and for each request creates a separate PHP process. Because of this, CGI is usually less efficient in terms of performance, so it is most often only used when other modes are not suitable for some reason.