Thursday, March 1, 2012

Get started with Zend Framework in the Amazon Cloud with BitNami

In this post, we will walk you step by step through how to start a project with Zend Framework in the Amazon Cloud using a BitNami LAMP Stack Amazon Machine Image (AMI).

To get started, you will need an Amazon acount. You can find how to create your account here. New Amazon users are eligible for a free tier which provides a free micro instance for a year. Once you log in to the AWS Console, go to the EC2 tab and launch a new Instance. You can locate the BitNami LAMP Stack image by searching in the Community AMIs tab for "lampstack-5.3.10", that is the latest version at the time of writing. If you want to run it using the free tier plan, you should run the 32bit or 64bit EBS AMI.

Launching BitNami LAMPStack from the AWS Console
Another option is to launch the image directly from the BitNami website. You can select your preferred region (United States, Europe, Asia or South America), the architecture (32 or 64 bits) and click on the appropriate link.

You can then set different parameters from the AWS Console: availability zone, ssh key, the image type (micro, small, medium) and the security group. Once the machine is started, access it by typing the public DNS name in a browser and you should see a welcome page for BitNami LAMPStack.

Now it is time to connect to the machine. You can download the private SSH key from your Amazon account. If you want to connect to the machine from Windows using the popular tool Putty, you will need to convert your private key to the .PPK format. Take a look at this tutorial if you are not sure how to perform this conversion.

On Linux or OS X, you can open a Terminal and run the following command:

$ ssh -i /path/to/your/private/key.pem bitnami@ec2-xx-xx-xx-amazonaws.com

You will see a welcome message similar to:
BitNami welcome message
All the required files for the Zend Framework are in the "/opt/bitnami" folder:

ctlscript.sh: It is the main script to start and stop the servers.
frameworks/zendframework: The Zend Framework files.
apache2: The Apache server files.
php: The PHP language files.
mysql: The MySQL database files.

One of the advantages of this structure is that it is common to all the BitNami stack types, including native installers and virtual machines. You can install the BitNami LAMP Stack on your own desktop machine, develop your application locally and then migrate the full directory directly to the cloud.

Creating a new Zend Framework project is as easy as type the following command:

$ zf create project your_project_name

You now need to create a new configuration file for Apache. You can edit the files online with a command line editor (nano, vim, emacs) but many people prefer to edit files with a graphical editor locally. Using an SFTP client like FileZilla, you can edit the files from your computer. If you need help, see our how-to for configuration instructions.

Create a folder called conf inside your project:

$ mdkir your_project_name/conf

And inside it create a new file zendframework.conf and paste the following lines:

Alias /zendframework "/path/to/your_project_name/public"

<Directory /path/to/your_project_name/public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Edit the Apache configuration file /opt/bitnami/apache2/conf/httpd.conf and add the following line at the end of the file:

Include "/path/to/your_project_name/conf/zendframework.conf"


Restart the Apache server and visit the Zend Framework welcome page at http://ec2-xx-xx-xx-amazonaws.com/zendframework

$ sudo /opt/bitnami/ctlscript.sh restart apache

Zend Framework welcome page

That's all! You can now create your Zend Framework application in the Amazon cloud. IF Zend Framework is not your thing, remember that BitNami  LAMPWAMP and MAMP Stacks bundle other framework like CakePHP, Symfony and CodeIgniter.

No comments:

Post a Comment