【问题标题】:How to config apache for php 8 in Centos 7?如何在 Centos 7 中为 php 8 配置 apache?
【发布时间】:2022-01-16 22:29:32
【问题描述】:

我正在尝试在以下文件中为 Centos 7 中的 apache 设置正确的配置:

/etc/httpd/conf/httpd.conf

我的应用程序是 Laravel,它适用于 php 8。

我还需要一个子域来用于第二个应用程序,即 laravel。

这些是我的服务器块:


<VirtualHost IP:80>
    SuexecUserGroup "#1000" "#1000"
    DocumentRoot /home/example/public
    ServerName example.com
    <Directory /home/example/public>
        Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
     allow from all
     AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
        Require all granted
     AddType application/x-httpd-php .php
     AddHandler fcgid-script .php
     AddHandler fcgid-script .php5
     AddHandler fcgid-script .php7.2
     AddHandler fcgid-script .php8.0
    FCGIWrapper /home/example/php8.0.fcgi .php
        FCGIWrapper /home/example/fcgi-bin/php5.fcgi .php5
        FCGIWrapper /home/example/fcgi-bin/php7.2.fcgi .php7.2
    FCGIWrapper /home/example/fcgi-bin/php8.0.fcgi .php8.0
    </Directory>
    ErrorLog /var/log/virtualmin/example.com_error_log
    CustomLog /var/log/virtualmin/example.com_access_log combined
    ScriptAlias /cgi-bin/ /home/example/cgi-bin/
    ScriptAlias /awstats/ /home/example/cgi-bin/
    DirectoryIndex index.php index.php4 index.php5 index.htm index.html

    <Directory /home/example/cgi-bin>
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
    </Directory>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} =webmail.example.com
    RewriteRule ^(?!/.well-known)(.*) https://example.com:20000/ [R]
    RewriteCond %{HTTP_HOST} =admin.example.com
    RewriteRule ^(?!/.well-known)(.*) https://subdomain.example.com:10000/ [R]
    RemoveHandler .php
    RemoveHandler .php5
            RemoveHandler .php7.2
    RemoveHandler .php8.0
    FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "example.com statistics"
AuthType Basic
AuthUserFile /home/example/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch ^/(?!.well-known)(.*)$ http://example.com/$1
<FilesMatch \.php$>
    SetHandler proxy:fcgi://localhost:8001
</FilesMatch>
</VirtualHost>


<VirtualHost IP:80>
    SuexecUserGroup "#1000" "#1000"
    DocumentRoot /home/subdomain.example/public
    ServerName subdomain.example.com
    <Directory /home/subdomain.example/public>
        Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
     allow from all
     AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
        Require all granted
     AddType application/x-httpd-php .php
     AddHandler fcgid-script .php
     AddHandler fcgid-script .php5
     AddHandler fcgid-script .php7.2
     AddHandler fcgid-script .php8.0
    FCGIWrapper /home/example/php8.0.fcgi .php
        FCGIWrapper /home/example/fcgi-bin/php5.fcgi .php5
        FCGIWrapper /home/example/fcgi-bin/php7.2.fcgi .php7.2
    FCGIWrapper /home/example/fcgi-bin/php8.0.fcgi .php8.0
    </Directory>
    ErrorLog /var/log/virtualmin/example.com_error_log
    CustomLog /var/log/virtualmin/example.com_access_log combined
    ScriptAlias /cgi-bin/ /home/example/cgi-bin/
    ScriptAlias /awstats/ /home/example/cgi-bin/
    DirectoryIndex index.php index.php4 index.php5 index.htm index.html

    <Directory /home/subdomain.example/cgi-bin>
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    Require all granted
    </Directory>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} =webmail.subdomain.example.com
    RewriteRule ^(?!/.well-known)(.*) https://subdomain.example.com:20000/ [R]
    RewriteCond %{HTTP_HOST} =admin.subdomain.example.com
    RewriteRule ^(?!/.well-known)(.*) https://subdomain.example.com:10000/ [R]
    RemoveHandler .php
    RemoveHandler .php5
            RemoveHandler .php7.2
    RemoveHandler .php8.0
    FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "example.com statistics"
AuthType Basic
AuthUserFile /home/example/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch ^/(?!.well-known)(.*)$ http://subdomain.example.com/$1
<FilesMatch \.php$>
    SetHandler proxy:fcgi://localhost:8001
</FilesMatch>
</VirtualHost>

更改此文件后,我重新启动了 apache 服务器。

我还在 dns manager 中设置了子域。

任何人都可以在这个问题上帮助我。加上没有子域它可以正常工作,但子域不能。

【问题讨论】:

    标签: php apache centos devops centos7


    【解决方案1】:

    将此块添加到所有&lt;VirtualHost&gt; 块中:

    AddHandler php-fcgi .php
    Action php-fcgi /php-cgi
    Alias /php-cgi "/usr/bin/php-cgi -f"
    

    【讨论】:

      猜你喜欢
      • 2016-01-04
      • 2021-12-23
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      • 2021-01-23
      • 2017-05-19
      • 2014-12-02
      相关资源
      最近更新 更多