Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create a PHP development environment on the cloud

Learn how to use the IBM Cloud to build and test your PHP applications

Daniel Krook (krook@us.ibm.com), Software Engineer, IBM
Daniel Krook is an IBM/Open Group Master Certified IT Specialist based in the greater New York City area. He has over ten years experience in web application development and currently builds a Cloud infrastructure for IBM using Java EE, DB2, REST, and mobile technologies. He holds certifications in PHP, Java EE, BlackBerry, DB2, and Solaris. He writes PHP-related articles for IBM developerWorks and co-authored the IBM Redbook "Developing PHP Applications for IBM Data Servers."

Summary:  This article explains what makes cloud computing appealing to PHP developers and provides step-by-step instructions how to use the IBM Cloud to set up a PHP and DB2 development environment quickly. Learn how to provision Linux data and web application servers, connect to the virtual machines via SSH, use X Forwarding to install a pre-configured PHP distribution, and test your connection to DB2.

Date:  14 Mar 2011
Level:  Intermediate PDF:  A4 and Letter (1657 KB | 27 pages)Get Adobe® Reader®
Also available in:   Chinese  Russian  Japanese

Activity:  54107 views
Comments:  

Introduction

The IBM Development and Test Cloud is a public Infrastructure as a Service (IaaS) intended for use in the construction and validation of applications. This cloud platform provides access to a variety of Linux and Windows server images that are pre-configured with IBM software. A web, mobile, command-line or custom application can be used to provision, configure and manage these virtual machines. You can then access them over SSH, HTTP, or FreeNX to install, run and test your applications.

Among the greatest risks to the planned release date of a project and its overall quality at launch is the time and cost of setting up a traditional development and test infrastructure comprised of physical servers. The IBM Development and Test Cloud significantly reduces these two risk factors. Instead of purchasing computers, and installing operating systems and middleware (which can be error prone), the IBM cloud reduces that risk and cost by enabling pre-configured virtual servers to be instantiated simply, quickly and consistently.

Beyond these benefits, this article explains why cloud computing appeals to PHP developers and then takes you through the steps needed to configure a PHP test environment on the IBM Cloud. It shows you how to provision two instances which simulate a typical two-tier test environment composed of a database server and an application server:

  • A Linux operating system running a DB2 data server
  • A Linux operating system with a DB2 client installed and running Zend Server, a pre-packaged, GUI-driven PHP distribution for web applications

The example in this article shows how much faster it is to set up a topology using the IBM cloud instead of purchasing, configuring, and installing two physical machines.


How PHP developers benefit from the IBM Cloud

The IBM Development and Test Cloud can help you ensure that your applications are released faster, with fewer bugs, to a larger market than an alternative cloud or physical development and test environment.

Why not use the IBM images on EC2?

There are several pre-configured IBM middleware images on Amazon EC2. You can also develop your applications there, but the Development and Test Cloud offers the following advantages:

  • Premium IBM and operating system vendor support.
  • Detailed control over network and capacity usage.
  • Simplified custom instance image creation.

Central to this system is a catalog of enterprise Linux or Windows images that are pre-configured with IBM software. An instance that is created from an image can mount a persistent disk, have IP addresses assigned to it, and it can be accessed using SSH public key authentication.

In addition, snapshots of your customized instances can be saved into a private image catalog, which makes your configurations reusable, retestable and repeatable.

All of these resources can be provisioned quickly and arranged into a topology that matches the needs of your PHP application.

The IBM Development and Test Cloud can address many types of challenges that affect PHP developers of all stripes, including corporate and freelance programmers, students and writers, system administrators and architects.

Here are a few specific scenarios where this cloud can help you achieve the quality goals for your PHP application.

Verify your deployment environment
The cloud can help you document your deployment steps earlier in the process. You can also use it to set up a test configuration so that you can perform user acceptance testing (UAT is the process to confirm that a system meets mutually agreed-upon requirements) earlier in your release cycle, before your ultimate production hosting environment is available. You'll know exactly what you need to provision on a production cloud, reducing the risk of error and misconfiguration. For example, you may need to evaluate whether your application will run better on one version or packaged distribution of PHP rather than another, or you may want to verify the publication process from staging to production or the replication configuration between two MySQL database servers.

