php 无法让 Laravel 4 在本地主机上工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14345174/
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
Can't make Laravel 4 to work on localhost
提问by Carlo
I'm trying Laravel for the first time after reading an announcement of the Laravel4 beta releasing.
在阅读 Laravel4 beta 发布公告后,我第一次尝试 Laravel。
I followed these stepsI installed composer and laravel with all the dependencies it needed. I put the laravel inside my ~/public_htmldirectory - as I'm used to do it with Codeigniter, but I think something's wrong here.
我按照这些步骤安装了 composer 和 laravel 以及它需要的所有依赖项。我把 laravel 放在我的~/public_html目录中——因为我习惯用Codeigniter来做,但我认为这里有问题。
If I point to the browser to http://localhost/~carlo/laravel-develop/, it just displays the content of the directory.
如果我将浏览器指向http://localhost/~carlo/laravel-develop/,它只会显示目录的内容。
Then, while on the filesystem I had a laravel-develop/publicfolder, it didn't appear on the browser.
然后,虽然在文件系统上我有一个laravel-develop/public文件夹,但它没有出现在浏览器上。
I've found that changing the .htaccesslike this:
我发现改变.htaccess这样的:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
resulted in an error when I try to access the public folder. The error:
当我尝试访问公用文件夹时导致错误。错误:
ErrorException: Warning: file_put_contents(/home/carlo/public_html/laravel-develop/app/config/../storage/meta/services.json): failed to open stream: Permission denied in /home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
ErrorException:警告:file_put_contents(/home/carlo/public_html/laravel-develop/app/config/../storage/meta/services.json):无法打开流:权限被拒绝在 /home/carlo/public_html/laravel-开发/供应商/laravel/framework/src/Illuminate/Filesystem/Filesystem.php 第 77 行
another one:
另一个:
/home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
/home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php 第 77 行
then a long list of errors. The last one is:
然后是一长串错误。最后一个是:
require_once('/home/carlo/public_html/laravel-develop/start.php') in /home/carlo/public_html/laravel-develop/public/index.php line 53
require_once('/home/carlo/public_html/laravel-develop/start.php') 在 /home/carlo/public_html/laravel-develop/public/index.php 第 53 行
回答by adridev
回答by socketman
Your errors resulted because laravel couldn't write to the app/storage folder. The rest was just a stack trace. In order to make the storage folder writable, cd into your app folder and then run:
你的错误是因为 laravel 无法写入 app/storage 文件夹。其余的只是一个堆栈跟踪。为了使存储文件夹可写,请 cd 进入您的应用程序文件夹,然后运行:
chmod -R 777 storage
回答by pinepain
Production way, moderate complexity for people not familiar with Unix, but more secure:
生产方式,对于不熟悉Unix的人来说复杂度适中,但更安全:
- Go in super user mode (sudo -s or su).
- Create group
web(groupadd web) - Add you main user to group
web(suppose your user iscool_user, so runusermod -a -G web cool_user) - Add php-fpm or web server user (if php is used as a SAPI module) to
webgroup (for example, on CentOS php-fpm utilizeapacheuser name, so in most cases this will work:usermod -a -G web apache) - Change your project root directory group owner to
webrecursively (chgrp -R web /path/to/project/root/) - Grant recursively write permission for group (
chmod -R g+w /path/to/project/root/ - OptionallyTo allow all newly created by
apache(or some other) user files and folders be accessible from your user, make them receive group ownership same as their parent folder by setting groupidbit recursively on your project root directory (chmod -R g+s /path/to/project/root/).
- 进入超级用户模式(sudo -s 或 su)。
- 创建组
web(groupadd web) - 将您的主要用户添加到组
web(假设您的用户是cool_user,所以运行usermod -a -G web cool_user) - PHP-FPM或Web服务器用户(如果PHP作为SAPI模块)添加到
web组(例如,在CentOS的php-fpm的使用apache用户名,所以在大多数情况下,这将工作:usermod -a -G web apache) - 以
web递归方式将您的项目根目录组所有者更改为(chgrp -R web /path/to/project/root/) - 为组授予递归写入权限 (
chmod -R g+w /path/to/project/root/ - (可选)要允许
apache您的用户访问所有由(或某些其他)用户新创建的文件和文件夹,请通过在项目根目录 ( )上递归设置groupid位,使它们获得与其父文件夹相同的组所有权chmod -R g+s /path/to/project/root/。
Voila!.
瞧!。
Fast and dirty way, for those who doesn't care about security and want make it works at any cost, not secure:
快速而肮脏的方式,对于那些不关心安全性并希望不惜一切代价使其工作而不安全的人:
- Go in super user mode (sudo -s or su).
- Grant recursively full permission (read, write, execute) for all users (
chmod -R o=rwx /path/to/project/root/
- 进入超级用户模式(sudo -s 或 su)。
- 为所有用户授予递归完全权限(读取、写入、执行)(
chmod -R o=rwx /path/to/project/root/
回答by user2316785
In my case I resolved this error by modifying in file /app/config/app.php the default setting:
就我而言,我通过在文件 /app/config/app.php 中修改默认设置来解决此错误:
'url' => 'http://localhost',
to my local custom virtualhost host url:
到我的本地自定义虚拟主机主机 url:
'url' => 'http://mydomain.local',
This seemed to be THE essential change that resolved the issue (I also chmod'ed the storage folder, as suggested here)
这似乎是解决问题的基本更改(我还修改了存储文件夹,如建议here)
hope this helps some of you..
希望这对你们中的一些人有所帮助..
回答by jacanterbury
further to above, if you're using a virtualbox/vagrant VM type environment, then on my Mac I needed to issue the chmod on the host (mac) system but on my Windows box, it was fine issuing the chmod direcly on the VM.
更进一步,如果您使用的是 virtualbox/vagrant VM 类型环境,那么在我的 Mac 上,我需要在主机 (mac) 系统上发出 chmod,但在我的 Windows 机器上,可以直接在 VM 上发出 chmod .
回答by Relaxing In Cyprus
You need to read the installation documentation:
您需要阅读安装文档:
http://laravel.com/docs/installation#configuration
http://laravel.com/docs/installation#configuration
Pay attention to the bit here:
注意这里的位:
Laravel requires one set of permissions to be configured - folders within app/storage require write access by the web server.
There is also other stuff thats useful in that document, so make sure you read it all.
该文档中还有其他有用的内容,因此请务必阅读所有内容。
回答by Flavio
I had the same problem, here is how I solve it: In your httpd-vhosts.conf files you need to add the configurations to your folders, this is what I have in mine
我遇到了同样的问题,这是我的解决方法:在您的 httpd-vhosts.conf 文件中,您需要将配置添加到您的文件夹中,这就是我的
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/home/carlospublic_html"
ServerName carlos.local
<Directory "/home/carlos/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>>
回答by Flavio
You need to add: Options +FollowSymLinks
您需要添加:Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>
回答by sidneydobber
The webroot of your server should point to the /publicfolder of your Laravel installation. This is where the index.htmlfile recides from where Laravel is initialized.
服务器的 webroot 应该指向/publicLaravel 安装的文件夹。这是index.html文件从 Laravel 初始化的位置开始的地方。
回答by Justin
I like this method better than changing permissions to 777. Set Apache to run as you.
我更喜欢这种方法,而不是将权限更改为 777。将 Apache 设置为像您一样运行。
In terminal type
idto getuid=123(Myname).Open /etc/apache2/httpd.conf and edit it to use your username.
<IfModule unixd_module> User Myname Group staff </IfModule>Back to terminal:
sudo apachectl restart
在终端类型
id中获取uid=123(Myname).打开 /etc/apache2/httpd.conf 并编辑它以使用您的用户名。
<IfModule unixd_module> User Myname Group staff </IfModule>回到终端:
sudo apachectl restart

