在 Apache 上使用虚拟主机的多个 PHP 版本


Multiple PHP versions with virtual hosts on Apache

我尝试在我的Windows服务器上使用apache和fcgi使用不同的PHP版本,但它不起作用...

以下是我的httpd.conf的摘录:

<IfModule php5_module>
PHPIniDir C:/Wamp/bin/php/php5.5.12
</IfModule>
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
    FcgidInitialEnv PATH "C:/Wamp/bin/php/php5.5.31-nts;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/Wamp/tmp"
FcgidInitialEnv TMP "C:/Wamp/tmp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 1000 
FcgidMaxProcesses 3
FcgidMaxRequestLen 8131072
#FcgidConfig -idle-timeout 110 -killInterval 120 -pass-header HTTP_AUTHORIZATION -autoUpdate
# Location php.ini:
FcgidInitialEnv PHPRC "C:/Wamp/bin/php/php5.5.31-nts"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
<Files ~ "'.php$">
    Options Indexes FollowSymLinks ExecCGI 
    AddHandler fcgid-script .php
    FcgidWrapper "C:/Wamp/bin/php/php5.5.31-nts/php-cgi.exe" .php
</Files>
</IfModule>
Listen 54
<VirtualHost *:54>
DocumentRoot "C:/WWWROOT/"
#SetEnv PHPRC "C:/Wamp/bin/php/php5.4.45-nts"
#ScriptAlias /php5445/ "C:/Wamp/bin/php/php5.4.45-nts"
#Action     php5445-script /php5445/php-cgi.exe
#AddHandler php5445-script .php

FcgidInitialEnv PHPRC "C:/Wamp/bin/php/php5.4.45-nts"
AddHandler fcgid-script .php
FcgidWrapper "C:/Wamp/bin/php/php5.4.45-nts" .php 

#<Directory "C:/Wamp/bin/php/php5.4.45-nts">
#    Options Indexes FollowSymLinks Includes ExecCGI
#    AllowOverride All
#    Require all granted
#    Order Allow,Deny
#    Allow from all
#</Directory>
<Directory "C:/WWWROOT/">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
    Order Allow,Deny
    Allow from all
</Directory>
</VirtualHost>
Listen 52
<VirtualHost *:52>
DocumentRoot "C:/WWWROOT/"
#SetEnv PHPRC "C:/Wamp/bin/php/php5.2.17-nts"
#ScriptAlias /php5217/ "C:/Wamp/bin/php/php5.2.17-nts"
#Action     php5217-script /php5217/php-cgi.exe
#AddHandler php5217-script .php

FcgidInitialEnv PHPRC "C:/Wamp/bin/php/php5.4.45-nts"
AddHandler fcgid-script .php
FcgidWrapper "C:/Wamp/bin/php/php5.4.45-nts" .php 
#<Directory "C:/Wamp/bin/php/php5.2.17-nts">
#    Options Indexes FollowSymLinks Includes ExecCGI
#    AllowOverride All
#    Require all granted
#    Order Allow,Deny
#    Allow from all
#</Directory>
<Directory "C:/WWWROOT/">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
    Order Allow,Deny
    Allow from all
</Directory>

你觉得有什么问题吗?

如果我去本地主机:52?phpInfo我可以看到_SERVER["PHPRC"] C:/Wamp/bin/php/php5.2.17-nts但主标题是"PHP 版本 5.5.31"如果我尝试在端口 52 上使用 mysql_connect(),这在 PHP 5.2 上没有被弃用,我会收到不推荐使用的错误消息......

我正在使用万普服务器...我花了一天时间寻找解决方案...所以如果你有任何想法...

简单的配置:

在端口 80 上托管 1 PHP 5.3:

