Using Symfony on a Shared Host

Screen Shot 2014-11-18 at 1.55.52 PM Most of my clients are on shared hosting. I advise the start-ups I work with to start on a good, respectable (just about anything besides GoDaddy or HostGator) shared hosting and save the expense.

I’ve heard some people say they can’t use Symfony on their shared hosting because Symfony requires command line access to use the tools. You may not be able to use these tools on your online hosting, but I usually build the site locally where I can use the tools and then ftp the files that are needed to the shared hosting account.

The next obstacle is the architecture and folder layout of symfony. Most shared hosting accounts use a different name for their web folder. Symfony2 makes this easy by allowing you to change the name of the folder without any problems.

If you move the web folder then you will need to change the paths to this folder in the front controller. I don’t suggest, however, that you put the app, src, and vendor folders inside the web folder since this opens them up to the public.

If your shared hosting uses cpanel. Just change your local web folder name to public_html. FTP everything from that local public_html folder to the shared hosting public_html folder when you are ready to deploy. Then FTP the app, src and vendor folders from your local machine to the root folder of your shared hosting – usually the folder containing the public_html folder.

As long as your public_html folder is in the same folder with your app, src and vendor folders you shouldn’t have to change anything. If they aren’t then you will need to change the paths to these files in your front controller.

Each time you FTP changes to your server you should clear the cache for your production environment. Assuming you are using prod for your production environment, you can just delete the app/cache/prod folder and all it’s contents. Then pull your site up in your browser and the cache will be rebuilt.

Anytime the cache needs to be cleared, you can just delete the app/cache/prod folder and pull up the site in your browser.

Everything should work fine on your shared hosting assuming the hosting provider has the resources required for Symfony 2.

14 thoughts on “Using Symfony on a Shared Host”

  1. Hello Cindy,

    I currently fight with a symfony2 deploy on a shared hosting.

    The issue that I’m encountering is how to make http://mydomain.com to use the symfony prod front controller (app.php)? From what I know, having a public_html folder on a shared hosting you tipically add an “index.php” or “index.html”, etc file there, but that doesn’t fit the symfony2 architecture.

    Also, regarding your post: “If you move the web folder then you will need to change the paths to this folder in the front controller” – There is a cookbook entry for that: http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html#override-the-web-directory.

    Cheers,
    Florin

    1. Florin, Make sure you have the .htaccess file set up correctly inside the puglic_html folder. This line will redirect it to the app.php instead of index.php:

      # Rewrite all other queries to the front controller.
      RewriteRule .? %{ENV:BASE}/app.php [L]

  2. After I checked that .htaccess file I noticed that everything is ok, the line is there.
    I’ve then tested another route that worked (domain/test-route).

    Guess what? The whole thing was just a “browser caching” issue. :)) I’ve opened an incognito window and hit the main domain and the thing worked as intended.

    Thanks!

    1. Great! Glad you got it working. Also, in case others may be having the problem, it could be a Symfony cache problem as well. So, they should try clearing the Symfony cache too. Thanks for leaving an update!

    2. Hey there! I am having problems deploying my Symfony project on a shared hosting – hostagator.
      The website is visible but all the images and other assets do not seem to work. They are not found. Can you please tell me how you achieved deploying it on a shared hosting.
      Thanks

  3. I am using Symfony on a Bluehost shared host. Everything has been working fine (still in beta), but I am now trying to use Bluehost’s Free Shared SSL Certificate for Registration, Login, etc.

    As per the instructions, I used the following URL to access the Sign In page:

    https://box####.bluehost.com/~username/login

    This works fine. However, after I am Signed in I would like the URL to return to my domain name (e.g. http://example.com/).

    This does not happen. The page goes to: https://box####.bluehost.com/~username/

    And then whatever page I go to the URL remains: https://box####.bluehost.com/

    Do you know what the best solution is to this problem? Is this a Symfony issue or a Bluehost issue?

    Do you know how to revert back to my domain name from the Bluehost domain name?

    Thank you for any help.

    Jim

  4. I want to upload my Symfony project to my shared hosting. Folder structure as follows:

    public_html/projects/Symfony/MyAppName

    how to configure paths now?

    1. You should be able to just change the paths to the app, src and vendor folders in your front controller.

  5. Hi Cindy,

    Have you already tried to deploy a Symfony 4 application to a shared hosting?
    I’m always interested in how to do it for the latest version…

    Thank you for helping me out…

    Jan

    1. No, Jan, I’ve moved on to Laravel. I still deploy Laravel projects to shared hosting – actually, easier than symfony in my opinion. I just copy the php files up there that I need. If I have ssh access I use the php artisan commands to migrate and seed the database. I change the .env environment variables file and make sure not to upload any development files that shouldn’t be on the production site. I’m sure there are better ways to do it and I’ll get there eventually, but done is better than perfect and as long as I’m keeping things as secure as possible, I find it works well.

  6. Hi Cindy,

    With Laravel, how do you get rid of the public folder on a shared host? Do you move the contents out from public/ to public_html/ ?

    1. Hi Andrew, It’s been a bit since I did this in Laravel, but if I remember correctly, it was super easy. I just changed the folder name from public to public_html on my dev and uploaded accordingly. I believe the way Laravel has the paths set up, it’s smart enough to figure it out. The only time I ran into a little bit of trouble was when I wanted to put the files in public_html/app or a different folder inside the public_html. Even then, it was as easy as going into the public_html/app/index.php and changing this line to go up another directory level: require __DIR__.’/../../bootstrap/autoload.php’;

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top