Deploying a Symfony Project on GoDaddy Shared Hosting
Posted by gfaraj on April 25, 2008
Recently, I had the task of deploying my Symfony project on my GoDaddy shared Linux hosting. I ran into some problems, and I thought I would share in hope of helping any other poor soul who might run into the same problems.
First of all, you should follow the steps here. It does not require you to freeze the project to deploy it. I find that useful for projects that are not yet stable and need to deploy a “beta” version. Also, make sure you have PHP 5 as the default in your GoDaddy Hosting settings.
Next, you need to modify the .htaccess file. Go ahead and uncomment the RewriteBase line in the default symfony .htaccess file:
# uncomment the following line, if you are having trouble # getting no_script_name to work RewriteBase /
This should prevent ‘www.myhost.com/mymodule’ from getting a 404 error from GoDaddy. Now, at least you might get forwarded to your 404 module/action. This is, at least, some proof that you’re moving forward. If you turn on logging (logging is turned off for production configurations by default), you might see the following:
1 Info Context initialization 2 Info Controller initialization 3 Info Routing match route [default_index] "/:module" 4 Info Request request parameters array ( 'module' => 'index.php', 'action' => 'index',) 5 Info Controller dispatch request 6 Info Controller action "indexphp/index" does not exist
As you can see, the module/action resolution is very wrong. This, of course, results in Symfony forwarding to your 404 module/action. Well, it turns out that adding one line to your php5.ini fixes this.
cgi.fix_pathinfo = 1
This worked nicely for me, and I hope it works for you. I’m posting my full php5.ini and .htaccess files for completeness.
Addendum
It has come to my attention that some people are still having problems after making the changes described here. You might want to try one more change. In your application’s config/settings.yml file, set the following setting:
prod:
.settings:
path_info_key: REDIRECT_URL
php5.ini
register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" memory_limit = 20000000 session.gc_maxlifetime = 72000 #log_errors = On #error_log = php_error.log #display_errors = On #error_reporting = E_ALL magic_quotes_gpc = false cgi.fix_pathinfo = 1 [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so
.htaccess
Options +FollowSymLinks +ExecCGI
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
# big crash from our front web controller
ErrorDocument 500 "<h2>Application error</h2>symfony application failed to start properly"
Michal Thomka said
Thank you very much for this helpful post!
Spent couple of hours trying to figure this out, it was already giving me quite a headache
All the best
Michal
gfaraj said
Glad it helped you
Zvi Landsman said
My top level directory on GoDaddy is my public html directory – this poses a security risk if all of my files are public.
Is there a way to configure this on GoDaddy (economy plan), or set up .htaccess to prevent these files from being accessed?
gfaraj said
Unfortunately, GoDaddy has that retarded flaw. I have no idea if they have an option to change it. You could probably write a .htaccess rewrite rule to protect the files from being accessed though.
bob said
3r0rjZ hi nice site thanx http://peace.com
Alexwebmaster said
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
Franck said
Thank you !
Important: in sf1.2 “path_info_key: REDIRECT_URL” is in the factories.yml file not in the settings.yml
XRumerMonstroZ said
Hi!
Gimme url for downloading XRumer 5.0 Palladium crack!
Thank you…
Very-very much.
I’m so need this program for advertise my web projects!!! This software is the best thing for online promo and mass posting, you know…
And, dont send me XRumer 2.9 and XRumer 3.0 – that versions are too old!
P.S. Google cant help me((((
sapumal said
Thank you very much. I had the exact problem and this method worked for me.
Jen said
The Symfony site mentions how shared hosting can be “unsafe”… is GoDaddy affected by the things they mention or can I use Symfony and not worry? I have GoDaddy shared as well and I’m able to navigate all over the place in SSH. I can see other user’s account names (but not their files)… I don’t really know enough about security to know if that means I’m vulnerable. Any help would be appreciated.
Dreceinge said
hmm. attractive )
car accident lawyer jacksonville said
i must say, your blog is very good, i will be checking back to read more
taunlinuere said
I really enjoyed reading your article, keep up posting such interesting stuff!