简体   繁体   English

将Symfony3应用程序从开发人员迁移到生产服务器时出现问题

[英]Problems when moving Symfony3 app from dev to production server

I've created a web application using Symfony 3. In the development environment, I always use Symfony's built-in server and just use the command "php bin/console server:run". 我已经使用Symfony 3创建了一个Web应用程序。在开发环境中,我始终使用Symfony的内置服务器,而仅使用命令“ php bin / console server:run”。 The app can then be accessed via "localhost:8000". 然后可以通过“ localhost:8000”访问该应用程序。

I've also defined routes using annotations in Controllers such as "/", "/about" etc. These pages can be accessed via "localhost:8000/" and "localhost:8000/about". 我还使用Controller中的注释(例如“ /”,“ / about”等)定义了路由。可以通过“ localhost:8000 /”和“ localhost:8000 / about”访问这些页面。 Other links on the page that point to routes like "/contact" or "/users/1" also work perfectly. 页面上指向“ / contact”或“ / users / 1”之类的路由的其他链接也可以正常工作。 They will link to "localhost:8000/contact" and "localhost:8000/users/1". 它们将链接到“ localhost:8000 / contact”和“ localhost:8000 / users / 1”。

Now, I move my application to the production server. 现在,我将应用程序移至生产服务器。 On the production server, Apache2 is installed and some other people have developed Symfony applications on it. 在生产服务器上,安装了Apache2,其他一些人已经在其上开发了Symfony应用程序。 Their apps can be accessed via url like "example.com/apps/app1/web/app_dev.php" and the links on their apps have been pre-appended with "example.com/apps/app1/web/app_dev.php" automatically. 可以通过诸如“ example.com/apps/app1/web/app_dev.php”之类的网址访问其应用,并且其应用上的链接已预先添加“ example.com/apps/app1/web/app_dev.php”自动。 So when the user clicks a button that links to "/contact", the link will direct to "example.com/apps/app1/web/app_dev.php/contact". 因此,当用户单击链接到“ /联系人”的按钮时,该链接将定向到“ example.com/apps/app1/web/app_dev.php/contact”。

Now, when I move my application named "app2" under the "example.com/apps/" directory, I can visit "example.com/apps/app2/web/app_dev.php" without any configuration and see my homepage perfectly. 现在,当我将名为“ app2”的应用程序移动到“ example.com/apps/”目录下时,无需进行任何配置即可访问“ example.com/apps/app2/web/app_dev.php”,并且可以完美地看到我的主页。 Apache can automatically pick up my code. Apache可以自动获取我的代码。 However all the links on the homepage will direct to "example.com/contact" instead of "example.com/apps/app2/web/app_dev.php/contact". 但是,首页上的所有链接都将直接指向“ example.com/contact”,而不是“ example.com/apps/app2/web/app_dev.php/contact”。

Can anyone help me with this? 谁能帮我这个? I'm pretty new with Symfony and Apache. 我对Symfony和Apache相当陌生。

Or perhaps I've done the migration from dev to production environment in a totally wrong way? 还是我以完全错误的方式完成了从开发人员到生产环境的迁移? Any new ideas or proper way to move Symfony3 application to production server? 是否有将Symfony3应用程序移至生产服务器的新想法或正确方法?

Thanks a lot! 非常感谢!

Do you have apache configured correctly? 您的apache配置正确吗? You may need to have a virtualhost configuration added to the server. 您可能需要将虚拟主机配置添加到服务器。 You can find out about it on the Symfony site for the specifics. 您可以在Symfony网站上找到它的详细信息。

I finally solved the issue. 我终于解决了这个问题。 I should use href="{{ path('about') }}" instead of href="/about" in all twig templates. 我应该在所有树枝模板中使用href =“ {{path('about')}}”“而不是href =” / about“。 Thanks everybody! 谢谢大家!

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

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