php 尝试访问本地 LAMP 服务器上的 localhost 时出现 404 Not Found 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4060034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:50:37  来源:igfitidea点击:

404 Not Found Error when trying to access localhost on local LAMP server

phpapacheubuntuhttp-status-code-404lamp

提问by slandau

I'm running Ubuntu. My Apache2 default file looks like this:

我正在运行 Ubuntu。我的 Apache2 默认文件如下所示:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

I have this file called Index.php in /var/www/

我在 /var/www/ 中有这个名为 Index.php 的文件

<?
phpinfo();
?>

When I access http://localhost/in my browser, I'm getting the 404 Not Found error:

当我在浏览器中访问http://localhost/时,出现 404 Not Found 错误:

The requested URL / was not found on this server. Apache/2.2.16 (Ubuntu) Server at localhost Port 80

在此服务器上找不到请求的 URL /。本地主机端口 80 上的 Apache/2.2.16 (Ubuntu) 服务器

What am I doing wrong? This actually worked when I first setup LAMP but it's not working now.

我究竟做错了什么?这在我第一次设置 LAMP 时确实有效,但现在不起作用。

回答by Andreas Jansson

Have a look in /etc/apache2/sites-enabled. It seems like my upgrade to 10.10 has wiped the symlinks from that directory. Try symlinking default to /etc/apache2/sites-available/default

查看 /etc/apache2/sites-enabled。似乎我升级到 10.10 已经从该目录中擦除了符号链接。尝试符号链接默认为 /etc/apache2/sites-available/default

sudo ln -s /etc/apache2/sites-available/default /etc/apache2/sites-enabled/default

回答by Mashpy Rahman

Check out error log (tail /var/log/apache2/error.log) in order to find out exact path that Apache tries to find.

查看错误日志 (tail /var/log/apache2/error.log) 以找出 Apache 尝试查找的确切路径。

回答by Usman

Use the url localhost/info.php. File info.php must contain <?php phpinfo(); ?>

使用 url localhost/info.php。文件 info.php 必须包含 <?php phpinfo(); ?>

回答by hatkirby

Do you have the PHP module installed and enabled? Because, normally, it would mention that in the server signature, but yours doesn't. That would also explain why the server doesn't recognize that index.phpis what you mean by /.

您是否安装并启用了 PHP 模块?因为,通常情况下,它会在服务器签名中提到这一点,而你的却没有。这也可以解释为什么服务器无法识别index.php出您的意思/

Try

尝试

sudo a2enmod php5

回答by RaviRokkam

Exactly the same problem with me.

和我完全一样的问题。

Following worked for me :

以下为我工作:

As Andreas Janssonmentioned, symlink default to:

正如Andreas Jansson提到的,符号链接默认为:

sudo ln -s /etc/apache2/sites-available/default /etc/apache2/sites-enabled/default

and restarted apache2:

并重新启动 apache2:

sudo /etc/init.d/apache2 restart

and then it works:

然后它的工作原理:

http://localhost/