Laravel 4 on PHP built-in web server (CGI) instead of Apache

你说的曾经没有我的故事 提交于 2019-12-23 18:45:57

问题


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?


回答1:


Try setting the "application.url" option in one of configuration files, probably in app/config/application.php or application/config/application.php:

https://github.com/laravel/laravel/blob/4cb904f44d24f856ec9c1040d2198ed8f009723b/application/config/application.php

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.

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],

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>

So it should work fine to add "/index.php" to root url, because this is what apache's mod_rewrite does.

If something doesn't work, take a look at some other files named "url.php", "uri.php".

Let us know if that works.

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.

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:

https://code.google.com/p/phpdesktop/issues/detail?id=137



来源:https://stackoverflow.com/questions/21517695/laravel-4-on-php-built-in-web-server-cgi-instead-of-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!