<VirtualHost 0.0.0.0:80>
    ServerAdmin "brko28@hotmail.com"
    DocumentRoot "/www/www"
    ServerName "localhost"
    ServerAlias "localhost"
    ScriptAlias /cgi-bin/ "/www/www/cgi-bin/"
    Options Indexes FollowSymLinks
    DirectoryIndex index.php index.html index.htm index.cgi default.html default.htm index.pl index.shtml default.php default.pl default.cgi default.shtml home.php home.pl home.cgi home.shtml home.html home.htm
    IndexOptions FancyIndexing IconHeight=22 IconWidth=18 NameWidth=50 IgnoreCase FoldersFirst
    AddType text/html .php .php3 .php4 .php5 .phps .shtml
    DefaultType text/plain
    <IfModule fcgid_module>
        Options +ExecCGI
        FcgidInitialEnv PATH "'www'php'encoders_new;'www'imagemagick;'www'php'bash;'www'perl'bin;C:'WINDOWS'system32;C:'WINDOWS;C:'WINDOWS'System32'Wbem"
        FcgidInitialEnv MIBDIRS "'www'php'x64'nts'php5.3.29VC9'extras'mibs"
        FcgidInitialEnv PHP_PEAR_SYSCONF_DIR "'www'php'x64'nts'php5.3.29VC9"
        FcgidInitialEnv PHPRC "'www'php'x64'nts'php5.3.29VC9"
        AddHandler fcgid-script .php .php3 .php4 .php5 .phps .cgi .pl .fcgi
        #FcgidWrapper "/www/php/x64/nts/php5.3.29VC9/php-cgi.exe" .php
    </IfModule>
    #
    # The following lines prevent .htaccess and .htpasswd files from being 
    # viewed by Web clients. 
    #
    <FilesMatch "^'.ht">
        Require all denied
        Satisfy All
    </FilesMatch>
    <IfModule autoindex_module>
        IndexIgnore .htaccess
    </IfModule>
    <Directory "/www/www/cgi-bin">
        DefaultType text/html
        Options -Indexes +ExecCGI
        AllowOverride None
        Require all granted
        SetHandler cgi-script
    </Directory>
    <Location "/cgi-bin">
        SetHandler cgi-script
        Options +ExecCGI
    </Location>
    <Directory "/www/www">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        AddType text/html .php .php3 .php4 .php5 .phps .shtml
        DirectoryIndex index.php index.html index.htm index.cgi default.html default.htm index.pl index.shtml default.php default.pl default.cgi default.shtml home.php home.pl home.cgi home.shtml home.html home.htm
        <IfModule fcgid_module>
            Options +ExecCGI
            <Files ~ "'.(php|phtml)$">
                AddHandler fcgid-script .php .php3 .php4 .php5 .phps .cgi .pl .fcgi
                FcgidWrapper "/www/php/x64/nts/php5.3.29VC9/php-cgi.exe" .php
                #
                # Taken care of in mod_fcgid.conf with: FcgidPassHeader Authorization
                RewriteEngine On
                RewriteCond %{HTTP:Authorization} ^(.*)
                RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
            </Files>
        </IfModule>
        <IfModule php5_module>
            AddType application/x-httpd-php .phtml .pwml .php5 .php4 .php3 .php2 .php .inc
            AddHandler application/x-httpd-php .php
            AddHandler application/x-httpd-php-source .phps
            <IfModule php5_module>
                php_admin_flag apc.enabled Off
            </IfModule>
        </IfModule>
    </Directory>
    Include "conf/extra/php53/*.conf"
</VirtualHost>

端口 83 上的主机 2 PHP 5.5:

