代码之家  ›  专栏  ›  技术社区  ›  VinGarcia

Apache未重定向到索引。Arch Linux中的php

  •  0
  • VinGarcia  · 技术社区  · 7 年前

    我试图在本地主机上配置Wordpress项目,但当我在上打开浏览器时 localhost 我只看到wordpress项目根目录中的文件。

    如果我点击 index.php 或访问 localhost/index.php 它按预期执行PHP。

    我已安装 apache 2.4 , php 7.2 php-apache 7.2 .

    我的项目在 /srv/http/mysite :

    中的相关行 /etc/httpd/conf/httpd.conf 文件:

    LoadModule rewrite_module modules/mod_rewrite.so
    
    # Virtual hosts
    Include conf/extra/httpd-vhosts.conf
    

    注:自httpd起。conf非常大,我只显示了我知道相关的行。如果这还不够,我可以将整个文件上传到pastebin。

    文件 /etc/httpd/conf/extra/httpd-vhosts.conf :

    <VirtualHost *:80>
        ServerAdmin webmaster@test.localhost
        DocumentRoot "/srv/http/mysite/"
        ServerName test.localhost
        ServerAlias test.localhost
        ErrorLog "/var/log/httpd/test.localhost-error_log"
        CustomLog "/var/log/httpd/test.localhost-access_log" common
    
        <Directory "/srv/http/mysite/">
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    

    文件 /srv/http/mysite/.htaccess :

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    我的 /etc/hosts 文件:

    127.0.0.1   localhost
    127.0.1.1   mycomputer_name
    127.0.2.1   test.localhost
    ::1 localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    

    关于最后一个文件,我注意到如果我删除 <IfModule ...> </IfModule> 它工作并重定向到的站点 指数php ,但我不希望更改此文件,因为它在使用 ubuntu .

    主要的问题是为什么这不起作用,但我也很高兴知道 <IfModule mod_rewrite.c> 以及为什么它被忽视 LoadModule rewrite_module modules/mod_rewrite.so 已启用。

    我知道这不是一个容易的问题,但我在网上没有发现任何人有同样的问题。我将非常感谢您的帮助。

    2 回复  |  直到 7 年前
        1
  •  3
  •   KaffineAddict    7 年前

    需要设置Apache来识别索引文件(在本例中为index.php)

    您的目录中是否有以下内容

    DirectoryIndex index.php
    

    所以

    <Directory "/srv/http/mysite/">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
    
        2
  •  0
  •   Jim    7 年前

    在httpd中。conf您应该有类似于。。。

    <IfModule dir_module> 
        DirectoryIndex index.php index.htm index.html
    </IfModule>
    

    这将是你的全面退却。

    然后在您的httpd vhost中。conf许多站点描述中的一个可能看起来像。。。

    <VirtualHost *:8080>
        ServerAdmin admin@siteName.com
        DocumentRoot "e:/Stack/Sites/siteName/web"
        ServerName siteName
        ServerAlias siteNameUser
        <Directory "e:/Stack/Sites/SiteName/web">
            DirectoryIndex index.php
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog "logs/siteName.error.log"
        CustomLog "logs/siteName.access.log" common
    </VirtualHost> 
    

    注:该 DirectoryIndex index.php 在httpd vhost中。如果您在httpd中包含了回退默认值,那么conf-site声明是不必要的。形态

    如果您不想使用默认端口80,则在任一文件中都有如下内容: Listen 8080

    对于localhost,我使用:在httpd中。配置。。。 Listen 127.0.0.1:8080 和httpd vhost中。形态 听8080

    在主机文件中,您需要定义如下内容。。。 127.0.0.1网站名网站名用户www.siteName。通用域名格式

    目前使用:Apache/2.4.33(Win64)PHP/7.2.4 ~ MySql 5.7.22自制堆栈。 httpd虚拟主机。conf示例部分是针对Drupal 8的。对于WP,您的文档根目录和目录将不同。

    您可以监听多个端口,例如8080用于dev、8081用于test、8082用于prod。此外,您还可以在httpd vhost中有许多不同的站点定义。conf文件。

    我更喜欢在httpd vhost中定义所有站点。conf,但您可以将它们放在httpd中。形态