Speed innovation and encourage experimentation
The cloud can help by empowering individual developers to innovate and compare platforms side by side. Developers can have the freedom to flesh out concepts outside of the main code branch without impacting stable configurations. For example, if you are evaluating a move from one PHP framework to another, such as the new Lithium project, creating a separate, virtual instance of PHP 5.3 with MongoDB on the cloud can be quicker and less disruptive than setting up the same configuration on an existing physical development server.

Resolve performance problems and preempt issues
Perhaps you have a performance problem and you want to tweak your system and test out resolution theories quickly, but you don't want to make major changes to your development or staging areas. Instead, you can now use the IBM Cloud to run those tests. Installation steps can be recorded and back out plans can be validated. For example, multiple possible configurations can be evaluated and tested using a cloud infrastructure rather than physical systems. In addition, by saving a catalog of private images, you can quickly retest or isolate issues to particular configurations.

Improve your open source project
If you are a maintainer of an open source PHP framework, your goal is to deliver a stable product that works on as many platforms as possible. Perhaps you get a bug report from a user in a particular configuration. With the IBM cloud, you can easily replicate the user's environment to identify the source of the bug. For example, if a user reported an issue with a version of SUSE Linux Enterprise Server, but all you have is Ubuntu or Fedora, you could quickly provision an instance of SLES running your framework to verify the bug report. In addition, you could expand the list of supported platforms after performing such a test by maintaining several enterprise Linux configuration images in a private catalog.

Build your skills and broaden your knowledge
Using the IBM Cloud environment, technical documentation writers, students, instructors and authors, or industry analysts can also benefit by being able to document new software or experimenting with a piece of software they need for only a limited time. Perhaps they have a final project or tight deadline, but don't want to make a long-term commitment to the purchase or setup of complete systems from scratch. The IBM Cloud can be the answer.

Now that you have a feel for the broad value the Development and Test Cloud can deliver to a variety of PHP users, let's configure a PHP development and test environment on the IBM Cloud.


Provision a Linux data server

The image catalog

The catalog of available server images is subject to change, and includes regular updates to IBM software, along with subsequently refreshed software images. If you do not see the exact image names used in the examples, a similar image will suffice.

For the data server, select a Red Hat Enterprise Linux server from the catalog that already has DB2 installed. You will create a web server instance later when you install PHP and connect to this server, so no special configuration is required once you provision this instance.

  1. Log into the Development and Test application and select the Control Panel tab. Click Add Instance.

    Figure 1: The Add Instance button on the Control Panel
    The Add Instance button on the Control Panel

  2. Choose DB2 Enterprise Developer Edition 9.7.1 64bit from the catalog.

    Figure 2: Select a DB2 image
    Select a DB2 image

  3. Give it a name, and generate a public/private key if necessary. I called this instance "dW DB2 data server" and chose the "dW" public key that I generated. Use the corresponding private key on your workstation to access this instance, instead of a user name and password.

    Figure 3: Configure the DB2 image
    Configure the DB2 image

  4. Set the passwords for the three new user accounts that DB2 requires.

    Figure 4: Configure the DB2 passwords
    Configure the DB2 passwords

  5. Verify the configuration of the instance.

    Figure 5: Verify instance configuration
    Verify instance configuration

  6. Review the license agreement and click Next.

    Figure 6: Read the license agreement
    Read the license agreement

  7. Confirm that the instance request has been submitted.

    Figure 7: Instance request submitted successfully
    Instance request submitted successfully

That's all you need to do to spin up an instance to be used as a data server. You can monitor the control panel, which shows the status of the instance as it is provisioned and starts up. When the system boots, DB2 is already running.


Provision a Linux web application server

Create another instance from the same image and install Zend Server Community Edition. This is the simplest way to ensure that the DB2 client that the PHP driver needs is already installed and available.

  1. Log into the Development and Test application and select the Control Panel tab. Click Add Instance.
  2. Choose the same DB2 Enterprise Developer Edition 9.7.1 64bit image from the catalog.
  3. Give it a name, and generate a key if necessary, as above. I called this instance "dW Zend Web server" and chose the "dW" public key.
  4. Set the DB2 passwords.
  5. Confirm the configuration.
  6. Review the license agreement.
  7. Click Next and wait for confirmation.

You can now monitor the status of the instance request on the control panel. The DB2 client is installed and running when the instance starts up.


Convert your private key and connect to your server using SSH

Once the web application server instance has provisioned, you can log into it and install Zend Server Community Edition.

