Deploying Symfony 2.5.3 website to production server

≯℡__Kan透↙ 提交于 2019-12-20 04:10:59

问题


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.

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

<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.

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

<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>

回答1:


If you are running ubuntu do the following

  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




回答2:


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.

Let's say you have your www directory in /home/user/www/ (it doesn't really matter). 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).

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.

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).

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). You can look it up online.




回答3:


You have to configure your Apache to point your project folder web as document root.

You can find information about to configure your server here: Configuring a Web Server (The Symfony CookBook)




回答4:


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.

<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>


来源:https://stackoverflow.com/questions/25887925/deploying-symfony-2-5-3-website-to-production-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!