On Monday, I posted a tutorial on how to migrate your application code from PHP Fog to AppFog. But as all of you know, migrating code is only one part of the process of migrating an application across platforms. Migrating your data is an equally essential part of that process. In this tutorial, I will cover how to use phpMyAdmin to pull your data out of MySQL on PHP Fog and then upload it to AppFog.
This process is a bit more tricky than migrating your application code, so make sure and follow closely and reach out to us at support.appfog.com if you have any issues. In the coming days, I’ll post part 2 of this tutorial, which will go through elements of this process in more depth and cover some other important aspects of the broader PHP Fog-to-AppFog migration process.
Accessing phpMyAdmin in the PHP Fog console
First things first, navigate to the console for your PHP Fog app. There, you’ll see a button for launching phpMyAdmin:
When you click on that button, you’ll be taken to a page that you should be quite familiar with if you’ve used phpMyAdmin in the past. Near the top of the page, click on the Export button in the toolbar. That will take you to a page that looks like this:
In this tutorial, we’ll through a “Quick” MySQL export. Feel free, however, to customize your export if the need arises. The “Custom” option allows you, for example, to save the output in a variety of file formats (we strongly recommend SQL), choose what kinds of
USE, and other commands you want contained in the file, and so on. Be aware, however, that the Quick option will in most cases provide the quickest database migration route.
When you click Go, a new
<database-name>.sql file will be saved in your default download directory on your local drive. If you see this
.sql file in that directory, then that means that the MySQL database that was previously powering your PHP Fog application is now on your local machine and ready to go.
Your .sql file is ready to go. Time to upload to download the phpMyAdmin jumpstart
Now that your MySQL database has been pulled down to your local machine, it’s time to use phpMyAdmin to push it up to AppFog. Fortunately, there is a phpMyAdmin jumpstart for AppFog that enables you to accomplish this very quickly.
Using this jumpstart involves the following steps:
1. Clone the Git repository for the jumpstart:
$ git clone https://github.com/appfog/af-php-myadmin.git
2. Navigate to the
af-php-myadmin directory you just created with the Git
$ cd af-php-myadmin
3. Create your phpMyAdmin credentials:
$ htpasswd .htpasswd <username>
This username can be anything you’d like it to be. Make sure and remember it, however, as you’ll need it to access phpMyAdmin on AppFog in the future (though you may change it later if you’d like). Once you’ve entered a username and hit Enter, you’ll be prompted for a password and then to confirm the password. Once that’s done, you’re ready to get phpMyAdmin up and running on AppFog.
Setting up phpMyAdmin on AppFog
All the necessary files for phpMyAdmin are now on your local machine, so let’s get the app up and running. From the
af-php-myadmin directory, run the following command:
$ af push
In order for this command to work, you will need to have an AppFog account and have both Ruby and the
af Ruby gem installed. For more on that, check the AppFog docs. If you do have both installed, and you have an AppFog account, and you’re logged in (if not, run
af login and enter your credentials), then the
af push command will bring up the following set of prompts:
Would you like to deploy from the current directory? [Yn]:
- Type in “Y” and hit Enter
Detected a PHP application, is this correct? [Yn]:
- Again, type in “Y” and hit Enter
- Then, you’ll be prompted to select an infrastructure. The options are AWS US East (Virginia), AWS EU West (Ireland), AWS Asia SE (Singapore), Rackspace AZ 1 (Dallas), and HP AZ 2 (Las Vegas). Select the one you wish to deploy to by number and hit Enter.
- At that point, you’ll be given the URL for your phpMyAdmin application. I have chosen
lucperkins-pma as my app name and AWS US East as my infrastructure, so the resulting URL is
lucperkins-pma.aws.af.cm. Copy this URL and hit Enter to confirm.
Memory reservation (128M, 256M, 512M, 1G, 2G):
- For most databases, a 128 MB memory reservation should work just fine. If it doesn’t, you can always retroactively increase the memory reservation by running
af mem <appname> [memsize] to change the memory allocation.
How many instances? :
- One instance is the default and should be sufficient for phpMyAdmin, so simply click Enter on this prompt.
Bind existing services to ‘<appname>’? [yN]:
- If you have not yet set up a MySQL service on AppFog, type in “n” and hit Enter. If you have indeed set up a MySQL service, type in “y” and hit
Enter, and you will be prompted to select the MySQL service that you want to use.
Create services to bind to ‘<addname>’? [yN]:
- You will only be prompted for this if you do not currently have a MySQL database on AppFog to bind to phpMyAdmin. If you reach this prompt, type in “y” and hit Enter.
- At this point, you’ll need to choose a service type from the five available options: MongoDB, MySQL, PostgresQL, RabbitMQ, and Redis. You will need to select number 2, MySQL and hit Enter.
Specify the name of the service [service-name]:
- Here, you can either accept the randomly generated service name (which should look something like
mysql-1234 or enter your own name. It’s up to you.
Create another? [yN]:
- No need to create another service. Type in “n” and hit Enter.
Would you like to save this configuration? [yN]:
- Yup! Select yes and hit Enter.
At this point, you should see the following output:
Manifest written to manifest.yml.
Creating application: …
It should take only a few seconds to create and deploy the application. Once you get a string of green
OKs, enter the URL generated for your app, paste it into your browser, enter the credentials you just selected, and voilà. You should see a phpMyAdmin interface that should look something like this:
You’re almost there!
phpMyAdmin is now running on AppFog. Time to upload our DB!
The beauty of phpMyAdmin is that the UI is super intuitive, and something we’re all quite familiar with. That’s why we chose it as the preferred option for migrating databases across our two platforms.
First, however, there is one important change you need to make to your
.sql file. Open that up file up in your favorite (preferably non line-wrapping) text editor.
Now, you need to replace the database name currently in your
.sql file with the database name provided in your phpMyAdmin app. This is a little bit tricky, but it involves just a few basic steps. In your phpMyAdmin instance running in your browser, click on the Databases tab in the top toolbar, and you should see something like this:
That gibberish-looking database name is exactly the one we’re looking for! Copy it, and then go to the
.sql file already open in your preferred text editor. First, delete or comment out the line that begins
CREATE DATABASE `<database-name>` but make sure and leave the line that begins
Then, anywhere in the file that you see the database’s current name (mine is
lucperkins2_phpfogapp_com), replace it with the name from phpMyAdmin. For me this meant changing this
Now, go into phpMyAdmin running in the browser, and click Import in the top toolbar. This will take you to a page where you can accomplish your
.sql file import. That page should look like this:
To upload your
.sql file, all you have to do is click on the Choose File button, find your database file (which may or may not still be in your default download folder), select it, and then click Go at the bottom.
Once you’ve done that, phpMyAdmin will take care of all the rest. It will create and populate the necessary tables. If you look at the left side of the main phpMyAdmin page, you should see your tables listed there. My database had only two tables, named
User Table respectively:
At this point, my database is up and running, manageable via phpMyAdmin in the browser (as well as through other means, such as
af tunnel, which will be covered in a later tutorial), and ready to be used in conjunction with my PHP apps running on AppFog (as well as Node, Python, Ruby, Java, Scala, Clojure, and other apps).
If you experience any troubles with migration, reach out to our support team and they’ll get you squared away as soon as possible. We know that this is can sometimes be a tricky process, and we’re happy to help any way we can!
Tune in for another database migration tutorial coming very soon which will cover command line migration options, database tunneling on AppFog, and other important elements of running PHP apps on our polyglot, multi-infra platform.