Listen 0.0.0.0:83
#
<VirtualHost 0.0.0.0:83>
    ServerAdmin "brko28@hotmail.com"
    DocumentRoot "/www/vhdoc"
    ServerName "localhost:83"
    ServerAlias "localhost:83"
    ScriptAlias /cgi-bin/ "/www/vhdoc/cgi-bin/"
    Options Indexes FollowSymLinks
    DirectoryIndex index.php index.html index.htm index.cgi default.html default.htm index.pl index.shtml default.php default.pl default.cgi default.shtml home.php home.pl home.cgi home.shtml home.html home.htm
    IndexOptions FancyIndexing IconHeight=22 IconWidth=18 NameWidth=50 IgnoreCase FoldersFirst
    AddType text/html .php .php3 .php4 .php5 .phps .shtml
    DefaultType text/plain
    <IfModule fcgid_module>
        Options +ExecCGI
        FcgidInitialEnv PATH "'www'php'encoders_new;'www'imagemagick;'www'php'bash;'www'perl'bin;C:'WINDOWS'system32;C:'WINDOWS;C:'WINDOWS'System32'Wbem"
        FcgidInitialEnv MIBDIRS "'www'php'x64'nts'php5.5.38VC11'extras'mibs"
        FcgidInitialEnv PHP_PEAR_SYSCONF_DIR "'www'php'x64'nts'php5.5.38VC11"
        FcgidInitialEnv PHPRC "'www'php'x64'nts'php5.5.38VC11"
        AddHandler fcgid-script .php .php3 .php4 .php5 .phps .cgi .pl .fcgi
        #FcgidWrapper "/www/php/x64/nts/php5.5.38VC11/php-cgi.exe" .php
    </IfModule>
    #
    # The following lines prevent .htaccess and .htpasswd files from being 
    # viewed by Web clients. 
    #
    <FilesMatch "^'.ht">
        Require all denied
        Satisfy All
    </FilesMatch>
    <IfModule autoindex_module>
        IndexIgnore .htaccess
    </IfModule>
    <Directory "/www/vhdoc/cgi-bin">
        DefaultType text/html
        Options -Indexes +ExecCGI
        AllowOverride None
        Require all granted
        SetHandler cgi-script
    </Directory>
    <Location "/cgi-bin">
        SetHandler cgi-script
        Options +ExecCGI
    </Location>
    <Directory "/www/vhdoc">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        AddType text/html .php .php3 .php4 .php5 .phps .shtml
        DirectoryIndex index.php index.html index.htm index.cgi default.html default.htm index.pl index.shtml default.php default.pl default.cgi default.shtml home.php home.pl home.cgi home.shtml home.html home.htm
        <IfModule fcgid_module>
            Options +ExecCGI
            <Files ~ "'.(php|phtml)$">
                AddHandler fcgid-script .php .php3 .php4 .php5 .phps .cgi .pl .fcgi
                FcgidWrapper "/www/php/x64/nts/php5.5.38VC11/php-cgi.exe" .php
                #
                # Taken care of in mod_fcgid.conf with: FcgidPassHeader Authorization
                RewriteEngine On
                RewriteCond %{HTTP:Authorization} ^(.*)
                RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
            </Files>
        </IfModule>
          <IfModule php5_module>
            AddType application/x-httpd-php .phtml .pwml .php5 .php4 .php3 .php2 .php .inc
            AddHandler application/x-httpd-php .php
            AddHandler application/x-httpd-php-source .phps
            <IfModule php5_module>
                php_admin_flag apc.enabled Off
            </IfModule>
        </IfModule>
    </Directory>
    Include "conf/extra/php55/*.conf"
</VirtualHost>

端口 82 上的主机 2 PHP 5.4:

Listen 0.0.0.0:82
#
<VirtualHost 0.0.0.0:82>
    ServerAdmin "brko28@hotmail.com"
    DocumentRoot "/www/vhdoc"
    ServerName "localhost:82"
    ServerAlias "localhost:82"
    ScriptAlias /cgi-bin/ "/www/vhdoc/cgi-bin/"
    Options Indexes FollowSymLinks
    DirectoryIndex index.php index.html index.htm index.cgi default.html default.htm index.pl index.shtml default.php default.pl default.cgi default.shtml home.php home.pl home.cgi home.shtml home.html home.htm
    IndexOptions FancyIndexing IconHeight=22 IconWidth=18 NameWidth=50 IgnoreCase FoldersFirst
    AddType text/html .php .php3 .php4 .php5 .phps .shtml
    DefaultType text/plain
    <IfModule fcgid_module>
        Options +ExecCGI
        FcgidInitialEnv PATH "'www'php'encoders_new;'www'imagemagick;'www'php'bash;'www'perl'bin;C:'WINDOWS'system32;C:'WINDOWS;C:'WINDOWS'System32'Wbem"
        FcgidInitialEnv MIBDIRS "'www'php'x64'nts'php5.4.45VC9'extras'mibs"
        FcgidInitialEnv PHP_PEAR_SYSCONF_DIR "'www'php'x64'nts'php5.4.45VC9"
        FcgidInitialEnv PHPRC "'www'php'x64'nts'php5.4.45VC9"
        AddHandler fcgid-script .php .php3 .php4 .php5 .phps .cgi .pl .fcgi
        #FcgidWrapper "/www/php/x64/nts/php5.4.45VC9/php-cgi.exe" .php
    </IfModule>
    #
    # The following lines prevent .htaccess and .htpasswd files from being 
    # viewed by Web clients. 
    #
    <FilesMatch "^'.ht">
        Require all denied
        Satisfy All
    </FilesMatch>
    <IfModule autoindex_module>
        IndexIgnore .htaccess
    </IfModule>
    <Directory "/www/vhdoc/cgi-bin">
        DefaultType text/html
        Options -Indexes +ExecCGI
        AllowOverride None
        Require all granted
        SetHandler cgi-script
    </Directory>
    <Location "/cgi-bin">
        SetHandler cgi-script
        Options +ExecCGI
    </Location>
    <Directory "/www/vhdoc">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        AddType text/html .php .php3 .php4 .php5 .phps .shtml
        DirectoryIndex index.php index.html index.htm index.cgi default.html default.htm index.pl index.shtml default.php default.pl default.cgi default.shtml home.php home.pl home.cgi home.shtml home.html home.htm
        <IfModule fcgid_module>
            Options +ExecCGI
            <Files ~ "'.(php|phtml)$">
                AddHandler fcgid-script .php .php3 .php4 .php5 .phps .cgi .pl .fcgi
                FcgidWrapper "/www/php/x64/nts/php5.4.45VC9/php-cgi.exe" .php
                #
                # Taken care of in mod_fcgid.conf with: FcgidPassHeader Authorization
                RewriteEngine On
                RewriteCond %{HTTP:Authorization} ^(.*)
                RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
            </Files>
        </IfModule>
          <IfModule php5_module>
            AddType application/x-httpd-php .phtml .pwml .php5 .php4 .php3 .php2 .php .inc
            AddHandler application/x-httpd-php .php
            AddHandler application/x-httpd-php-source .phps
            <IfModule php5_module>
                php_admin_flag apc.enabled Off
            </IfModule>
        </IfModule>
    </Directory>
    Include "conf/extra/php54/*.conf"
