Updated 2012-05-25: As of March 2012, AWS Elastic Beanstalk now has built-in support for PHP applications. For most people this eliminates the need for the implementation described in this article. However, the implementation explained below does have additional benefits for some users in providing a bridge between PHP and Java with Quercus.
The latest service offering from Amazon Web Services is AWS Elastic Beanstalk, allowing companies to deploy applications to Amazon’s cloud and let Amazon handle deployment and scaling of infrastructure automatically.
You simply upload your application, and Elastic Beanstalk automatically handles the deployment details of capacity provisioning, load balancing, auto-scaling, and application health monitoring.
While Amazon claims they’re working on other platforms, initially Beanstalk only supports Java applications deployed in the Caucho, we can run PHP using AWS Elastic Beanstalk. All it takes is setting up a simple <a href=”http://maven.apache.org/) project.
The first step is to setup the Caucho Maven repository and our dependencies in our POM:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
For this demo, I used the web.xml and PHP files from Caucho’s Quercus download and added a phpinfo.php page to show phpinfo() output. Here’s what our Maven webapp directory structure looks like:
Running mvn package produces a war file that can be deployed to AWS Elastic Beanstalk without any further modifications. After waiting a few minutes for the EC2 instance to start up, here’s our phpinfo.php file running on AWS:
That’s it… we have PHP running on AWS Elastic Beanstalk. It could not have been easier. Chances are Amazon will add PHP support down the road but until then you can run your own PHP applications using Quercus.
The full project code can be downloaded on GitHub at https://github.com/clstokes/aws-elastic-beanstalk-php.