Thursday, June 13, 2013

Steps to move Symfony 2 project to hosting?

Steps to move Symfony 2 project to hosting?

 

Altenative 1

First the httpd.conf file MUST be changed to reference /sites/dir/website/web directory as the DocumentRoot directory, all other files such as lib and config must not be accessible over the web.

 

Altenative 2

 

  1. It depends on kind of hosting that you have: if you have SSH console, then you can do it on hosting after step 2, if you haven`t than do it localy: run command 'php app/console cache:clear --env=prod'.
  2. Suppose you have on you hosting folders youdomain/public_html, so in public_html must be located all web files. So you must upload all from symfony project (folders: app,src,vendors, bin; files: deps, deps.lock), except folder 'web' in folder 'youdomain'. Everuthing from folder 'web' upload to folder public_html.
  3. Check CHMOD for folders app/cache and app/logs, there should be write access.
  4. If there is no file .htaccess in public_html, then create it and add such code in it: https://raw.github.com/symfony/symfony-standard/master/web/.htaccess
  5. Now you should use youdomain.com/index instead of youdomain.com/app_dev.php/index, that you use locally. If site still did not works, you can open file web/config.php and find code where perform check for IP, you find there only ip 127.0.0.1, add your current ip to this list and upload new config on server. Then you can open path yourdomain/config.php and check what`s wrong. If config.php shows that everything ok, but still didn't work, you can enable app_dev.php to debug: open app/app_dev.php and your ip as for config.php. Now you can run scripts as localy using app_dev.php.

 

 

Alternative3

 

I got it to work, this is my experience:
  • Upload the whole project folder to the server.
  • Enter www.your-website.com/project-name/web/config.php.
  • It should say: "This script is only accessible from localhost".
  • Open this web site: http://www.whatismyip.com, it should show you your public IP address, copy it.
  • Open the config.php from the admin panel (like cPanel) and edit that config.php:

if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1', /*your IP here*/))) {
    header('HTTP/1.0 403 Forbidden');
    die('This script is only accessible from localhost.');  
}

  • Refresh your config.php file, the page will tell you if your system is missing some required conditions like: PHP version, APC extension, giving /cache and /log folders permissions to write on, etc.
  • After you provide the required conditions you'll see a form of configuring you project to connect to a database if you have one, this step is pretty simple.
  • Open the link www.your-website.com/project-name/web/app_dev.php, it'll help you get started with Symfony2 project.
  • In case you got in app_dev.php this message: You are not allowed to access this file... just do the same thing to app_dev.php as you did in steps 4 and 5 (add your public IP address to the array).
    Note of Hakan Deryal (comment): If you don't have a fix IP address, you need to do this last step each time you get a new IP adrdress from the DHCP. So to solve that, open the app_dev.php and comment out the line die('You are not allowed to.., however this is not a recommended way because you're disabling the built-in security of the file.
  • One thing stopped me and may stop you too, the server I deployed the project on, was case-sensitive (unlike the localhost on my computer), so it kept telling me that the template (Index.html.php for example) does not exist, however it does exist, but I did return $this->render('...:index.html.php') with small i in DefaultController.php. So render the exact template (file) name with the same letters cases.
Now everything is going well, I hope that helps you.

 

No comments:

Post a Comment