Tip: Reusing a PuTTY session configuration

You can reuse the PuTTY session you set up below for future instances by loading it, changing the "Host name" field to your new host, renaming it, and clicking Save.

The following steps assume you are using Windows for SSH and X forwarding. If you're using a different platform, you'll need to install the equivalent tools for that platform.

  1. When you created the instances above, you had an option to generate a public/private key pair in order to connect to your servers without a user name and password. You'll need to convert the private key that you downloaded to your workstation from OpenSSH format to PuTTY's private key format using the PuTTY Key Generator, PuTTYgen. Open PuTTYgen and choose File > Load private key.

    Figure 8: Convert private key
    Convert private key

  2. You'll see a notice that this key is in the OpenSSH format. Click OK.

    Figure 9: Loaded OpenSSH private key
    Loaded OpenSSH private key

  3. Click Save private key and pick a new location for the converted file. To confirm that you want to save the converted key without a passphrase, click Yes.

    Figure 10: Save converted key
    Save converted key

  4. Install and configure XMing. It should start automatically. If not, click the Xming shortcut.
  5. Configure PuTTY to log into the instance using SSH. Add the hostname you see in the control panel after your instance has finished provisioning. Click Save, then Load.

    Figure 11: PuTTY configuration
    PuTTY configuration

  6. Set the user to "idcuser" under Connection...Data in the Auto-login username field.

    Figure 12: Set user name
    Set user name

  7. Import your private key on the SSH...Auth screen and browse for the private key file you converted earlier.

    Figure 13: Import converted key
    Import converted key

  8. Finally, set up X forwarding in order to view X Windows from the Linux server on your Windows desktop. On the SSH...X11 screen, check the X11 forwarding box and enter localhost:0 in the X display location field.

    Figure 14: Configure X forwarding
    Configure X forwarding

  9. Now, go back to Session and click Save, then Open. Click Yes to the PuTTY Security Alert and accept the instance host key, as this is the first time you are connecting to this server.
  10. Disable the firewall in order to allow X forwarding. Then test X Windows using a simple test with xclock:

    Listing 1: Shut down the firewall and run xclock
    $ sudo /etc/init.d/iptables stop
    $ xclock
    



    Figure 15: Disable iptables and test X forwarding
    Disable iptables and test X forwarding


Install a pre-configured PHP distribution

  1. Now that you are logged in and set up for a GUI installation, download Zend Server Community Edition (Zend Server CE (PHP 5.3) 5.0.3 (64 bit) (TAR.GZ) 55.95 MB). Find more information about Zend Server on the Zend product page.

    Listing 2: Downloading and installing Zend Server
    $ mkdir src
    $ cd src
    $ wget http://www.zend.com/download/353?start=true
    $ tar - xvzf ZendServer-CE-php-5.3.3-5.0.3-linux-glibc23-x86_64.tar.gz
    $ cd ZendServer- 5.0.3_Tarball_B3-php5.3.3-linux-glibc23-x86_64/
    $ sudo su -
    # cd /home/idcuser/src/ZendServer-5.0.3_Tarball_B3-php5.3.3-linux-glibc23-x86_64/
    # ./install.sh
    

    Allow time for the system to complete the installation. After a few minutes, you should see the following screen.



    Figure 16: Install Zend Server
    Install Zend Server

  2. Type exit to escape the root shell and resume the idcuser session, then launch the Firefox web browser. You won't be able to launch any windows as root, as you configured X forwarding in PuTTY only for idcuser.

    Listing 3: Launch Firefox as idcuser
    # exit
    $ firefox https://localhost:10082/ZendServer
    

    Since Zend Server is running over HTTPS with a self-signed certificate, you need to add an exception when prompted to view the page. Once Firefox has launched, the first page is the End User License Agreement. Read it and click Next.



    Figure 17: Zend Server EULA
    Zend Server EULA

  3. On the second page, set a console password, retype it and click Next.
  4. On the third page you can optionally provide your email address if you would like to join the Zend Server Community Edition mailing list. Click Finish.
  5. You'll see the Zend Server Dashboard. The most common extensions are included and enabled out of the box. The DB2 driver extension is included, but you need to activate it.
  6. Choose the Server Setup tab, then the Extensions link below it and scroll down to ibm_db2. Click Turn On.

    Figure 18: ibm_db2 extension
    ibm_db2 extension

  7. In a new PuTTY session, source the DB2 environment for the Apache web server and change the default port to 80, then restart all Zend Server daemons.
    1. Edit the Apache configuration file and change the line Listen 10088 to Listen 80.

      Listing 4: Edit httpd.conf to change the port
      $ sudo su -
      # vi /usr/local/zend/apache2/conf/httpd.conf
      

    2. Source the DB2 environment for Apache each time it starts up. This is necessary in order to set the path for Apache to find DB2 for the PHP driver. Once you open the file, add the line . /home/db2inst1/sqllib/db2profile anywhere after the first line.

      Listing 5: Edit apachectl to source the DB2 environment
      
      # vi /usr/local/zend/apache2/bin/apachectl
      

    3. Restart all of the Zend Server processes from the command line. Clicking Restart PHP in the GUI is not sufficient.

      Listing 6: Restart the Zend Server processes
      
      # /usr/local/zend/bin/zendctl.sh restart
      

  8. Open a new tab in the existing Firefox window and enter http://localhost/. You should see a screen that says Zend Server Test Page.

    Figure 19: Zend Server Test Page
    Zend Server Test Page


Test the connection

  1. Finally, we'll create a simple PHP script to test that we have configured the DB2 connection correctly. I'll create the following PHP script in the /var/www/html directory. It simply connects to the data server to verify the connection.

    Listing 7: Edit apachectl to source the DB2 environment
    
    # vi /usr/local/zend/apache2/htdocs/db2info.php
    



    Listing 8. PHP script to connect to DB2
    
    <?php
    $username = 'db2inst1';
    $password = 'passw0rd';
    $database = 'sample';
    $hostname = 'vhost0323.developer.ihost.com';
    $port     = '50001';
    
    $conn_string =
       "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
       "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP" .
       "UID=$username;PWD=$password";
      
    $conn_resource = db2_connect($conn_string, '', '');
    
    if ($conn_resource) {
        echo 'Connection to database succeeded.';
        db2_close($conn_resource);
    } else {
        echo 'Connection to database failed.<br />';
        echo 'SQLSTATE: ' . db2_conn_error() . '<br />';
        echo 'Message: ' . db2_conn_errormsg(). '<br />';
    }
    ?>
    

  2. After saving this file, you should see the following screen when you load http://localhost/db2info.php in the browser.

    Figure 20: Successful connection from PHP to DB2
    Successful connection from PHP to DB2

Congratulations, you now have two virtual servers configured to support your PHP and DB2 powered web application! The steps you followed to create this system are similar for any other virtual servers you decide to instantiate in the future.


Conclusion

In this article you learned:

  • The compelling opportunities that cloud computing and the SmartCloud Enterprise can offer PHP developers.
  • How to provision a typical PHP development and test environment on the IBM Cloud quickly.

With a PHP configuration up and running on the cloud, you can now tackle any one of the scenarios described in the article:

  • Verify your deployment environment.
  • Speed innovation and encourage experimentation.
  • Resolve performance problems and preempt issues.
  • Improve your open source project.
  • Build your skills and broaden your knowledge.

Check out the resources below to learn more about PHP development on the cloud, then get started with IBM SmartCloud Enterprise.


Resources

Learn

Get products and technologies

  • See the product images available on the IBM SmartCloud Enterprise.

  • Download PuTTY and PuTTYgen which are used in this article to connect to your instances over SSH using public key authentication.

  • Download Xming X Server for Windows which is used in this article to support X forwarding.

  • Download and experiment with the cutting edge Lithium framework for PHP 5.3.

  • Download the Zend Server Community Edition to run the examples in this article.

  • Evaluate IBM products in the way that suits you best: Download a product trial, try a product online, use a product in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement Service Oriented Architecture efficiently.

Discuss

About the author

Daniel Krook is an IBM/Open Group Master Certified IT Specialist based in the greater New York City area. He has over ten years experience in web application development and currently builds a Cloud infrastructure for IBM using Java EE, DB2, REST, and mobile technologies. He holds certifications in PHP, Java EE, BlackBerry, DB2, and Solaris. He writes PHP-related articles for IBM developerWorks and co-authored the IBM Redbook "Developing PHP Applications for IBM Data Servers."

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing, Linux, Information Management
ArticleID=631569
ArticleTitle=Create a PHP development environment on the cloud
publish-date=03142011