php 安装 Laravel 后 XAMPP localhost 返回未找到的对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17129612/
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 12:19:25  来源:igfitidea点击:

XAMPP localhost returns object not found after installing Laravel

phplaravelxampplaravel-4

提问by kaizenCoder

After much faffing about I got laravel to work with XAMPP. However, I can't seem to access directories in the htdocs folder via localhost now. Attempt to access a file returns Object not found!along with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

经过一番折腾之后,我让 laravel 与 XAMPP 一起工作。但是,我现在似乎无法通过 localhost 访问 htdocs 文件夹中的目录。试图访问一个文件返回Object not found!沿The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

The changes I made to get laravel working seems like a blur now. The only thing I remember doing is editing the hostsfile to enable the virtual host to work by adding 127.0.0.1 laravel.devin the hosts file (using a mac btw). I also added a virtual host to the httpd-vhost.conf file.

我为让 laravel 正常工作所做的更改现在看起来很模糊。我记得做的唯一一件事是编辑hosts文件以通过添加127.0.0.1 laravel.dev主机文件(使用 mac btw)使虚拟主机能够工作。我还在 httpd-vhost.conf 文件中添加了一个虚拟主机。

I did undo the above changes but it didn't make a difference.

我确实撤消了上述更改,但没有任何区别。

Any thoughts on whats gone wrong?

关于出了什么问题的任何想法?

Thanks.

谢谢。

Dispelling ConfusionJust thought I'd clarify what my experience is. Before installing laravel 4I could access all my projects with localhost/someProjectNamebut now it fails.

消除混乱只是想我会澄清我的经验是什么。在安装laravel 4之前,我可以访问我所有的项目,localhost/someProjectName但现在它失败了。

I'm trying to identify what change caused this behaviour. Btw, I have no problems accessing my laravel project (my mapping allows me access to it via laravel.dev)

我试图确定是什么变化导致了这种行为。顺便说一句,我访问我的 laravel 项目没有问题(我的映射允许我通过 访问它laravel.dev

回答by jon_athan_hall

Look into your /etc/httpd.conffile and see if you have Virtual hosts activated.

查看您的/etc/httpd.conf文件,看看您是否激活了虚拟主机。

If so, check your etc/extra/httpd-vhosts.conffile. You might have set up a VirtualHost already.

如果是这样,请检查您的etc/extra/httpd-vhosts.conf文件。您可能已经设置了 VirtualHost。

EDIT: I have found that once you turn on Virtual Hosts, XAMPP needs a default VirtualHost for your basic htdocs files

编辑:我发现一旦你打开虚拟主机,XAMPP 需要一个默认的 VirtualHost 作为你的基本 htdocs 文件

Try adding a default VirtualHost (at the bottom of the file) like so:

尝试添加一个默认的 VirtualHost(在文件底部),如下所示:

<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/htdocs"
<Directory "/Applications/XAMPP/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>

回答by luisfego

It sounds to me like it is a problem with the way your directories are configured. Be sure to create a Virtual Host (if you're using Apache) that points to the publicfolder within your application directory.

在我看来,这是您的目录配置方式的问题。请务必创建一个指向应用程序目录中公共文件夹的虚拟主机(如果您使用的是 Apache)。

For example, if your Laravel project is under /Applications/XAMPP/htdocs/Laravel then set up a Virtual Host like this:

例如,如果您的 Laravel 项目位于 /Applications/XAMPP/htdocs/Laravel 下,则设置一个虚拟主机,如下所示:

<VirtualHost *:80>
    DocumentRoot /Applications/XAMPP/htdocs/Laravel/public

    # Other directives here
</VirtualHost>

Additionaly, if you're working with PHP >= 5.4, SSH into the application folder and run

另外,如果您使用 PHP >= 5.4,请通过 SSH 进入应用程序文件夹并运行

./artisan serve

(Be sure that your PHP executable is in your PATH variable). Then go localhost:8000 and you should have your application running. Running this command runs the PHP built-in webserver and saves you the trouble of configuring virtual hosts.

(确保您的 PHP 可执行文件在您的 PATH 变量中)。然后转到 localhost:8000,您应该可以运行您的应用程序。运行此命令会运行 PHP 内置的 webserver,省去了配置虚拟主机的麻烦。

回答by William Lawn Stewart

In your Apache's http.conf, find the DocumentRootline and add the subdirectory /publicon the end.

在 Apache 的 http.conf 中,找到该DocumentRoot行并/public在末尾添加子目录。

Once that is done and you've restarted Apache, you'll be able to access everything which is contained within your htdocs/publicfolder (including subdirectories of that folder), along with any routes you've defined in Laravel.

完成并重新启动 Apache 后,您将能够访问htdocs/public文件夹中包含的所有内容(包括该文件夹的子目录),以及您在 Laravel 中定义的任何路由。

Laravel is designed to be set up this way as to protect the code and files by not having them in the folder which is served out to the web.

Laravel 旨在以这种方式进行设置,以通过不将它们放在提供给网络的文件夹中来保护代码和文件。

回答by Neo Ighodaro

I don't know if you're running L4 or L3. However, launch CLI and

不知道你是跑L4还是L3。但是,启动 CLI 和

$ cd ./path/to/project

$ cd ./path/to/project

Then for L4:

然后对于 L4:

$ php artisan serve

For L3:

对于 L3:

$ php -S localhost:8000 -t public

Now you can go to localhost:8000and see your application.

现在您可以前往localhost:8000查看您的应用程序。

回答by user3148161

You're having problem because the object really doesn't exist in your htdocsdirectory. You don't have to append xamppafter localhostor 127.0.0.1because xamppwill treat it as an object or a folder under htdocs.

您遇到了问题,因为该对象确实不存在于您的htdocs目录中。您不必xampp在之后追加localhost127.0.0.1因为xampp将其视为htdocs.

if you want to access your blog, make sure you have a blog folder under htdocsand put in your URL localhost/blog

如果你想访问你的博客,请确保你有一个博客文件夹htdocs并输入你的 URLlocalhost/blog

回答by Nadeem0035

I have same issue and found that there are miss configuration in vhost. So that's are correct configuration.

我有同样的问题,发现 vhost 中存在未命中配置。所以这是正确的配置。

in etc/extra/httpd-vhosts.conf

etc/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "D:/xampp/htdocs/laravel-master/public"
    ServerName laravel.local
    ErrorLog "logs/laravel-master-error.log"
     <Directory D:/xampp/htdocs/laravel-master/public>  
        AllowOverride All
        Order Allow,Deny
        Allow From All
    </Directory>
</VirtualHost>

In the hosts file

在主机文件中

127.0.0.1 laravel.local