You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Apache no 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.

¿Qué controladores admiten cPanel y Plesk con Apache?

cPanelPlesk
DSO/mod_phpApache Module/mod_php
CGICGI
FCGI/FastCGIFCGI/FastCGI
PHP-FPMPHP-FPM
suPHP-- (CGI / suExec habilitado)
LSAPI-- (a menos que esté instalado LiteSpeed Web Server)

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 PHP.

DSO/Apache Module

Esto también se conoce como mod_php. 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.

Contras

  • 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.

Contras

  • Uno de los controladores más lentos.
  • No funciona bien con el almacenamiento en caché de código de operación PHP.
  • No se pueden poner cambios de configuración de PHP en un archivo .htaccess.

FCGI/FastCGI

FastCGI es una variación del protocolo CGI que proporciona una serie de beneficios sobre el controlador CGI anterior. Con este módulo, el sistema ejecutará scripts PHP como el usuario propietario del dominio o subdominio. Hay algunas diferencias entre mod_fastcgi y mod_fcgid, pero ninguna que sea relevante para el alcance de este artículo.

Pros

  • Las secuencias de comandos se ejecutan como usuario de dominio o subdominio, no como usuario de Apache.
  • Un manejador muy rápido
  • Trabaja con PHP opcode caching.

Contras

  • Este controlador utiliza más memoria que la mayoría de los demás.
  • No se pueden poner cambios de configuración de PHP en un archivo .htaccess.

PHP-FPM

FPM significa FastCGI Process Manager. Es una forma mejorada de implementar el procesamiento FastCGI de PHP. Con este controlador, el sistema ejecutará scripts PHP como el usuario propietario del dominio o subdominio. Cada grupo de FPM puede tener configuraciones independientes.

Pros

  • Scripts run as the domain or subdomain user, not as the Apache user.
  • One of the fastest PHP handlers.
  • Works with PHP opcode caching.
  • Allows for some additional level of flexibility per pool.

Contras

  • 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.

Pros

  • Scripts run as the domain or subdomain user, not as the Apache user.
  • cPanel configures suPHP so that it blocks accessing or executing any files or directories with permissions higher than 755 for security.

Cons

  • 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.

Pros

  • Designed to perform as well or better than PHP-FPM under certain circumstance.
  • Less memory use than most other handlers.
  • Scripts run as the domain or subdomain user, not as the Apache user.
  • No special configuration required.
  • Can read PHP values out of a .htaccess file.

Cons

  • 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?

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.


On cPanel, you can adjust the PHP handler in WHM by clicking on MultiPHP Manager and then select the PHP Handler tab and adjust the hander as needed.

The settings in this area of cPanel only apply if you haven't configured a site to use PHP-FPM on the main MultiPHP Manager screen.


On Plesk, navigate to Service Plans > Example plan > PHP Settings > run PHP as and select the handler you want to use.

If you have service with HostDime and you are unsure what to do about your PHP handlers, please contact us for assistance before trying to make any changes.

  • No labels