Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Symfony2 application on amazon (for dummies)

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.

  1. How to solve that? Is there some really idiot-proof solution for this?
  2. RDS requires to read

    $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?

like image 564
Zeljko Avatar asked Dec 17 '13 16:12

Zeljko


People also ask

How do I create an Elastic Beanstalk application?

To create an applicationOpen the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Applications, and then choose Create a new application. Use the on-screen form to provide an application name. Optionally, provide a description, and add tag keys and values.

Can I host a PHP website on AWS?

A: You can host Laravel, CodeIgniter, CakePHP, Symfony, and many other PHP frameworks on AWS Cloud servers. All of these frameworks are quite advanced and provides optimized features to be deployed with PHP7 AWS EC2 servers.

How do I use AWS Beanstalk?

Create an application and an environment It creates an Elastic Beanstalk application and launches an environment within it. An environment is the collection of AWS resources required to run your application code. Optionally add application tags. For Platform, choose a platform, and then choose Create application.


2 Answers

Infrastructure

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)

So, Symfony

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.

Imagery

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)

Database.

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.

like image 125
stefancarlton Avatar answered Oct 13 '22 21:10

stefancarlton


You can use Amazon s3 bucket to store your files. Have a look at https://github.com/KnpLabs/Gaufrette , it enables you to store files on either local filesystem, Amazon s3 filesystem, or other, simply by control it using configuration. For specifying the database details on RDS. configure the following in parameters.yml:

database_driver:   pdo_mysql
database_host:     127.0.0.1
database_port:     ~
database_name:     symfony
database_user:     root
database_password: password
like image 25
shacharsol Avatar answered Oct 13 '22 23:10

shacharsol