PHP内置Web服务器(CGI)上的Laravel 4代替Apache
我正在尝试在无法使用Apache或Nginx的服务上运行laravel4.
一切都很好,直到我想在项目中使用Routes为止.
我已经尝试在URL上使用/index.php/...
,但是无法完成这项工作.
有什么方法可以迫使laravel不要使用.htaccess文件,或者有什么方法可以使用原始PHP路由?
I am trying to run laravel4 on a service that cannot use Apache or nginx.
everything is good till I wanted to use Routes on my project.
I've tried using /index.php/...
on the URL but could not make this work.
is there any way to force laravel not to use .htaccess file or any ways to use raw PHP routing?
尝试在一个配置文件(可能在app/config/application.php或application/config/application.php)中设置"application.url"选项:
Try setting the "application.url" option in one of configuration files, probably in app/config/application.php or application/config/application.php:
将其设置为http://127.0.0.1:54007/index.php
.现在,当laravel创建网址时,它将以此为根,最终网址应类似于http://127.0.0.1:54007/index.php/account/signin
.
Set it to http://127.0.0.1:54007/index.php
. Now when laravel creates url it will use this as a root and the final urls should be like http://127.0.0.1:54007/index.php/account/signin
.
此外,您还需要修改PHP桌面设置,以便它使用固定端口.编辑settings.json文件,并将其设置如下:
Also you need to modify PHP Desktop settings so that it uses a fixed port. Edit settings.json file and set it like this:
"web_server": {
"listen_on": ["127.0.0.1", 54007],
在laravel的.htaccess文件中,我发现了这一点:
In laravel's .htaccess I've found this:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
因此,将"/index.php"添加到根URL应该很好,因为这是apache的mod_rewrite所做的.
So it should work fine to add "/index.php" to root url, because this is what apache's mod_rewrite does.
如果某些操作无效,请查看其他名为"url.php","uri.php"的文件.
If something doesn't work, take a look at some other files named "url.php", "uri.php".
让我们知道是否可行.
编辑.
您也可以尝试将根网址设置为"index.php",而不使用"http://".这样,就不需要设置固定的Web服务器端口.
EDIT.
You may also try setting root url to "index.php", without the "http://". This way it wouldn't be required to set a fixed web server port.
更新 PHP桌面中的Mongoose Web服务器中存在一个错误,该错误阻止了诸如"index.php/company/5"之类的URL正常工作.请参见第137期中的__fix_mongoose_env_variables()php函数对其进行修复:
UPDATE There was a bug in Mongoose web server in PHP Desktop, that prevented urls like "index.php/company/5" from working properly. See the __fix_mongoose_env_variables() php function in Issue 137 that fixes it: