How can I tell Apache2, run mod_php5 by default but run this VH in CGI mode?

前端 未结 2 1070
孤城傲影
孤城傲影 2021-01-19 15:33

The Server

I have a development server that I\'m using to host my current projects. Here are some stats:

root@myserver:/usr/bin $ ca         


        
相关标签:
2条回答
  • 2021-01-19 15:58

    The problem is that mod_php still handles .php files, even when the CGI handler is set for a vhost.

    To fix that, the <Directory> in the vhost needs to have a SetHandler directive:

      Action php-cgi /cgi-bin-php/php-cgi-5.2.11
      <FilesMatch \.php$>
        SetHandler php-cgi
      </FilesMatch>
    </Directory>
    

    I've updated the tutorial.

    0 讨论(0)
  • 2021-01-19 16:10

    A good alternative is suPHP.

    If set up properly, you can have as many handlers, as you wish; even for different directories within a virtual host.

    For added security, there's suPHP's "paranoid" mode in which you assign a Unix user and group to a virtual host and the scripts will be run as that user.

    My suPHP config looks like that:

    ...
    
    [handlers]
    ;Handler for php-scripts
    x-httpd-php=php:/usr/bin/php4-cgi
    x-httpd-php5=php:/usr/bin/php5-cgi
    
    ;Handler for CGI-scripts
    x-suphp-cgi=execute:!self
    
    ...
    

    Within a simple .htaccess file it is possible to have scripts run using different versions of PHP:

    <FilesMatch \.php$>
       SetHandler x-httpd-php
    </FilesMatch>
    
    <FilesMatch \.php5$>
       SetHandler x-httpd-php5
    </FilesMatch>
    
    # etc...
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题