Everything about Web and Network Monitoring

Using AppFog with PHP

AppFog is the new baby in cloud computing town. With this said, it has been doing very well for quite a while, with its sleek UI, simple deploying tools and a super fast cloud infrastructure. So what is AppFog, as you might be already wondering? In a nutshell, AppFog is the best PaaS (Platform as a service) provider, allowing developers to develop and deploy their apps in no time.

 

It is similar to services like Pagoda Box and Heroku, but what makes AppFog better is the variety of programming languages it supports. In addition, AppFog is based off a cross cloud system, allowing you to use cloud servers across the globe. Without further ado, let’s look using AppFog with PHP, as it is the subject of this particular article.

 

Step 1: Get an Account on AppFog

As you might have already guessed, you will need an AppFog account to get things started. Unless you are already have one, you can create a new AppFog account by clicking this link here. The signup process is fairly self explanatory so hopefully you it won’t take you long.

 

Step 2: Get Motivated

Ok, you have an AppFog account. Welcome to AppFog. To give you a bit more motivation as to why AppFog is better, here are a few pointers:


  1. Space: You get 2GB of RAM and the ability to run 10 services.

  2. Easy Migration to any other Cloud Foundry App.

  3. AppFog supports pretty much every web technology. Java, .NET, Node, Ruby, Python, PHP, Mongo, MySQL, Redis, AWS, Rackspace, Azure and you name it!

  4. AppFog has a great free support and you can expect reply in 4 hours.

  5. And lastly, easy scalability, just like you’d except with any other cloud platform.

Step 3: Create an App

It’s time to create an app on AppFog. Click on “New App” while you are in your Console. Alternatively, click here. Once there, click on “PHP” tab. That tells AppFog that you are looking to work with PHP. Next, scroll down and choose an Infrastructure. It is best to choose the one which is near you. Finally, enter a name for your app, like sample or sample-app. Once done, click the blue button that says “Create App”.

Step 4: Download the Source Code

Once you have successfully created your PHP app in Step 3, you should have a console window showing you a variety of options. However, exploring each of the options on the console is beyond the scope of this article.

As shown in the image below, you must download the source code on your computer, so that you can develop your PHP application locally before pushing it to the AppFog platform.

Running a XAMPP server, you can place the source code folder for further development in the htdocs folder. Here’s how it’s done on Macintosh and Windows:

Windows: C: /XAMPP/htdocs/copy_it_here

Macintosh: ~/Applications/XAMPP/htdocs/copy_it_here

Now, by default the folder comes in packaged with an index.php file that says “Hello World”. Of course you’d want your app to have more than that. Let’s do some quick HTML to demonstrate. If you wish, just copy this piece of HTML/PHP combo code into the index.php sample file.

<html><title> Sample App </title> <body>
<h1> This is a Sample Application </h1>
<h2> Running on AppFog </h2>
<h3> Using PHP </h3>
<code><?php echo "Hello world!"; ?></code>
</body></html>

Step 5: Pushing your PHP App to AppFog

Before you do anything, you need to ensure you have Ruby on your Mac or Windows. Macs usually come pre-installed with Ruby, but what about Windows. If you are on Windows, you’d need to download this.


The Ruby Installer will enable you to work with Ruby on your Windows. Once done, go into your Programs and Start Command Prompt with Ruby. On Mac OSX, this will be your Terminal. Now, the next few steps are identical on both, Mac and Windows, so follow them carefully.


Now, using Command line, go into your sample app folder and when inside it do this:


gem install af -This will install the AppFog Ruby Gem.

af login - Sign in with your AppFog credentials.

af update sample-app - This will push your app online. You sir are live! Kudos.



To check, go to your console by clicking here. On the right hand side, you can see the link that will allow you to access the app online. Here’s how it shows for the demonstration app.


Congratulations for creating your first PHP app on AppFog.


Post Tagged with

About Ali Gajani

I’m a science geek, aspiring blogger, thinker, entrepreneur and freelancer. I live in Sheffield, UK, have three amazing pets named iPad, iPhone and iMac and I love life. You can find me on mrgeek.me to know more about myself!