gpt4 book ai didi

php - Laravel 5.4 - 路线不工作

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:21 24 4
gpt4 key购买 nike

我已经设置了全新的 ubuntu mini 安装并安装了 apache2 和 PHP。 (也用最新的稳定版 ubuntu 试过)我还安装了一些模块,其中包括 laravel installation documentation 中列出的模块。 :

OpenSSL PHP Extension
PDO PHP Extension
Tokenizer PHP Extension
Mbstring PHP Extension
XML PHP Extension

我还安装了:

libapache2-mod-phpgitcurl、php-curl:

sudo apt-get install libapache2-mod-php
sudo apt-get install curl
sudo apt-get install php-curl
sudo apt-get install git

现在我从 Windows 的 apache 服务器复制了整个 laravel 项目。然后我执行了

chmod 775 -R *

chown www-data:www-data -R *

但是,路由不起作用。

例如http://192.168.2.100/selenium/public/start

应该显示我的起始页,但我得到:

Not Found: The requested URL /selenium/public/start was not found on this server.`

所以我研究并找到了this在 stackoverflow 上。

来自答案:

Try to navigate to your expected route prepend it with /index.php/, in
your case: http://localhost/laravel/index.php/users.
If it works (no 404) then you problem is with the Rewrite Module configuration of
Apache HTTP, you should follow the next steps.

所以我尝试按照建议调用我的页面:

http://192.168.2.100/selenium/public/index.php/start

成功了。所以Rewrite Module Configuration有问题。

他/她建议在 public/.htaccess 中的 RewriteEngine On 行下添加 RewriteBase/directory/

所以我将我的 public/.htaccess 更改为此并重新启动了 apache2:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

RewriteEngine On
RewriteBase /selenium/

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

但是,路由仍然无法正常工作。我还能尝试什么?

系统信息

Apache 版本:

Server version: Apache/2.4.7 (Ubuntu)
Server built: Jul 15 2016 15:32:47

PHP 版本:

PHP 7.0.16-4+deb.sury.org~trusty+1 (cli) (built: Mar  2 2017 13:50:00) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.16-4+deb.sury.org~trusty+1, Copyright (c) 1999-2017, by Zend Technologies

Linux 版本:

Linux linux 3.13.0-110-generic #157-Ubuntu SMP Mon Feb 20 11:55:25 UTC 2017 i686 i686 i686 GNU/Linux

最佳答案

很多时候,如果它是全新安装的 Ubuntu 并且您安装了 apache,rewrite 模块默认情况下未启用。在您的终端中运行以下命令

sudo a2enmod rewrite

sudo service apache2 restart

现在,由于启用了重写模块,将读取 laravel 项目公共(public)文件夹中的 .htaccess 并且路由将按预期工作。

我不必更改 laravel 中默认的 .htaccess 文件中的任何行。
希望这会有所帮助。

关于php - Laravel 5.4 - 路线不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42650086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com