Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a Symfony2 project

We were working on a Symfony2 project. Now, it's done and ready to be deployed. We uploaded the whole project files to the server (via ftp of course) and the database as well. Now when we open any page of it we got just a blank page (empty source code). Cache is clean, logs do not show anything new. We googled the steps of deploying a Symfony2 project to a hosting but we did not find a good explanation (even these ones were about Symfony not-version-2). We believe it maybe a configuration issue, but no idea so far. Any help will be greatly appreciated. Thanks in advance.

Edit: the blank page is in Firefox. Google Chrome is saying something:

Server error The website encountered an error while retrieving http://*.com/mammoky/web/app_dev.php/main. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

error_log is showing:

[24-Mar-2012 23:29:24] PHP Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/leadow33/public_html/mammoky/web/app.php on line 7

It's: use Symfony\Component\HttpFoundation\Request; And

[24-Mar-2012 23:15:08] PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/leadow33/public_html/mammoky/web/config.php on line 84

It's: $reflector = new \ReflectionExtension('intl');


EDIT: I've posted my solution, check it out down here.

like image 798
Nadjib Mami Avatar asked Mar 24 '12 21:03

Nadjib Mami


2 Answers

Answer:

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.

like image 74
Nadjib Mami Avatar answered Oct 08 '22 04:10

Nadjib Mami


In my case it was the php version* and I catched the error by running config.php with removed lines for checking ip address. On my hosting I just changed the default version of PHP for my scripts.

*Since namespaces are only from 5.3.

like image 38
Peter Csiba Avatar answered Oct 08 '22 06:10

Peter Csiba