1

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>
Shairyar
  • 3,268
  • 7
  • 46
  • 86
  • One better solution is to say your web host to give path of DocumentRoot up to web. – herr Sep 17 '14 at 11:34
  • imagine if you want to create a script to sell it, how on earth people without this kind of knowledge will be able to use the script? – Shairyar Sep 17 '14 at 12:04
  • Take a look here: http://stackoverflow.com/questions/12462220/steps-to-move-symfony-2-project-to-hosting ;) – sphinks Jun 30 '15 at 10:24

4 Answers4

2

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

Matthew A Thomas
  • 924
  • 7
  • 15
  • what if you are on shared hosting and no access to apache configuration file? – Shairyar Sep 17 '14 at 12:51
  • I'm not sure if this can be done with htacess as I have never tried, but if I was to write something it may look like this `RewriteEngine on RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.domain-name.com$ RewriteCond %{REQUEST_URI} !folder/ RewriteRule (.*) /folder/$1 [L]` – Matthew A Thomas Sep 17 '14 at 12:55
  • what is this going to do? – Shairyar Sep 17 '14 at 12:57
  • domain-name.com - Type your own domain name folder - Type the name of the sub-folder which has the web directory i.e. !web/ it is an attempt to rewrite the base url request to the web directory. – Matthew A Thomas Sep 17 '14 at 12:59
  • like i mentioned in my question that i am able to get the site to work with `.htaccess` by pointing it to the `web` folder except that now each URL has the word `web` in it like www.domain.com/web/about www.domain.com/web/services and so on – Shairyar Sep 17 '14 at 13:06
  • Then i think your stuck, honestly using Symfony framework it is recommended to use a hosting provider with ssh access, check out AWS at the moment you can get 12 months free access – Matthew A Thomas Sep 17 '14 at 13:08
  • nope not stuck, the `.htaccess` did the trick, this is what i have in my `.htaccess` file and it works like a charm, there is no mention of `web` folder in all URLs ` RewriteEngine On RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.domain.com$ RewriteCond %{REQUEST_URI} !web/ RewriteRule (.*) /web/$1 [L] ` – Shairyar Sep 17 '14 at 13:21
1

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.

Kelu Thatsall
  • 2,494
  • 1
  • 22
  • 50
  • Thanks for giving me your point of view, i have updated my question, i have mentioned that the site is working when i add `.htaccess` file and redirect to `web` folder but the domain looks like `domain.com/web` and all links look like `domain.com/web/about` and so on. The website is in root `public_html` and not in subfolder, just mentioning it in case – Shairyar Sep 17 '14 at 11:29
  • What I said would put symfony in your domain.com (no `web` in address) – Kelu Thatsall Sep 17 '14 at 11:35
  • I am saying there is a `web` folder that comes with symfony, this is the folder that people need to access in order to view the site. – Shairyar Sep 17 '14 at 12:05
  • I know that, that's what I said. You can put symlink to your `web` folder in place of your `www` directory and the symfony will work this way: domain.com/app.php. – Kelu Thatsall Sep 17 '14 at 12:07
  • But if thats something you don't understand then just keep reading the official document for configuration. – Kelu Thatsall Sep 17 '14 at 12:08
  • I am not aware of what is `symlink` i need to search about it, but what you are saying, is that same as changing the default root document of a domain to `web`? – Shairyar Sep 17 '14 at 12:17
  • effect is the same, but it's not the same. symlink is symbolic link - it's kinda "like" shortcuts in windows. But it's generally better to change default root document of domain ;) – Kelu Thatsall Sep 17 '14 at 13:18
1

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)

  • I think this cannot be done for people on shared hosting as hosting companies do not provide access to Apache configuration file – Shairyar Sep 17 '14 at 12:52
  • Some shared hostings let you configure a subdirectory of your public folder as the entry point. In other case you can try with the `.htaccess` configuration. As a start point you can take a look here: http://silex.sensiolabs.org/doc/web_servers.html . You can use Silex with `web` directory and you can see a note about configure it with a directory that it is not the webroot. – pedro.nofuentes Sep 17 '14 at 20:38
1

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>
Shairyar
  • 3,268
  • 7
  • 46
  • 86