简体   繁体   English

Symfony 3中的HTTP 500错误

[英]HTTP 500 Error in Symfony 3

I created an app on my localhost using symfony 3 . 我使用symfony 3localhost上创建了一个应用程序。 Stuff works perfectly well on my local host. 在我的本地主机上,东西工作得很好。 Now my main problem is moving it to my shared hosting ( cPanel ). 现在,我的主要问题是将其移至共享主机( cPanel )。 Moved the files to the public_html folder, then I moved the .exe , bin , src , var , etc folders to the parent folder (The folder containing the public_html folder) while leaving the 'web' folder in the public_html . 将文件移动到public_html文件夹,然后将.exebinsrcvar等文件夹移动到父文件夹(包含public_html文件夹的文件夹),同时将'web'文件夹保留在public_html I then moved everything from the 'web' folder (Which is inside the public_html folder) into the public_html folder. 然后,我将所有内容从“ web”文件夹(位于public_html文件夹中)移到public_html文件夹中。 Making me have the following directory structure: 使我具有以下目录结构:

cpanel-root-directory<br>
---/app<br>
---/bin<br>
---/src<br>
---/tests<br>
---/var<br>
---/vendor<br>
---/public_html<br>
------/bundles<br>
------/css<br>
------/dist<br>
------/fonts<br>
------/img<br>
------/js<br>
------/plugins<br>
------/uploads<br>
------.htaccess<br>
------app.php<br>
------app_dev.php<br>
------apple-touch-icon.png<br>
------config.php<br>
------robots.txt<br>
<br>

When I go to the domain name, I keep getting this annoying HTTP 500 error. 当我转到域名时,我不断收到此烦人的HTTP 500错误。 Then on both localhost and on the server (at different times), I created a fresh new symfony project, dumped it in the server and got the "Welcome to Symfony 3" page quite alright. 然后在localhost和服务器上(在不同的时间),我创建了一个新的新symfony项目,将其转储到服务器中,并获得了“ Welcome to Symfony 3”页面。 But, when I tried putting my controller files, and going to the routes defined in them (I use annotations in the Sensio bundle to define routes), I get that HTTP 500 error. 但是,当我尝试放置控制器文件并转到其中定义的路由时(我使用Sensio捆绑包中的注释来定义路由),出现了HTTP 500错误。 Then, in the default controller that works, I try defining a new action 'testAction'. 然后,在有效的默认控制器中,我尝试定义一个新动作“ testAction”。 When I go to the route for the test action, I still get the HTTP 500 error, but going to the '/' route, I see the symfony welcome page correctly. 当我转到测试操作的路由时,我仍然收到HTTP 500错误,但是转到“ /”路由,我可以正确看到symfony欢迎页面。

My clients have seen that the stuff works perfectly well on my localhost , but now moving it to the server is the issue. 我的客户已经看到,这些东西在我的localhost上运行良好,但是现在将其移动到服务器是个问题。

If you can (have access), just keep your web dir, and then make public_html a symlink to your web dir. 如果可以(具有访问权限),只需保留您的Web目录,然后将public_html链接到您的Web目录即可。

If you need to change the name of your "web" dir, you need to follow this instructions: http://symfony.com/doc/current/configuration/override_dir_structure.html 如果您需要更改“ Web”目录的名称,则需要遵循以下说明: http : //symfony.com/doc/current/configuration/override_dir_structure.html

You should check this paragraph from Symfony documentation 您应该从Symfony文档中检查此段

This part seems to describe exactly your problem: 这部分似乎准确地描述了您的问题:

Some shared hosts have a public_html web directory root. 一些共享主机具有public_html Web目录根。 Renaming your web directory from web to public_html is one way to make your Symfony project work on your shared host. 将Web目录从Web重命名为public_html是一种使Symfony项目在共享主机上工作的方法。 Another way is to deploy your application to a directory outside of your web root, delete your public_html directory, and then replace it with a symbolic link to the web in your project. 另一种方法是将应用程序部署到Web根目录之外的目录,删除public_html目录,然后将其替换为指向项目中Web的符号链接。

Eh, I think that's because, now, you are online, so you need to clear the cache for the prod environment: 恩,我认为那是因为现在您在线,所以您需要清除产品环境的缓存:

$ php bin/console cache:clear --env=prod

But you say you are on a shared hosting, so unless you have some available tools to access the terminal (and run the above command), then you need to manually delete the var/cache/prod directory if present. 但是您说您正在共享主机上,因此,除非您有一些可用的工具来访问终端(并运行上面的命令),否则您需要手动删除var/cache/prod目录(如果存在)。

Or if this doesn't work, I usually, don't upload the var/cache + var/logs + var/sessions directories at all, but create them manually as empty ones, and then let Symfony do its job with them by default. 或者如果这不起作用,我通常通常根本不上传var/cache + var/logs + var/sessions目录,而是手动将它们创建为空目录,然后默认情况下让Symfony对其进行处理。

LE LE

Maybe you have another problem, and the one with the cache you've solve it already. 也许您还有另一个问题,而带有缓存的问题已经解决了。 So, to check if there is something wrong with your app, enable the dev mode ( app_dev.php ), by modifying, locally, your public_html/app_dev.php file, and comment out these lines: 因此,要检查您的应用程序是否存在问题,请通过在本地修改public_html/app_dev.php文件并启用以下行来启用dev模式( app_dev.php ):

if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

And then, copy this file over the one on the server, and then access a route with app_dev.php in front, and see if there is an error (eg): 然后,将该文件复制到服务器上的那个文件中,然后使用前面的app_dev.php访问路由,看看是否有错误(例如):

http://www.domain.com/app_dev.php/existing_route

After you are done, don't forget to uncomment the code inside app_dev.php ,and re-upload the file on the server. 完成后,请不要忘记取消注释app_dev.php的代码,并在服务器上重新上传文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM