简体   繁体   English

将Symfony 2.5.3网站部署到生产服务器

[英]Deploying Symfony 2.5.3 website to production server

I have been working on a website in development environment built on top of Symfony framework and now it is time to deploy it to live site, in development environment we run the command php app/console server:run to run the website but I am not sure what needs to be done to make the user see website contents on live server, after i uploaded the code to live server all I see is root directory structure of Symfony, I have gone through How to Deploy a Symfony Application and i am scratching my head as there is got to be more to it because after following the steps no difference was made and i still see directory structure. 我一直在开发基于Symfony框架的开发环境中的网站,现在是时候将其部署到实时网站了,在开发环境中,我们运行命令php app/console server:run以运行网站,但我不是确保将用户上传到实时服务器上后,要使用户看到实时服务器上的网站内容需要做些什么,我所看到的只是Symfony的根目录结构,我已经经历了如何部署Symfony应用程序,并且正在抓紧我的工作。头,因为有更多的东西,因为在执行以下步骤后没有区别,而且我仍然看到目录结构。

I did notice that when I click on the web folder I see the website so I created the following .htaccess file which works but the URL looks like www.domain.com/web how can i just make it www.domain.com 我确实注意到,当我单击Web文件夹时,我看到了网站,因此我创建了以下.htaccess文件,该文件可以工作,但URL看起来像www.domain.com/web ,我如何才能将其设置为www.domain.com

<IfModule mod_rewrite.c>
RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

I will really appreciate if I can get some help here, if it helps I am trying to deploy on Linux based server using Apache. 如果能在这里获得一些帮助,如果我尝试使用Apache在基于Linux的服务器上进行部署,我将不胜感激。

SOLUTION Add the following in your .htaccess file and it will work as this is what solved my problem and please remember to clear your browser cache as well 解决方法在您的.htaccess文件中添加以下内容,由于它可以解决我的问题,因此它将起作用,请记住也要清除浏览器缓存

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
</IfModule>

If you are running ubuntu do the following 如果您正在运行ubuntu,请执行以下操作

  sudo nano /etc/apache2/sites-enabled/000-default.conf

change document root to and save 将文档根目录更改为并保存

  DocumentRoot /var/www/html/web

Then run 然后跑

  sudo service apache2 restart

Then run 然后跑

 cd /var/www/html

 php app/console cache:clear --env=prod --no-debug

all done 全部做完

I don't know how it is done professionally because I don't use symfony, but I will tell you how I did it when I was testing on Linux. 我不知道它是如何专业完成的,因为我不使用symfony,但是我会告诉您在Linux上进行测试时我是如何做到的。

Let's say you have your www directory in /home/user/www/ (it doesn't really matter). 假设您在/home/user/www/有您的www目录(这并不重要)。 I would put whole symfony directory (with all directory structure) to some other directory (let's say /home/user/applications/my-symfony-webpage - the last being your directory with symfony files structure). 我会将整个symfony目录(具有所有目录结构)放置到其他目录中(例如/home/user/applications/my-symfony-webpage最后是您的带有symfony文件结构的目录)。

Last thing you need to do to make it work is to create a symlink which will direct from /home/user/www/ to /home/user/applications/my-symfony-webpage/web . 要使其正常工作,您需要做的最后一件事是创建一个符号链接,该符号链接将从/home/user/www/指向/home/user/applications/my-symfony-webpage/web

It can be done with this command: ln -s /home/user/applications/my-symfony-webpage/web /home/user/www/ (I think you need to delete www directory first if it's meant just for symfony installation). 可以使用以下命令完成此操作: ln -s /home/user/applications/my-symfony-webpage/web /home/user/www/ (我认为您仅需要删除www目录(如果仅用于symfony安装)) 。

That's my solution, I doubt it's the only one and probably not the best one. 那是我的解决方案,我怀疑这是唯一的解决方案,可能不是最好的解决方案。 I think you can create redirects with apache to direct some domains to some directory in your file structure (in your case to web directory of course). 我认为您可以使用apache创建重定向,以将某些域定向到文件结构中的某个目录(当然,将您的情况定向到web目录)。 You can look it up online. 您可以在线查找。

You have to configure your Apache to point your project folder web as document root. 您必须配置Apache,以将项目文件夹web指向文档根目录。

You can find information about to configure your server here: Configuring a Web Server (The Symfony CookBook) 您可以在此处找到有关配置服务器的信息: 配置Web服务器(Symfony CookBook)

After following all the How to deploy a Symfony App , in the root of your Symfony application create .htaccess file and add the following code in it, this is what solved my problem. 在完成所有如何部署Symfony应用程序之后 ,在Symfony应用程序的根目录中创建.htaccess文件并在其中添加以下代码,这就是解决我的问题的方法。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
</IfModule>

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

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