Deploying custom PHP apps on AppFog
We like jumpstarts on AppFog. We like enabling people to almost instantly deploy a basic “Hello world” app that can act as a placeholder for a future, more sophisticated app. We currently offer a variety of jumpstarts in our console, including four for PHP: a jumpstart for custom PHP apps, Drupal apps, WordPress apps, and for an in-browser phpMyAdmin console.
“But the tool I want to use isn’t a Jumpstart!!!”
There has been some confusion about jumpstarts that we’d like to clear up.
Jumpstarts are just helpers that can save time in many instances. You don’t need to use jumpstarts to use AppFog, and you don’t need them to deploy PHP apps.
Jumpstarts are just helpers to get you up and going.
“So I can use any tool or framework I want?”
AppFog enables you to deploy apps from a vast variety of PHP frameworks, the majority of which do not currently have jumpstarts in the console. And so if you don’t see a jumpstart for the framework of your choice, be it Zend or CakePHP or Yii or ThinkUp or something else, don’t worry: you can still use AppFog!
Today, I’d like to go over how to deploy PHP apps on AppFog that are not covered by jumpstarts. I won’t be covering every PHP framework, of course, because any PHP dev knows that that would be an almost endless tutorial. Instead, I’ll deploy a CodeIgniter app as an example and walk through the steps.
Please note: Deploying to AppFog using your framework of choice might proceed in a very similar fashion or it might demand a quite different set of steps. While some frameworks work “out of the box”, some have dependencies that make them challenging or potentially a non-starter. So make sure to reach out to our support team at firstname.lastname@example.org if you’re having trouble.
Getting started with CodeIgniter and the AppFog console
First things first, download CodeIgniter. Simply go to the CodeIgniter main page and click “Download.” This will create a folder on your machine that is set up to act as an already-functioning app (think of it as a jumpstart app itself). If you use MAMP, WampServer, or another local PHP server, you can use that downloaded folder straight out of the box, so to speak. If you navigate to the main page on your
localhost, you’ll see a main page stub similar to this:
To get this stub app running on AppFog, you’ll need to create a custom PHP jumpstart app. Let’s do that really quickly in the AppFog console.
Select the PHP jumpstart, select the infrastructure you want to deploy to, select a name for your app, then click “Create.” For more comprehensive instructions on using the AppFog console, check out our docs.
If you navigate to the URL associated with the jumpstart app, you’ll see a simple “Hello world!” message. At this point, you’ll need to use the command line. What you’ll be doing is essentially updating your already-created PHP jumpstart app and replacing it with your CodeIgniter app. If you have Ruby and the af gem installed and are signed up for an AppFog account, simply run the following in the command line:
af update <my-codeigniter-app-name>
If you see the line
Starting Application ‘<my-codeigniter-app-name>’: OK, then that means that the app has been successfully updated. If you navigate to the app’s URL, you will now see the “Welcome to CodeIgniter!” page that you saw when you ran it on your local server.
Now, I’m guessing that you’ll probably want to make significant changes to your CodeIgniter app. The “Welcome” page that is the default
index.php file is nice enough, but not terribly exciting and does nothing to take advantage of what CodeIgniter has to offer. When you make changes down the road and want those changes to be reflected in your deployed app, simply run
af update from the app’s root directory or
af update <my-codeigniter-app-name> from anywhere else on your local machine.
And that’s it. Deploying an app created in any PHP framework will typically involve an analogous set of steps. But there are some things to be aware of if you’re a PHP developer wanting to use PHP frameworks on AppFog, which I’ll go over in the next section.
Frameworks beyond CodeIgniter
In this tutorial, I used CodeIgniter simply as an example. You can deploy apps from lots and lots of PHP frameworks on AppFog. At the moment, we’re working hard to bring AppFog’s set of capabilities up to speed with that of PHP Fog by providing, for example, persistent file storage, writable directories, and other features. But because of AppFog’s structure, some frameworks function more seamlessly than others. Here is a list of frameworks that are AppFog-ready, the ones that are more “experimental,” and the ones that you probably want to hold off on for now.
Certainly possible, but pretty experimental right now
Not officially supported
Over time, this list will change, and we’ll keep you posted when it does.
Other things to be aware of
We sent out a FAQ a few weeks ago detailing some of the crucial differences between AppFog and PHP Fog. I won’t go over all of those points here, and I’d suggest giving the FAQ a close read. But I would like to go over some of the architectural differences between PHP Fog and AppFog here.
Instances vs. memory distinction
One important thing to remember when using PHP on AppFog versus PHP Fog is that scalability comes in two very different forms on the two platforms. On PHP Fog, scaling up and down meant adding and removing dedicated servers. With AppFog, on the other hand, scaling up and down means adding and removing instances of an app. The difference is that the number of instances doesn’t have any necessary correspondence to the actual number of physical machines being used.
PHP Fog had direct support for traditional CRON jobs. At the moment, AppFog does not. Fortunately, you can use standalone apps to manage task scheduling. Check out this tutorial on how to do so. You can do task scheduling in any of the languages that AppFog supports, and there are a variety of modules available from node-cron for Node.js and the whenever Ruby gem, amongst many others.
Not Git based
Unlike PHP Fog, AppFog does not directly support Git deployment because we want to give users the ability to use a whole variety of version control systems, from Git to Mercurial to Subversion and beyond, as well as the ability to separate version control from the application deployment and management process, which are two things that don’t always neatly coincide.
To that end, we created the af Ruby gem, based on Cloud Foundry’s vmc gem, to deploy and manage apps. This tool is incredibly easy to use (here are the docs), and we’re continuously adding new functionality to it. You’re more than welcome to use Git, and we are enormous Git fans. But you will need to use the
af tool to use AppFog in the command line.
No persistent file storage
Unlike PHP Fog, AppFog does not offer persistent file storage at this point. In the meantime, we strongly recommend using Amazon’s Simple Storage Service (S3). We put together this tutorial to get you up and running in PHP.