如何让 PHP 在 Apache2 MPM Worker 上运行?

如何让 PHP 在 Apache2 MPM Worker 上运行?

我正在虚拟远程服务器上设置 apache 和 php。

我想使用 MPM Worker 而不是 prefork,因为我上个月在 prefork 的内存使用方面遇到了麻烦,而且我确实读到过 worker 的运行速度比 prefork 更快。

但我在运行 PHP 时遇到了麻烦。

我遵循了以下说明:http://www.garron.me/blog/ubuntu-lamp-apache2-mpm-worker-and-php-fpm.html但是当我打电话时http://www.mydomain.xy/test.php我收到此错误:

You don't have permission to access /php5-fcgi/test.php on this server.

我必须改变什么才能避免这个错误?

这是 apachectl -V 的输出:

Server version: Apache/2.2.22 (Ubuntu)
Server built:   Mar  8 2013 15:53:20
Server's Module Magic Number: 20051115:30
Server loaded:  APR 1.4.6, APR-Util 1.3.12
Compiled using: APR 1.4.6, APR-Util 1.3.12
Architecture:   64-bit
Server MPM:     Worker
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/worker"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

这是 apache2.conf:

ServerRoot "/etc/apache2"
LockFile ${APACHE_LOCK_DIR}/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 10

<IfModule mpm_worker_module>
    StartServers            3
    MinSpareThreads        25
    MaxSpareThreads       100 
    ThreadLimit            64
    ThreadsPerChild        20
    MaxClients            300
    MaxRequestsPerChild 20000
</IfModule>

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

AccessFileName .htaccess

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

DefaultType text/html
HostnameLookups Off

Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/httpd.conf
Include /etc/apache2/ports.conf
Include /etc/apache2/conf.d/
Include /etc/apache2/sites-enabled/

LogFormat "%h %l %u %t \"%r\" %>s %b" common
ErrorLog  /var/log/apache2/NoVHost_error.log
LogLevel  warn
CustomLog /var/log/apache2/NoVHost_access.log common

我将此文件添加到 /etc/apache2/conf.d/: /etc/apache2/conf.d/php.conf

<IfModule mod_fastcgi.c>
    AddHandler php5-fcgi .php
    Action php5-fcgi /php5-fcgi
    Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
</IfModule>

在启用站点中我有此文件的软链接:

#000-default.conf
<VirtualHost *:80>
    ServerName x.x.xx:80
    DocumentRoot /var/www/default
    ServerAdmin [email protected]
    <Directory />
        Options None
        AllowOverride None
        Order deny,allow
                Deny from all
        DirectoryIndex index.html
    </Directory>
    <Directory /var/www/default/>
        Order allow,deny
        allow from all
        DirectoryIndex index.html
    </Directory>
    ErrorLog /var/log/apache2/DefaultVHost_error.log
    LogLevel warn
    CustomLog /var/log/apache2/DefaultVHost_access.log common
</VirtualHost>

以及这个文件:

#899-www.mydomain.xy

<VirtualHost *:80>
    ServerName www.mydomain.xy:80
    ServerAlias mydomain.xy *.mydomain.xy
    DocumentRoot /var/www/www.mydomain.xy/www
    ScriptAlias /cgi-bin/ /var/www/www.mydomain.xy/cgi-bin/
    ServerAdmin [email protected]

    <Directory />
        Options None
        AllowOverride None
        Order deny,allow
        Deny from all
        DirectoryIndex index.html
    </Directory>

    <Directory /var/www/www.mydomain.xy/www/>
        Options -ExecCGI +FollowSymLinks -Includes -Indexes -MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        DirectoryIndex index.html
    </Directory>

    <Directory "/var/www/www.mydomain.xy/cgi-bin">
        AllowOverride None
        Options +ExecCGI +FollowSymLinks -Includes -Indexes -MultiViews
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/www_shapp_at_error.log
    LogLevel warn
    CustomLog /var/log/apache2/www_shapp_at_access.log common

</VirtualHost>

您需要更多信息吗?

我必须改变什么才能避免这个错误?

答案1

您可能需要配置目录以允许所有

类似这样的事情。在应用此功能之前,请仔细检查权限,因为这可能会打开过多的 cgi 文件夹。

<Directory "/php5-fcgi/">
        Options +Indexes FollowSymLinks +ExecCGI
        AllowOverride AuthConfig FileInfo
                Order allow,deny
        Allow from all
</Directory>

相关内容