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.
我正在尝试学习如何在亚马逊云上成功部署Symfony2应用程序。有用的是我开始使用空白的Ubuntu,安装了lamp-server ^,svn ......其他很少的东西,它工作得很好。
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.
问题是:所有资产和数据库都托管在那个实例上,我知道这不是正确的做法。我检查了很多网站,并没有找到任何简单的解决方案设置真正的S2应用程序,只有Wordpress和类似。
My application allows users to upload images and then display them using Liip/Imagine bundle
我的应用程序允许用户上传图像,然后使用Liip / Imagine软件包显示它们
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.
我还检查了AmazonWebServices包,我想我应该以某种方式使用它们;第一个用于显示,第二个用于将文件发送到S3存储桶。它也必须在我当地的Windows环境中工作。
- How to solve that? Is there some really idiot-proof solution for this?
- 怎么解决?是否有一些真正的白痴解决方案?
-
RDS requires to read
RDS需要阅读
$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?
能够访问mysql。使用parameters.yml时如何做到这一点?
3 个解决方案
#1
22
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:
虽然您可以使用AWS来提供独立服务器,但如果您希望支持多个实例,负载平衡等,那么您需要将事情分开。在最基本的级别,您可能希望使用:
- S3 - persistent storage
- S3 - 持久存储
- RDS - MySQL database
- RDS - MySQL数据库
- EC2 - Apache / Nginx, PHP front end
- EC2 - Apache / Nginx,PHP前端
You can then augment this with:
然后你可以通过以下方式增加:
- Cloudfront - localised delivery of your S3 content
- Cloudfront - S3内容的本地化交付
- Loadbalancer - ensure your EC2 instances are used optimally
- 负载均衡器 - 确保以最佳方式使用EC2实例
- Auto scaling - start / stop new instances
- 自动缩放 - 启动/停止新实例
- Route 53 - DNS
- Route 53 - DNS
- VPC - important as this offers security, single front ends for SSL certificates etc.
- VPC - 重要的是,它提供安全性,SSL证书的单个前端等。
Also, rather than start from scratch you can use AMI's from the marketplace: https://aws.amazon.com/marketplace/
此外,您可以从市场上使用AMI,而不是从头开始: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
查看AWS入门指南,详细介绍所有内容: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.
使用上面的内容,我建议将数据库移动到RDS并简单地在EC2实例上托管Apache。您甚至可能会发现这也具有成本效益,因为您可以在内存/ CPU要求较低的情况下使用小型实例。
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)
此外,随着时间的推移,您可以开始查看Elastic Beanstalk和Chef(甚至可能是本地开发盒的流浪者),Elastic Beanstalk(http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP_symfony2.html )
So, Symfony
所以,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.
我假设您已经创建了生产和开发环境:http://symfony.com/doc/current/cookbook/configuration/environments.html。这很重要,因为您可以在本地环境和生产环境之间更改配置。
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).
结帐https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/data-loader/stream.md,它使用https://github.com/KnpLabs/Gaufrette(或捆绑包: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/
似乎有一篇关于如何配置它的好文章: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)
使用上述环境,您可以将生产配置为读取/写入s3,而开发会写入/ tmp(例如)
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.
我将假设您使用Doctrine作为数据库连接,并遵循Symfony文档了解如何设置配置:http://symfony.com/doc/current/book/doctrine.html#配置-的数据库。
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.
您需要做的就是遵循环境逻辑并相应地设置db strings production / local。这应该是后台无缝的,不需要手动MySQL连接。
#2
3
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:
您可以使用Amazon s3存储桶来存储文件。看看https://github.com/KnpLabs/Gaufrette,它使您能够将文件存储在本地文件系统,Amazon s3文件系统或其他文件系统上,只需使用配置进行控制即可。用于在RDS上指定数据库详细信息。在parameters.yml中配置以下内容:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_user: root
database_password: password
#3
0
The problem is: Symfony expects a SYMFONY__
prefix in the environment variable name to be pipe it into the param container. This could be easily achieved by aliasing the environment variables in elastic beanstalk.
问题是:Symfony期望环境变量名中的SYMFONY__前缀将其输入到param容器中。这可以通过在弹性beanstalk中对环境变量进行别名来轻松实现。
My own config looks like follows:
我自己的配置如下所示:
SYMFONY__DATABASE_HOST: '$RDS_HOST'
SYMFONY__DATABASE_PORT: '$RDS_PORT'
SYMFONY__DATABASE_USER: '$RDS_USERNAME'
SYMFONY__DATABASE_PASSWORD: '$RDS_PASSWORD'
SYMFONY__DATABASE_NAME: '$RDS_DB_NAME'
#1
22
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:
虽然您可以使用AWS来提供独立服务器,但如果您希望支持多个实例,负载平衡等,那么您需要将事情分开。在最基本的级别,您可能希望使用:
- S3 - persistent storage
- S3 - 持久存储
- RDS - MySQL database
- RDS - MySQL数据库
- EC2 - Apache / Nginx, PHP front end
- EC2 - Apache / Nginx,PHP前端
You can then augment this with:
然后你可以通过以下方式增加:
- Cloudfront - localised delivery of your S3 content
- Cloudfront - S3内容的本地化交付
- Loadbalancer - ensure your EC2 instances are used optimally
- 负载均衡器 - 确保以最佳方式使用EC2实例
- Auto scaling - start / stop new instances
- 自动缩放 - 启动/停止新实例
- Route 53 - DNS
- Route 53 - DNS
- VPC - important as this offers security, single front ends for SSL certificates etc.
- VPC - 重要的是,它提供安全性,SSL证书的单个前端等。
Also, rather than start from scratch you can use AMI's from the marketplace: https://aws.amazon.com/marketplace/
此外,您可以从市场上使用AMI,而不是从头开始: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
查看AWS入门指南,详细介绍所有内容: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.
使用上面的内容,我建议将数据库移动到RDS并简单地在EC2实例上托管Apache。您甚至可能会发现这也具有成本效益,因为您可以在内存/ CPU要求较低的情况下使用小型实例。
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)
此外,随着时间的推移,您可以开始查看Elastic Beanstalk和Chef(甚至可能是本地开发盒的流浪者),Elastic Beanstalk(http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP_symfony2.html )
So, Symfony
所以,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.
我假设您已经创建了生产和开发环境:http://symfony.com/doc/current/cookbook/configuration/environments.html。这很重要,因为您可以在本地环境和生产环境之间更改配置。
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).
结帐https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/data-loader/stream.md,它使用https://github.com/KnpLabs/Gaufrette(或捆绑包: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/
似乎有一篇关于如何配置它的好文章: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)
使用上述环境,您可以将生产配置为读取/写入s3,而开发会写入/ tmp(例如)
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.
我将假设您使用Doctrine作为数据库连接,并遵循Symfony文档了解如何设置配置:http://symfony.com/doc/current/book/doctrine.html#配置-的数据库。
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.
您需要做的就是遵循环境逻辑并相应地设置db strings production / local。这应该是后台无缝的,不需要手动MySQL连接。
#2
3
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:
您可以使用Amazon s3存储桶来存储文件。看看https://github.com/KnpLabs/Gaufrette,它使您能够将文件存储在本地文件系统,Amazon s3文件系统或其他文件系统上,只需使用配置进行控制即可。用于在RDS上指定数据库详细信息。在parameters.yml中配置以下内容:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_user: root
database_password: password
#3
0
The problem is: Symfony expects a SYMFONY__
prefix in the environment variable name to be pipe it into the param container. This could be easily achieved by aliasing the environment variables in elastic beanstalk.
问题是:Symfony期望环境变量名中的SYMFONY__前缀将其输入到param容器中。这可以通过在弹性beanstalk中对环境变量进行别名来轻松实现。
My own config looks like follows:
我自己的配置如下所示:
SYMFONY__DATABASE_HOST: '$RDS_HOST'
SYMFONY__DATABASE_PORT: '$RDS_PORT'
SYMFONY__DATABASE_USER: '$RDS_USERNAME'
SYMFONY__DATABASE_PASSWORD: '$RDS_PASSWORD'
SYMFONY__DATABASE_NAME: '$RDS_DB_NAME'