</VirtualHost>

最后,最重要的事情。所有 php 的设置mod_fcgid

LoadModule fcgid_module modules/mod_fcgid.so
#
<IfModule fcgid_module>
    FcgidInitialEnv PATH "/www/php/encoders_new;/www/php/mplayer;/www/imagemagick;/www/php/bash;F:/www/perl/perl/bin;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem"
    FcgidInitialEnv SystemRoot "C:/Windows"
    FcgidInitialEnv SystemDrive "C:"
    FcgidInitialEnv TEMP "/www/php/tmp"
    FcgidInitialEnv TMP "/www/php/tmp"
    FcgidInitialEnv windir "C:/WINDOWS"
    FcgidInitialEnv MIBDIRS "/www/php/x64/nts/php5.3.29VC9/extras/mibs"
    FcgidInitialEnv MYSQL_HOME "/www/MySQL5.1.68/bin"
    FcgidInitialEnv OPENSSL_CONF "/www/apache2.4.34x64-VC14/conf/openssl.cnf"
    FcgidInitialEnv MAGICK_HOME "/www/imagemagick"
    FcgidInitialEnv PERL "F:/www/perl/perl/bin"
    FcgidInitialEnv PERL5LIB "F:/www/perl/perl/site/lib;F:/www/perl/perl/lib"
    FcgidInitialEnv FFMPEG "/www/php/encoders_new"
    FcgidInitialEnv FFMPEG_DATADIR "/www/php/encoders_new/ffpresets"
    #
    FcgidInitialEnv PHP_FCGI_CHILDREN 0
    #
    # Set PHP_FCGI_MAX_REQUESTS to greater than or equal to FcgidMaxRequestsPerProcess  
    # to prevent php-cgi process from exiting before all requests completed
    FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000
    #
    # php.ini defaults to cgi.fix_pathinfo = 1
    # instructions say mirror php.ini value, but Joomla won't work
    # perhaps this applies the path fix again?
    # Set 1, if cgi.fix_pathinfo=1 in php.ini
    FcgidFixPathinfo 0
    #
    # The FastCGI application must begin generating the response within this period of time.
    # Number of seconds of idle time before a php-cgi process is terminated (Default: 40)
    FcgidIOTimeout 8200
    #
    # Application processes which have not handled a request for this period of time will be terminated,
    # if the number of processses for the class exceeds FcgidMinProcessesPerClass (3) (Default: 300) 240
    FcgidIdleTimeout 300
    #
    # FastCGI application will be killed after handling a request for FcgidBusyTimeout (Default: 300)
    FcgidBusyTimeout 300
    #
    # Scan interval for busy timeout process (Default: 120)
    FcgidBusyScanInterval 120
    #
    # Scan interval for exited process (Default: 3)
    FcgidErrorScanInterval 3
    #
    # Full path to FastCGI access checker (Default: none)
    #FcgidAccessChecker
    #
    # Set to 'off' to allow access control to be passed along to lower modules upon failure (On|Off, Default: On)
    #FcgidAccessCheckerAuthoritative On
    #
    # Full path to FastCGI authenticator (Default: none)
    #FcgidAuthenticator 
    #
    # Set to 'off' to allow authentication to be passed along to lower modules upon failure (On|Off, Default: On)
    #FcgidAuthenticatorAuthoritative On
    #
    # Full path to FastCGI authorizer (Default: none)
    #FcgidAuthorizer 
    #
    # Set to 'off' to allow authorization to be passed along to lower modules upon failure (On|Off, Default: On)
    #FcgidAuthorizerAuthoritative On
    #
    # Scan interval for idle timeout process (Default: 120)
    FcgidIdleScanInterval 120
    #
    # Maximum size of a request which will be held in memory (Default: 65536)
    FcgidMaxRequestInMem 65536
    #
    # Shared memory file path (Default: logs/fcgid_shm)
    #FcgidProcessTableFile "../logs/fcgid_shm"
    #
    # Directory for AF_UNIX sockets (Unix) or pipes (Windows) (Default: logs/fcgidsock)
    #FcgidIPCDir "../logs/fcgidsock"
    #
    # Each spawn adds this value to the process activity score (Default: 1)
    #FcgidSpawnScore 1
    #
    # Maximum value of the process activity score which allows a spawn to occur (Default: 10)
    # Limit on rate of spawning new application processes
    #FcgidSpawnScoreUpLimit 10
    #
    # Each terminated process adds this value to the process activity score (Default: 2)
    #FcgidTerminationScore 2
    #
    # Set processing options for a FastCGI command
    #FcgidCmdOptions
    #
    # Job Control orphan prevention for fcgi workers. (On|Off, Default: Off)
    FcgidWin32PreventOrphans Off
    #
    # Maximum period of time the module will wait while trying to connect to a FastCGI application on Windows (Default: 3).
    FcgidConnectTimeout 400
    #
    # Maximum number of FastCGI application processes which can be active at one time (Default: 1000).(32)
    # Global limit on number of processes
    FcgidMaxProcesses 1000
    #
    # Set to 1/2 FcgidMaxProcesses so one VirtualHost can't take up all processes. (Default: 100) 300
    # Limit on number of processes per application
    FcgidMaxProcessesPerClass 500
    #
    # Scan interval for zombie process (Default: 3)
    FcgidZombieScanInterval 20
    #
    # Maximum HTTP request length (Default: 131072) in Bytes
    FcgidMaxRequestLen 1000000000
    #
    # Amount subtracted from process activity score each second (Default: 1)
    FcgidTimeScore 3
    #
    # CGI output buffer size (Default: 65536) 64 100
    FcgidOutputBufferSize 65536
    #
    # Maximum FastCGI application process lifetime (Default: 3600)
    FcgidProcessLifeTime 8200
    #
    # Each FastCGI application process will be terminated after handling the specified number of requests.
    # A value of 0 disables the check.
    FcgidMaxRequestsPerProcess 1000
    #
    # Min process count of one class of FastCGI application (Default: 3) 0
    FcgidMinProcessesPerClass 0
    #
    # Needed for user authorization (login) to work (with phpmyadmin and all other scripts)
    # Header name which will be passed to FastCGI as environment variable
    FcgidPassHeader Authorization
    FcgidPassHeader Proxy-Authorization
    FcgidPassHeader HTTP_AUTHORIZATION
    #
    #FcgidPassHeader Range
    #FcgidPassHeader If-Range
    #FcgidPassHeader If-Unmodified-Since
    #FcgidPassHeader If-Modified-Since
    #FcgidPassHeader If-Match
    #FcgidPassHeader If-None-Match
     #
     # environment variables for the IIP server
     #
    Include "conf/extra/mod_fcgid.conf"
</IfModule>