PHP remains one of the most popular Web development languages. Modern application frameworks for PHP have sophisticated features. Many of them bootstrap and manage dependencies via Composer and contain RDBMS-backed object model frameworks. Applications developed on top of these frameworks are ideal for deployment to CenturyLink AppFog, which is a Platform-as-a-Service (PaaS) backed by Cloud Foundry. In this tutorial, we cover the CodeIgniter framework.

Tools Used

AppFog is our PaaS offering based on Cloud Foundry. It allows you to easily host cloud-native applications without worrying about provisioning and maintaining servers and separate services. AppFog applications deploy quickly and scale automatically while having access to the full range of CenturyLink Cloud products.

CenturyLink MySQL is a cloud-hosted, managed relational database solution. It is backed by 100% flash storage, and automatically scales to handle even the most demanding workloads.

Getting Started with AppFog

Before you can deploy anything to AppFog, you need to sign up for a CenturyLink Cloud account and enable AppFog. If you don't have a CenturyLink Cloud account, migrate to the CenturyLink Cloud Platform with free onboarding assistance and receive a matching spend credit. The credit is based on your initial commitment period of platform use.

For a good understanding of AppFog, we recommend reading the Getting Started Guide. The following steps will get you up and running quickly.

Enable AppFog

First, enable AppFog in the CenturyLink Cloud Control Portal.

  1. Go to the Control Panel and log in.
  2. Select AppFog from the pull-down menu. Control Portal
  3. Select a Region to host your application. Host Region

Log in to AppFog using the Cloud Foundry Tools

Once AppFog is set up in your CenturyLink Cloud account, you need to login to AppFog using the Cloud Foundry CLI. The Control Panel gives you an exact command from the Overview tab.

  1. Find the cf login command on your AppFog control panel. It will look similar to the following:

      cf login -a -o C007 -u your.username


  2. Run the command in your project directory.

  3. Enter your CenturyLink Cloud password when prompted. Password
  4. Select the Dev application space. Dev App

    Note: To learn more about logging into AppFog using the Cloud Foundry CLI, read this Knowledge Base article.

Deploying a CodeIgniter Application

CodeIgniter is a PHP web framework designed for rapid development and deployment. Like Laravel and Zend Framework 2, it uses a Model-View-Controller development pattern. The CodeIgniter platform has a small footprint and provides a simple, elegant toolkit for web developers. In this tutorial, we follow the tutorial found in the online User Guide for CodeIgniter 3.x.

Downloading and Preparing

To get started, visit the CodeIgniter download page and download the current version. We used version 3.0.6 for the tutorial. Unpack the downloaded package, which creates a new project working directory. In a Linux shell, the commands looks like this:

    $ unzip ~/Downloads/
    $ cd CodeIgniter-3.0.6/

Configure CodeIgniter for AppFog

AppFog uses buildpacks to install and deploy services which run and support your application. A buildpack is a package containing runtime support for a specific type of application. For instance, the PHP buildpack we use in the tutorial includes a specific version of PHP, a web server, and several support utilities. The PHP buildpack works closely with Composer to install project dependencies, which integrates conveniently with the PHP frameworks we look at in this tutorial.

Configuration for an AppFog project happens inside the project's working directory. Your project working directory is the CodeIgniter-3.0.6 directory created in the previous section.

Creating a Project Manifest

In your project working directory, create a file manifest.yaml with a text editor. Edit the file to look like this:

     - name: <your-app-name>
       memory: 512M
       instances: 1

Replace <your-app-name> with a project or application name. The name can’t contain any spaces. Note that because AppFog uses a global project namespace, this needs to be unique across AppFog.

Configuring the PHP Buildpack

The PHP buildpack configuration is kept in a subdirectory of your project directory. This configuration allows us to specify PHP versions and configure different subsystems and services, such as Composer and Apache HTTPD. To configure the buildpack for your project, follow these instructions:

  1. Inside your project working directory, create a .bp-config directory:

        $ mkdir .bp-config
  2. With a text editor, create and edit .bp-config/options.json to look like this:

          "PHP_VERSION": "PHP_55_LATEST",
          "COMPOSER_VENDOR_DIR": "vendor",
          "PHP_EXTENSIONS": [ "bz2", "zlib", "openssl", "curl", "mcrypt", "mbstring", "pdo", "pdo_mysql" ]
  3. From your project working directory, run the following command:

        $ mkdir -p .bp-config/httpd/extra
  4. With a text editor, create and edit .bp-config/httpd/extra/httpd-modules.conf to look like this:

       LoadModule authz_core_module modules/
       LoadModule authz_host_module modules/
       LoadModule log_config_module modules/
       LoadModule env_module modules/
       LoadModule setenvif_module modules/
       LoadModule dir_module modules/
       LoadModule mime_module modules/
       LoadModule reqtimeout_module modules/
       LoadModule unixd_module modules/
       LoadModule mpm_event_module modules/
       LoadModule proxy_module modules/
       LoadModule proxy_fcgi_module modules/
       LoadModule remoteip_module modules/
       # Needed for PHP application framework
       LoadModule rewrite_module modules/
       LoadModule access_compat_module modules/

