PHP Fog is a new PHP PaaS service. It’s dazzling. It takes the weight of deploying applications to the cloud off your shoulders and allows you to focus on writing code. You can deploy your app’s with a simple
git push phpfog master. This is great, but PHP Fog is new and there is no built-in considerations for Symfony2. That makes sense – Symfony2 is still (at the time of writing) in beta. But I want to deploy Symfony2 apps now!
In this article I’ll show you how you can use PHP Fog to host a Symfony2 application. For the purpose of ease we are going to use Github but you could just as easily host your code with Beanstalk, or use PHP Fog’s Git repository alone.
If you already have your application in Git and have at least one production route, then you can skip to the next step.
CompanyExampleBundlewhere company is the name of your company, group, or project. Don’t forget to add
Companyto the auto-loader in
app/autoload.php, and register the bundle in
src/Company/Controller/HelloWorldController.phpwhich renders a view
CompanyExample:HelloWorld:index.html.twig. In the view, put in a nice little
_welcomeroute’s pattern to
/welcome. Now go to
app/routing.ymland add a route like so:
http://localhost/yourproject/web/app_dev.php/in your browser. If you see a
Hello world!, then you’re gravy. Now substitute app_dev.php for just app.php to access the production front controller and make sure you see the same thing. If you get a 400 or things appear to be as they were before, you might need to blow production cache. This can be done from the command line like so:
Pushing your app to PHP Fog is really easy. It’s perhaps my favorite thing to do.
~/.ssh/id_rsa.pubto the accepted SSH keys in your Account Settings.
robots.txtfile that comes with Symfony2 by default. Should be at a url like so:
http://company.phpfogapp.com/web/robots.txt. If this resolves, you’ve successfully deployed your code to the cloud!
You’re not done yet, however, you still need to tweak you PhpFog app to Symfony2’s liking.
You’re almost there. There’s just a couple things left…
appdirectory, and therefor needs write access. Go to the “Permissions” tab of your app’s admin panel and add the pathname
appand save changes.
web. This will tidy up your url, you won’t have to type in /web before accessing resources.
web/clean_prod_cache.phpwith the code like so:
http://company.phpfogapp.com/clean_prod_cache.phpthe cache will be wiped and warmed. All ready to go.
I hope that this guide helps both developers looking to use Symfony2 on PHP Fog early as well as the PHP Fog team in implementing Symfony2 support.