【问题标题】:Error 500 on Symfony2 deploymentSymfony2 部署时出现错误 500
【发布时间】:2015-04-01 21:19:25
【问题描述】:

几天来我一直在为一个奇怪的错误而苦苦挣扎。到目前为止,我设法创建了一个工作应用程序,在本地一切正常。我尝试部署我的应用程序,但收到以下消息:

内部服务器错误

服务器遇到内部错误或配置错误,并且 无法完成您的请求。

由于这是我的第一次部署,我完全不知道在哪里查看。我搜索了一段时间,使用了调试器,使用 Insight 修复了每个主要和严重错误,但我仍然收到相同的错误消息。

最大的问题是我根本没有日志。我授予了对 app/cache 和 app/logs 的所有访问权限,但没有在服务器上创建日志文件。

编辑

这里是 Apache 日志

[Sun Mar 29 18:35:26.944078 2015] [:error] [pid 83621] [client 127.0.0.1:59365] PHP Notice:  Undefined index: user in /Volumes/Data/nfs/zfs-student-2/users/2013_paris/ptran/mamp/apps/AOFVH/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 1758
[Sun Mar 29 18:35:26.944155 2015] [:error] [pid 83621] [client 127.0.0.1:59365] PHP Warning:  Invalid argument supplied for foreach() in /Volumes/Data/nfs/zfs-student-2/users/2013_paris/ptran/mamp/apps/AOFVH/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php on line 1763
[Sun Mar 29 18:35:26.954155 2015] [:error] [pid 83621] [client 127.0.0.1:59365] PHP Notice:  Undefined index: user in /Volumes/Data/nfs/zfs-student-2/users/2013_paris/ptran/mamp/apps/AOFVH/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php on line 183
[Sun Mar 29 18:35:26.954175 2015] [:error] [pid 83621] [client 127.0.0.1:59365] PHP Fatal error:  Call to a member function setValue() on a non-object in /Volumes/Data/nfs/zfs-student-2/users/2013_paris/ptran/mamp/apps/AOFVH/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/PersistentCollection.php on line 183

【问题讨论】:

  • 您向我们提供了生产错误消息。 Apache 日志和其中的实际 PHP 错误呢?
  • 我添加了 Apache 日志。 “实际的 PHP 错误”是什么意思?
  • BasicEntityPersister.phpPersistentCollection.php 中的那些。看看他们。
  • 看看这个问题,看来你也有同样的问题:*.com/questions/3328836/…
  • php app/console dictionary:schema:validate 返回什么?有没有失败?

标签: php symfony deployment


【解决方案1】:

我得到它的工作,这是我的经验:

Upload the whole project folder to the server.
Enter www.your-website.com/project-name/web/config.php.
It should say: "This script is only accessible from localhost".
Open this web site: http://www.whatismyip.com, it should show you your public IP address, copy it.
Open the config.php from the admin panel (like cPanel) and edit that config.php:

if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1', /你的 IP/))) { header('HTTP/1.0 403 禁止'); die('这个脚本只能从 localhost 访问。');
}

Refresh your config.php file, the page will tell you if your system is missing some required conditions like: PHP version, APC extension, giving /cache and /log folders permissions to write on, etc.
After you provide the required conditions you'll see a form of configuring you project to connect to a database if you have one, this step is pretty simple.
Open the link www.your-website.com/project-name/web/app_dev.php, it'll help you get started with Symfony2 project.
In case you got in app_dev.php this message: You are not allowed to access this file... just do the same thing to app_dev.php as you did in steps 4 and 5 (add your public IP address to the array).
Note of Hakan Deryal (comment): If you don't have a fix IP address, you need to do this last step each time you get a new IP adrdress from the DHCP. So to solve that, open the app_dev.php and comment out the line die('You are not allowed to.., however this is not a recommended way because you're disabling the built-in security of the file.
One thing stopped me and may stop you too, the server I deployed the project on, was case-sensitive (unlike the localhost on my computer), so it kept telling me that the template (Index.html.php for example) does not exist, however it does exist, but I did return $this->render('...:index.html.php') with small i in DefaultController.php. So render the exact template (file) name with the same letters cases.

现在一切顺利,希望对你有所帮助。

【讨论】: