Showing posts with label laravel. Show all posts
Showing posts with label laravel. Show all posts

Sunday, June 19, 2016

Introducing Bitnami Development Containers

Folks who have known me for a while, know that I love to make things easy for developers. From my days as a usability engineer on the Visual Studio team, to my pet projects, to my tutorials and samples, making programming easy and fun has been a theme of my work since 1998.

Now at Bitnami, I am happy to be working with a team who is as excited about this as I am. We have started a project that takes advantage of Docker to make developing with whatever framework you choose easy and fun. We call this project “Bitnami Development Containers.” This project is an extension of the development process that we have created for our own internal development. It only made sense to share our experience with developers everywhere.

We are in the beginning phase of the public part this project, and we are practicing the “release early and often” strategy, so let’s see what people think.

The basic idea behind the project is that if you have Docker enabled on your development machine, trying a framework should be as simple as what I affectionately call, “curling up”. That means that all you need to do is curl (download) a docker-compose file, and then run it with the docker-compose up command. After those two steps, and only those two steps, you can see your app running and start coding. It is that easy.

To accomplish this, we had to do a couple of things:
  1. First, we created custom containers that are meant specifically for developing with the frameworks of interest. These containers have an entry point that is designed to get developers going with zero configuration. We take care of all the configuration and any code generation necessary to get started.
  2. We include any necessary infrastructure and orchestrate them together using a simple docker-compose file. That means that if your framework of choice requires a database, maybe a specific database configured in a specific way, you don’t have to worry. We took care of all the work to set it up that way. You can just start coding.
So, for any framework that we support, with a development container, for example, if I wanted to write some good old Ruby on Rails code, I would just do this:

$ mkdir myrailsapp
$ cd myrailsapp
$ curl -L "https://raw.githubusercontent.com/bitnami/bitnami-docker-rails/master/docker-compose.yml" > docker-compose.yml
$ docker-compose up

Then open my browser, go to my docker-machine’s ip address at port 3000. And there’s the Rails welcome page. 

The exact same process works for Express:

$ mkdir express
$ cd express
$ curl -L "https://raw.githubusercontent.com/bitnami/bitnami-docker-express/master/docker-compose.yml" > docker-compose.yml
$ docker-compose up

Then open my browser, go to my docker-machine’s ip address at port 3000. And there’s the Express welcome page. It’s always the same simple steps.

One important thing to note is that the containers are designed to work as immutable infrastructure. By that, I mean, none of the code that is generated or that you write is on the container. Rather, it is also mounted in a volume. That is important because it means that the containers support easy reproducibility. So, if you change some code, you can check in that code, and someone else can check it out, and docker-compose up just works with the existing code.

Ok, let’s just try it. I heard about Laravel. My team says it's pretty cool, but I never really knew what it was. So, I am going to using Bitnami’s Development Container to quickly get started with it.

First thing, I will create a directory for the application that I will write. Then I will download the docker-compose file into that dir. Again, the same simple steps, “curl up.”

$ mkdir laravel
$ cd laravel
$ curl -L "https://raw.githubusercontent.com/bitnami/bitnami-docker-laravel/master/docker-compose.yml" > docker-compose.yml



That went fast, so let’s take a look:

$ cat docker-compose.yml



Ok, that is a nice and simple file. I can see that I am going to get a copy of MariaDB along with it. That’s handy, since as far as I can tell, Laravel and MariaDB go together like peanut butter and jelly. Note also that the port is already mapped for me.

Finally, note that it mounts a volume called “./app”. This is very important and interesting. What this means is that the application code that is generated and that I will modify is NOT in the container, but rather right on my desktop. This is how we achieve the immutability I mentioned above. This way, besides being easy to manage with source control, it is also trivially easy to edit with my desktop editor.

So, I curled, now I up. Of course, make sure that Docker is running before you do this:

$ docker-compose up




The first time I run this, Docker will download the images first. Then it will start the containers.



Looks like the container is started. Let’s check out the app.

First, I’ll check the ip address of my Docker VM:

$ docker-machine ip

Now that I have that, I can navigate to port 3000. Port 3000 is a typical port for development web servers to run on. I could also tell I needed to port 3000 from the docker-compose file.




It works! Let’s pause for a moment and consider how cool this is. In a matter of minutes I went from having an empty Docker environment to having a running Laravel 5 app. And I’ve never used Laravel before.

Of course, the first thing I want to do is to change the default to prove to myself that I have some control over the content.

Because this is my first experience with Laravel and I know almost nothing about it, I will have to poke around a bit. I’ll just guess that the string displayed in the default web page will help me out, so I will start with a recursive grep.

$ grep "Laravel 5" -R ./



That “welcome.blade.php” file looks like a promising start for making my first change. Keep in mind, I have never even written PHP code, much less Lavarel code. But, I love to learn by doing, so I am just going to dive in with my editor and see if I can make a change.




And …




Yup! It’s that easy. Within minutes, I have made a change!

Let’s take another look at my Mac’s directory:



As I mentioned before, you can see that the application code is on my development machine, NOT in the container. Furthermore, the docker-compose.yml file that sets up the development environment is in the same directory. That means I can easily commit this directory and share it. Anyone could check it out from source control, and run $ docker-compose up, and end up with the exact same environment. So, a team of developers could easily use the Bitnami Development Containers to collaborate on projects, and easily stay in sync with both the development environment and the code.

Today we have 3 development frameworks ready. Rails, Express, and Laravel, with more on the way. Please try them out and give us feedback. And please let us know what other frameworks you think we should do next! You can reach us at containers@bitnami.com.

- Rick Spencer, Bitnami VP of Engineering

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.