只有在我的 EC2 实例服务器上适用于 Laravel 4 的 AWS 的主路由

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

Only the home route working on my EC2 instance server for AWS for Laravel 4

amazon-web-serviceslaravelamazon-ec2laravel-4

提问by user1072337

I am trying to set up my laravel project on my EC2 Instance for AWS. I have successfully uploaded the files to the server using SFTP, and I rewrote the 000-default.conf file to point to the public folder of the project.

我正在尝试在我的 EC2 实例上为 AWS 设置我的 Laravel 项目。我已经成功地使用SFTP将文件上传到服务器,并重新编写了000-default.conf文件以指向项目的公共文件夹。

The home route is loading fine, but none of the other routes are working? Any idea what is going on here? They all work fine on local host (MAMP) and on other servers.

回家路线加载正常,但其他路线都没有工作?知道这里发生了什么吗?它们在本地主机 (MAMP) 和其他服务器上都可以正常工作。

All of the other routes show a NOT FOUND page (The requested URL /fans was not found on this server (for instance) )

所有其他路由都显示未找到页面(在此服务器上找不到请求的 URL /fans(例如))

回答by Y M

This worked for me:

这对我有用:

First in 000-default.conf

首先在 000-default.conf

Make Document Root point to your public folder:

使 Document Root 指向您的公用文件夹:

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html/your/laravel-project-folder/public/

Then add this to end of the 000-default.conf:

然后将其添加到 000-default.conf 的末尾:

<Directory "/var/www/html/your/laravel-project-folder/">
    AllowOverride All
</Directory>

Last two steps:

最后两步:

run this as root user:

以 root 用户身份运行:

1. sudo a2enmod rewrite
2. service apache2 restart

Now everything was working fine for me.

现在一切对我来说都很好。

Hope this helps :)

希望这可以帮助 :)

回答by user1072337

For people who have this issue in the future:

对于将来遇到此问题的人:

All I had to do was add:

我所要做的就是添加:

<Directory /var/www>
AllowOverride All
</Directory>

to my 000-default.conffile in /etc/apache2/sites-availabledirectory.

到我000-default.conf/etc/apache2/sites-available目录中的文件。

Place it right under the DocumentRoot line.

将它放在 DocumentRoot 行的正下方。

Cheers.

干杯。

回答by Ramsey Jiang

I met the same problem when I use Laravel5.2 on AWS. Can you see the welcome page after you deploy laravel on AWS? You can use the following to access the welcome page. /public/index.php

我在 AWS 上使用 Laravel5.2 时遇到了同样的问题。在 AWS 上部署 laravel 后能看到欢迎页面吗?您可以使用以下内容访问欢迎页面。/public/index.php

If you can do above, then you modify your route.php in the app/Http/ folder, like this:

如果你能做到以上,那么你在 app/Http/ 文件夹中修改你的 route.php,像这样:

Route::get('/convert/{name}', function ($name) {
     return str_plural($name);
});

After that you can try "/public/index.php/convert/123". Then you will see "123s" on the screen.

之后你可以尝试“/public/index.php/convert/123”。然后你会在屏幕上看到“123s”。

It is really tricky to visit your route with /public/index.php/, it waste long time for me to fix this problem.

用/public/index.php/访问你的路由真的很棘手,我浪费了很长时间来解决这个问题。