Wednesday, December 14, 2011

Get started with CodeIgniter in the Amazon Cloud


We recently released BitNami LAMP WAMP and MAMP Stacks with CodeIgniter 2, a popular development framework (the *AMP Stacks also bundle other frameworks like ZendFramework, Symfony and CakePHP). In this post, we will walk you step by step through how to start a project with CodeIgniter in the Amazon Cloud using a BitNami LAMP Stack AMI

First, you will need an Amazon acount to access the AWS Console. You can find how to create your account here (note that they have a free tier which provides you with a free micro instance for a year). Once you login 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.8-2", which is the latest version at the time of this writing.



Another option is to launch directly from the BitNami website. You can select your preferred region (United States, Europe or Asia) and the architecture (32 or 64 bits) and click on the appropriate link. Then, you can 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. You should see something similar to the screenshot below.



The next step involves connecting 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:



All the required files are in the "/opt/bitnami" folder:

ctlscript.sh: It is the main script to start/stop the servers.
frameworks/codeigniter: The CodeIgniter framework files.
apache2: The Apache server files.
php: The PHP language files.
mysql: The MySQL database files.

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.



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

Include "/opt/bitnami/frameworks/codeigniter/conf/codeigniter.conf"

Restart the Apache server and visit the CodeIgniter welcome page at http://ec2-xx-xx-xx-amazonaws.com/codeigniter

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



Success! You can now access the CodeIgniter user guide and create your own application in the Amazon cloud using this framework.