Deploying Symfony 2.5.3 website to production server
Asked Answered
A

4

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>
Ahmadahmar answered 17/9, 2014 at 10:16 Comment(3)
One better solution is to say your web host to give path of DocumentRoot up to web.Superannuation
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?Ahmadahmar
Take a look here: #12462720 ;)Cordiecordier
A
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>
Ahmadahmar answered 18/9, 2014 at 7:53 Comment(0)
S
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

Seaden answered 17/9, 2014 at 12:40 Comment(7)
what if you are on shared hosting and no access to apache configuration file?Ahmadahmar
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]Seaden
what is this going to do?Ahmadahmar
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.Seaden
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 onAhmadahmar
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 accessSeaden
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 <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>Ahmadahmar
C
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.

Clite answered 17/9, 2014 at 11:6 Comment(7)
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 caseAhmadahmar
What I said would put symfony in your domain.com (no web in address)Clite
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.Ahmadahmar
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.Clite
But if thats something you don't understand then just keep reading the official document for configuration.Clite
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?Ahmadahmar
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 ;)Clite
S
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)

Sellars answered 17/9, 2014 at 11:31 Comment(2)
I think this cannot be done for people on shared hosting as hosting companies do not provide access to Apache configuration fileAhmadahmar
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: 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.Sellars
A
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>
Ahmadahmar answered 18/9, 2014 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.