Apache没有在Arch Linux中重定向到index.php

Apache没有在Arch Linux中重定向到index.php,php,wordpress,apache,.htaccess,archlinux,Php,Wordpress,Apache,.htaccess,Archlinux,我试图在本地主机上配置Wordpress项目,但当我在localhost上打开浏览器时,我只看到Wordpress项目根目录中的文件 如果我单击index.php或访问localhost/index.php,它将按预期执行php 我已经安装了apache2.4、php7.2和phpache7.2 我的项目位于/srv/http/mysite: /etc/httpd/conf/httpd.conf文件中的相关行: LoadModule rewrite_module modules/mod_rewr

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

如果我单击
index.php
或访问
localhost/index.php
,它将按预期执行php

我已经安装了
apache2.4
php7.2
phpache7.2

我的项目位于
/srv/http/mysite

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

LoadModule rewrite_module modules/mod_rewrite.so

# Virtual hosts
Include conf/extra/httpd-vhosts.conf
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
注意:由于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>
我的
/etc/hosts
文件:

LoadModule rewrite_module modules/mod_rewrite.so

# Virtual hosts
Include conf/extra/httpd-vhosts.conf
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
关于最后一个文件,我注意到如果我删除
站点,它会工作并重定向到
index.php
,但我不想更改此文件,因为它的工作方式与使用
ubuntu
的远程服务器上的工作方式相同

主要问题是为什么这不起作用,但我也很高兴知道
正在做什么,以及为什么它被忽略,即使
LoadModule rewrite\u module modules/mod\u rewrite。因此启用了


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

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

您的目录中有以下内容吗

DirectoryIndex index.php
所以


DirectoryIndex.php
允许超越所有
要求所有授权

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

您的目录中有以下内容吗

DirectoryIndex index.php
所以


DirectoryIndex.php
允许超越所有
要求所有授权

在httpd.conf中,您应该有类似于

<IfModule dir_module> 
    DirectoryIndex index.php index.htm index.html
</IfModule>
<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.php index.htm index.html
这将是你的全部退路

然后在httpd-vhosts.conf中,许多站点描述中的一个可能看起来像

<IfModule dir_module> 
    DirectoryIndex index.php index.htm index.html
</IfModule>
<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> 

服务器管理员admin@siteName.com
DocumentRoot“e:/Stack/Sites/siteName/web”
服务器名站点名
服务器别名siteNameUser
DirectoryIndex.php
选项索引跟随符号链接
允许超越所有
要求所有授权
ErrorLog“logs/siteName.error.log”
CustomLog“logs/siteName.access.log”通用
注意:如果在httpd.conf中包含了回退默认值,则httpd-vhosts.conf站点声明中的
DirectoryIndex.php
是不必要的

如果您不想使用默认端口80,则在两个文件中都有类似的内容:
Listen 8080

对于localhost,我使用:在httpd.conf中<代码>收听127.0.0.1:8080
并在httpd-vhosts.conf
收听8080

在主机文件中,您需要定义如下内容。。。 127.0.0.1 siteName siteName用户www.siteName.com

目前使用:Apache/2.4.33(Win64)PHP/7.2.4~MySql 5.7.22自制堆栈。 httpd-vhosts.conf示例部分适用于Drupal 8.x-对于WP,DocumentRoot和目录将有所不同

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


我更喜欢在httpd-vhosts.conf中定义所有站点,但您可以将它们放在httpd.conf中,在httpd.conf中您应该有如下内容

<IfModule dir_module> 
    DirectoryIndex index.php index.htm index.html
</IfModule>
<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.php index.htm index.html
这将是你的全部退路

然后在httpd-vhosts.conf中,许多站点描述中的一个可能看起来像

<IfModule dir_module> 
    DirectoryIndex index.php index.htm index.html
</IfModule>
<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> 

服务器管理员admin@siteName.com
DocumentRoot“e:/Stack/Sites/siteName/web”
服务器名站点名
服务器别名siteNameUser
DirectoryIndex.php
选项索引跟随符号链接
允许超越所有
要求所有授权
ErrorLog“logs/siteName.error.log”
CustomLog“logs/siteName.access.log”通用
注意:如果在httpd.conf中包含了回退默认值,则httpd-vhosts.conf站点声明中的
DirectoryIndex.php
是不必要的

如果您不想使用默认端口80,则在两个文件中都有类似的内容:
Listen 8080

对于localhost,我使用:在httpd.conf中<代码>收听127.0.0.1:8080
并在httpd-vhosts.conf
收听8080

在主机文件中,您需要定义如下内容。。。 127.0.0.1 siteName siteName用户www.siteName.com

目前使用:Apache/2.4.33(Win64)PHP/7.2.4~MySql 5.7.22自制堆栈。 httpd-vhosts.conf示例部分适用于Drupal 8.x-对于WP,DocumentRoot和目录将有所不同

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


我更喜欢在httpd-vhosts.conf中定义所有站点,但您可以将它们放在httpd.conf中,因为在Arch Linux上Apache的问题通常与您在其他发行版中看到的问题不同,所以我很难找到您提到的答案。所以,我认为保留这个问题对Arch Linux用户是有益的,但我不是stackoverflow规则方面的专家,如果您认为应该删除这个问题,我会同意您的决定。但是你提到的答案很可能不会被其他Arch用户发现。我很难找到你提到的答案,因为Arch Linux上Apache的问题通常与你在其他发行版中看到的不同。所以,我认为保留这个问题对Arch Linux用户是有益的,但是