I am trying to learn how to successfully deploy Symfony2 application on amazon cloud. What worked is that I started with blank Ubuntu, installed lamp-server^, svn… few other goodies and it worked perfectly.
The problem: all assets and DB were hosted on that one instance and I know it is not the right thing to do. I checked numerous sites and didn’t find any easy solution of setting real S2 application, only WordPress and alike.
My application allows users to upload images and then display them using Liip/Imagine bundle
I also checked AmazonWebServices bundle and I guess I should somehow use both of them; first one for display, second one for sending files to S3 bucket. And it also must work in my local Windows enviroment.
- How to solve that? Is there some really idiot-proof solution for this?
- RDS requires to read
Default1234$dbhost = $_SERVER['RDS_HOSTNAME'];$dbport = $_SERVER['RDS_PORT'];$dbname = $_SERVER['RDS_DB_NAME'];
to be able to access mysql. How to do that when using parameters.yml?
Whilst as you can use AWS to provide standalone servers, if you wish to support multiple instances, load balancing etc, you’ll want to separate things out. At the most basic level you’ll likely want to be using:
- S3 – persistent storage
- RDS – MySQL database
- EC2 – Apache / Nginx, PHP front end
You can then augment this with:
- Cloudfront – localised delivery of your S3 content
- Loadbalancer – ensure your EC2 instances are used optimally
- Auto scaling – start / stop new instances
- Route 53 – DNS
- VPC – important as this offers security, single front ends for SSL certificates etc.
Also, rather than start from scratch you can use AMI’s from the marketplace: https://aws.amazon.com/marketplace/
Checkout the AWS getting started guide as this goes through everything in detail: http://docs.aws.amazon.com/gettingstarted/latest/wah-linux/web-app-hosting-intro.html
Using the above, I’d suggest moving your database to RDS and simply hosting Apache on your EC2 instances. You might even find this is cost effective too as you’ll be able to utilise small instances given the lower memory / CPU requirements.
Also, as time progresses, you can start to look at Elastic Beanstalk and Chef (maybe even vagrant for local dev boxes), Elastic Beanstalk (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP_symfony2.html)
first up, environments
I’m assuming you’ve created production and development environments: http://symfony.com/doc/current/cookbook/configuration/environments.html. This is important as you are able to change configuration between local and production environments.
Checkout https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/data-loader/stream.md which utilises https://github.com/KnpLabs/Gaufrette (or the bundle: https://github.com/KnpLabs/KnpGaufretteBundle).
There appears to be a good article on how to configure it here: https://florian.ec/articles/upload-files-to-amazon-s3-with-symfony2-and-gaufrette/
Using the above environments, you’d be able to configure production to read/write to s3, whereas developments write to /tmp (for example)
I’m going to make an assumption that you’re using Doctrine as your DB connection and have followed the Symfony docs on how to set up the configuration: http://symfony.com/doc/current/book/doctrine.html#configuring-the-database.
All you’d need to do is follow the environment logic and set the db strings production / local accordingly. This should be seamless in the background and not require manual MySQL connections.