Configure the Cloud Foundry CLI Tool

Since all application dependencies are handled by Composer, we can configure the Cloud Foundry CLI tool to exclude those from upload commands. This can save time and resources by significantly reducing the number of files uploaded by the tool. Configure the CLI tool by following these steps:

  1. In your project working directory, create and edit .cfignore to look like this:

  2. If your text editor uses different filenames for backups, temporary files, or lock files, add those patterns to the .cfignore file.

  3. If your application uses temporary files, installation-specific configuration files, or other files that don't need to be uploaded to AppFog, add those filenames or patterns to the .cfignore file.

Deploy to AppFog

It's now time to deploy your CodeIgniter application to AppFog without running it. This gives us the necessary information to finish configuring your application.

  1. Run the following commands:

       $ composer install
       $ cf push --random-route --no-start
  2. If successful, you should see output similar to this: CodeIgniter Deploy

  3. Look for the line that starts with Binding and record the hostname. This is circled in the example screenshot.
  4. Open application/config/config.php with a text editor.
  5. Look for the line that begins $config['base_url'] and edit it to look like the following example. Replace <hostname> with the hostname you recorded in Step 3.
       $config['base_url'] = 'http://<hostname>/';

Add a CenturyLink MySQL Database

The next step is to add a CenturyLink MySQL database to your AppFog project.

  1. Provision a MySQL instance and attach it to your application using the following commands:

       $ cf create-service ctl_mysql micro <your-database-name>
       $ cf bind-service <your-app-name> <your-database-name>
  2. Replace <your-database-name> and <your-app-name> with the name of your AppFog application and a database name.

  3. Find your MySQL configuration and authentication information using the cf env command.

       $ cf env <your-app-name>
        "VCAP_SERVICES": {
         "ctl_mysql": [
           "credentials": {
            "certificate": "-----BEGIN CERTIFICATE-----{...}-----END CERTIFICATE-----",
            "dbname": "{dbname}",
            "hostname": "{hostname}",
            "password": "{password}",
            "port": {port},
            "username": "{username}"
           "label": "ctl_mysql",
           "name": "<your-database-name>",
           "plan": "micro",
           "tags": []
  4. Record the dbname, hostname, password, port, and username for use in configuring your CodeIgniter application.

  5. Open application/config/database.php with a text editor.
  6. Find the section that begins with $db['default'] and edit it to look like this:

       $db['default'] = array(
               'dsn'   => '',
               'hostname' => '{hostname}',
               'port'     => '{port}',
               'username' => '{username}',
               'password' => '{password}',
               'database' => '{dbname}',
               'dbdriver' => 'mysqli',
               'dbprefix' => '',
               'pconnect' => FALSE,
               'db_debug' => (ENVIRONMENT !== 'production'),
               'cache_on' => FALSE,
               'cachedir' => '',
               'char_set' => 'utf8',
               'dbcollat' => 'utf8_general_ci',
               'swap_pre' => '',
               'encrypt' => FALSE,
               'compress' => FALSE,
               'stricton' => FALSE,
               'failover' => array(),
               'save_queries' => TRUE
  7. Replace "{hostname}", "{port}", "{username}", "{password}", and "{dbname}" with the values you saved in Step 4.

For more information on using CenturyLink MySQL with AppFog applications, read this Knowledge Base article. For more information on configuring database connections for CodeIgniter, see the CodeIgniter User Manual.

Deploy and Run Your Application

Now, it's time to deploy your application to AppFog. Run the following command:

       $ cf push

Continue Following the Tutorial

You're now ready to follow the rest of the CodeIgniter tutorial, starting with the Static Pages section. When you are ready to deploy and test your work, run the cf push command from the "Deploying and Running Your Application" section.

For More Information

Be sure to check out the CenturyLink Cloud blog and our Knowledge Base for additional information and helpful tutorials.

Other Framework Resources

We have tutorials available for other popular frameworks. You might want to check them out as well.

What's Next?

This brief tutorial provides a thorough outline of what's needed to get an application written for a PHP framework to run on CenturyLink AppFog. Expanding on these tutorials, you can add CenturyLink Object Storage, Autoscale, and other robust cloud services to give your application the performance edge it needs.

Sign-up for our Developer-focused newsletter CODE. Designed hands-on by developers, for developers. Keep up to date on topics of interest: tutorials, tips and tricks, and community building events.

We’re a different kind of cloud provider – let us show you why.