Friday, October 19, 2012

Get started with Laravel in the Amazon Cloud



We recently released BitNami LAMP WAMP and MAMP Stacks with Laravel 3.2.10, a popular development framework (the *AMP Stacks also bundle other frameworks like ZendFramework, CodeIgniter, Symfony or CakePHP). According to its website, Laravel is "A clean and classy framework for PHP web development. Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax.". In this post, we will walk you step by step through how to start a project with Laravel in the Amazon Cloud using a BitNami LAMP Stack AMI.


First, you will need an Amazon account to access the Amazon Web Services (AWS) Console. Instructions on how to create your account can be found here (note that Amazon offers 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.17-1", which is the latest version at the time of this writing.


Community AMIs in AWS console


Another option is to launch your AMI directly from the BitNami website (click on the button for either the LAMP or LAPP Stack towards the bottom of the page). You can select your preferred region (United States, Europe or Asia) from the drop down menu 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.



LAMP welcome page

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:

BitNami welcome message


All of the required files for the Laravel framework are in the "/opt/bitnami" folder:

ctlscript.sh: It is the main script to start and stop the servers.
frameworks/laravel: The Laravel 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 you can install the BitNami LAMP Stack on your desktop machine using either the BitNami installers for virtual appliances and develop your application locally, then migrate the full directory directly to the cloud when you are ready to put it into production.

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.

A simple way to start learning Laravel is via the Quick Tour that you can access via web. To enable it, you should uncomment the following line that you can find in the Apache configuration file /opt/bitnami/apache2/conf/httpd.conf:

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

and restart the Apache server:

$ ./ctlscript.sh restart apache

Laravel framework welcome page

That's all! You can configure the database settings in the "application/config/database.php" file. You can find more info about the Laravel configuration here.