Apache does not natively support PHP scripts without a special module. The module that tells Apache how to handle PHP scripts is referred to as a PHP handler. Without a properly configured module, Apache will just send you the PHP file as a download since it doesn't know what else to dono admite de forma nativa scripts PHP sin un módulo especial. El módulo que le dice a Apache cómo manejar los scripts PHP se conoce como un controlador PHP. Sin un módulo configurado correctamente, Apache simplemente le enviará el archivo PHP como descarga, ya que no sabe qué más hacer.
| Table of Contents | ||
|---|---|---|
|
...
¿Qué controladores admiten cPanel y Plesk con Apache?
| cPanel | Plesk |
|---|---|
| DSO/mod_php | Apache Module/mod_php |
| CGI | CGI |
| FCGI/FastCGI | FCGI/FastCGI |
| PHP-FPM | PHP-FPM |
| suPHP | -- (CGI |
| / suExec |
| habilitado) | |
| LSAPI | -- ( |
| a menos que esté instalado LiteSpeed Web Server |
| ) |
In broad terms, how does each PHP handler work and what are the pros and cons of working with each of them?
En términos generales, ¿cómo funciona cada controlador PHP y cuáles son las ventajas y desventajas de trabajar con cada uno de ellos?
Cada módulo proporciona un método diferente para analizar Each module provides a different method of parsing PHP.
DSO/Apache Module
This is also referred to as Esto también se conoce como mod_php. This module allows Apache itself to directly parse and display PHP files. PHP scripts parsed by mod_php run as the same user that Apache itself does (rather than the user account that hosts the PHP files.
Pros
- One of the fastest handlers available.
- Works with mod_ruid2 or mpm_itk modules.
Cons
- Only works with a single version of PHP on cPanel servers (you'll need to use other handers for other versions of PHP if you offer them).
- Scripts run as the Apache user rather than the owner of the domain or subdomain. For example, on a cPanel server, if the script creates a file or directory, that file will be owned by the user "nobody" which can cause problems when the account owner goes to backup or remove them.
CGI
Stands for Common Gateway Interface. Using this handler, the system will run PHP scripts as the user that owns the domain or subdomain.
Pros
- Scripts run as the domain or subdomain user, not as the Apache user.
Cons
Este módulo le permite a Apache analizar y mostrar directamente archivos PHP. Los scripts PHP analizados por mod_php se ejecutan como el mismo usuario que hace el propio Apache (en lugar de la cuenta de usuario que aloja los archivos PHP.
Pros
- Uno de los controladores más rápidos disponibles.
- Funciona con módulos mod_ruid2 o mpm_itk.
Cons
- Solo funciona con una única versión de PHP en servidores cPanel (necesitará usar otros controladores para otras versiones de PHP si los ofrece).
- Las secuencias de comandos se ejecutan como el usuario de Apache en lugar del propietario del dominio o subdominio. Por ejemplo, en un servidor cPanel, si el script crea un archivo o directorio, ese archivo será propiedad del usuario "nobody", lo que puede causar problemas cuando el propietario de la cuenta va a hacer una copia de seguridad o eliminarlos.
CGI
Significa Common Gateway Interface. Con este controlador, el sistema ejecutará scripts PHP como el usuario propietario del dominio o subdominio.
Pros
- Las secuencias de comandos se ejecutan como usuario de dominio o subdominio, no como usuario de Apache.
Cons
- Uno de los controladores más lentos.
- No funciona bien con el almacenamiento en caché de código de operación PHP
- One of the slowest handers.
- Doesn't work well with PHP opcode caching.
- Cannot put PHP configuration changes in an .htaccess file.
FCGI/FastCGI
FastCGI is a variation of the CGI protocol that provides a number of benefits over the older CGI handler. Using this module, the system will run PHP scripts as the user that owns the domain or subdomain. There are some differences between mod_fastcgi and mod_fcgid, but none that are relevant to the scope of this article.
...
- This handler uses more memory than most of the others.
- Cannot put PHP configuration changes in an .htaccess file.
PHP-FPM
FPM stands for FastCGI Process Manager. It is an improved way of implementing FastCGI processing of PHP. Using this handler, the system will run PHP scripts as the user that owns the domain or subdomain. Each FPM pool can have independent settings.
...
- This handler can use more memory than any other handler listed here, but that depends on the number of sites using PHP-FPM and the configuration of the FPM pool.
- Can be somewhat more complicated to manage.
- Cannot put PHP configuration changes in an .htaccess file and some directives can only be changed on a global level.
suPHP
This handler was specifically designed to serve PHP scripts as the owner of the domain or subdomain that is executing the PHP script. On cPanel servers, it is also configured to disallow execution of files with unsafe permissions. cPanel their copy of suPHP with the latest security fixes.
...
- Slowest PHP handler in most cases.
- PHP Opcode caching has no performance improvement and only wastes memory.
- Cannot put PHP configuration changes in an .htaccess file.
LSAPI
This handler implements the LiteSpeed Web Server (LSWS) SAPI. This handler requires CloudLiunx or LSWS for the maximum benefits. Using this handler, the system will run PHP scripts as the user that owns the domain or subdomain.
...
- You don't get full benefits without purchasing a third-party commercial product.
- Not compatible with mod_ruid2 or mpm_itk (but it shouldn't need them).
Which PHP hander should I use?
What you should use depends on your server's resources and the types of PHP sites you need to serve. On cPanel, we recommend defaulting to suPHP, LSAPI or FCGI. On Plesk we recommend FastCGI. Once you understand how PHP-FPM works, you may want to try enabling it for at least some sites and see if it helps at all.
How do I change the PHP handler that Apache uses?
| Warning |
|---|
Do not change the PHP handler you are using without fully understanding what the handler will do. If you switch from a handler that does run scripts as the user to one that doesn't, or vice versa, you may need to adjust the permissions of some files or directories so that Apache can access things properly. |
...