Please not that I will not be covering data migration in this post. I will be covering that in just a few days. This tutorial will show you how to migrate only your application code to AppFog.
We know that a lot of PHP Fog users have checked out AppFog, and that some of you have even migrated apps to AppFog. But a lot of you haven’t had the chance yet.
We also know some current PHP Fog users might have certain concerns regarding PHP Fog-to-AppFog migration. Isn’t AppFog a lot different? Isn’t the deployment and management process a completely different animal?
We understand these concerns 100% and are here to assure you: there is actually a lot of overlap in how the two platforms work, and migrating between them can in most cases be accomplished quickly once you know some of the key differences.
For the sake of this demonstration, I’ll be migrating a super-duper simple PHP app (the code is on GitHub). As you can tell, it probably won’t be nominated for a Webby this year (!). It does, however, have just enough dynamic PHP-based functionality to allow us to ascertain whether or not our migration has worked.
So let’s go through the steps one by one.
Signing up for AppFog
First things first: score yourself a free AppFog account at console.appfog.com. It’s the same thing we’ve all done a million times: e-mail, password, and then e-mail verification. Once you have your account set up, you’ll get what everyone gets: the most generous free tier in the entire world of PaaS, with 2 GB of RAM, 10 service instances, a 50 GB data transfer limit, free custom domains, free access to AppFog support, and much more.
Installing the AppFog command line tool (CLI)
Now, you need to install Ruby and RubyGems. Following the instructions in these links should get you going quickly. If you’re on Mac OS X or on many Linux distributions, Ruby and RubyGems will already be installed. In a *nix environment, check if Ruby is installed by running
ruby -v and if RubyGems is installed by running
gem -v. If the response is blank or something like
command not found, then you’ll need to go through the install process appropriate to your OS.
Once you’ve got Ruby running, you will need to install the
af Ruby gem with a simple install command:
gem install af
This will enable you to use the AppFog command line tool to manage PHP app deployment. If you’re unfamiliar with the command line, don’t worry: using the CLI tool is dead simple, and even advanced users tend to use only a few commands, like
af update, and a few others.
Migrating an already existing PHP Fog app using the AppFog CLI
So let’s assume that you have an already existing PHP Fog app housed in the directory
~/desktop/my-php-app. Deploying that app on AppFog requires running just a few commands and responding to some prompts.
First, navigate to the root directory of your PHP app. I’m running Mac OS X and storing my app on the desktop, so my navigation will look like this:
I’m already signed up for AppFog, so I’m going to run
af login to get logged in to AppFog. I’ll then be prompted for my username and password. If I get
Sucessfully logged in as a response, then I’m all set.
AppFog is now ready to accept my application code. All I have to do at this point is run the
af push command, and AppFog will do the rest for me via a series of prompts.
Here is a basic rundown of that series of prompts:
- The name of the application. As in the console-based example above, I’m going to choose
af-plus-php-equals-winfor the name, which will produce the URL
af-plus-php-equals-win.ap01.aws.af.cm. AppFog supports custom domain names, but this will be the app’s URL to begin with. For now, it can be whatever you want it to be, provided that it isn’t being used already. So go nuts.
- The type of app. The
afgem will automatically detect that you’re deploying a PHP app, so just say “yes” when you get this prompt:
Detected a PHP Application, is this correct? [Yn].If it doesn’t automatically detect a PHP app, then it will prompt you which runtime your app is using, and you may select PHP from the list by number.
- Select an infrastructure. If you’ve gotten this far, the AppFog server will want to know on which infrastructure you want to deploy. Select one of the currently available options by number and hit Enter. At the moment, there are five options available: AWS US East, AWS EU West, AWS Asia SE, Rackspace AZ 1, and HP AZ 2. A PHP app that runs on any of those infras will run on all of them. The choice is 100% up to you. And there will be more infras on the way soon.
- URL for the app. If you’ve selected an available app name/URL, it will prompt you with this:
Application Deployed URL [php-app.aws.af.cm]:. Simply select yes by typing “y” and hitting enter.
- Allocate memory. You’ll be prompted to input your memory reservation. You’ll have the choice of 128 MB, 256 MB, 512 MB, 1 GB, or 2 GB. Manually type in the amount that would like to use and hit enter. 128 MB will appear in brackets because it’s the default. This will all depend on the size of your app. PHP apps tend to not be very memory-hungry, so select 128 MB to begin with and go from there.
- Allocate instances. If you’re not planning on getting crazy amounts of traffic directly out of the gate, then I’d recommend going with just one instance. This can always be changed later if you need to scale up.
Once you answer all of these prompts, it should upload your app, push it, stage it, and then start it. Just like that!!
What I like is that the CLI will automatically create a
manifest.yml file in the main directory. This file is a basic repository for the input that you enter concerning the number of instances you want to run, how much memory you would like to use, etc. Other sites that I’ve used for app deployment require you to produce your own YAML file. In most cases, this isn’t terribly difficult, but if you make a small error in syntax, that will mean that the deployment process is dead in the water until that’s cleared up. But having this done automatically means having one fewer thing that can go wrong.
Don’t have an existing PHP app yet? Try creating a new one in the AppFog console
Just like PHP Fog, AppFog enables you to create jumpstart apps in our console. The currently available jumpstarts include custom PHP, Drupal, and WordPress apps. There will be more PHP jumpstarts on the way soon, but please note that PHP apps from any PHP framework can currently be deployed to AppFog, including CakePHP, Facebook, ThinkUp, Laravel, and many others. Simply choose a custom PHP jumpstart in the console and update your application code after the jumpstart app has been deployed.
I won’t go into a full walkthrough of the AppFog console here, but it’s very intuitive and there are a number of resources already available for introducing you to the full breadth of the console’s functionality. Check out this video for a nice introduction, and this section of our docs for a brief introduction to choosing jumpstarts in the AppFog console.
PHP app up and ready to go on AppFog? Here’s how to manage it
Once you have a PHP app running on AppFog, you’ll need to update it from the command line. Fortunately, you only need to run a single command from your app’s root directory to do so:
af update <app-name>
You’ll remember from before that I named my custom PHP app
af-plus-php-equals-win, and so I simply run this command from my project’s directory (
~/desktop/my-php-app) and AppFog will take care of the rest for me.
If you chose to create your PHP app in the console, the
af update command essentially takes the “Hello World’ PHP app that resulted and replaces it with your own custom app. Remember that this is the way to do things if your PHP app was created in a framework outside of Drupal or WordPress (such as CakePHP or Facebook).
Lots more functionality where that came from
Naturally, there’s a lot more that you can do in both the console and the command line. This tutorial was simply meant to get your apps up and going on AppFog. For a more exhaustive introduction to the AppFog CLI tool, check out the documentation page for it or simply run
af help in the command line for a list of all of the
af gem-based commands that are available. I’ll also be giving a thorough rundown in a later tutorial.
In both the console and on the CLI, you’ll be able to bind and provision services (MySQL, just like with PHP Fog, except also a lot more, like MongoDB, PostgresQL, RabbitMQ, and Redis, all of which can now be used with PHP apps!), manage domain names, and a whole lot more.
That’s it for now. Like I said, more tutorials in the coming days for PHP Fog users switching to AppFog, in particular concerning data migration and more advanced features like provisioning and binding services, which is somewhat trickier than basic code migration. If you have any trouble, please reach out to support.appfog.com and they’ll get you all squared away.
In the meantime, happy migration!