Develop > Server Automation Platform > Automation Platform Extensions (APX) > Tutorial: Create a wb application APX

Tutorial: Create a Web application APX

This tutorial demonstrates how to create, publish, and run a simple web application APX named mywebapp.

Running the default version of the APX created during this tutorial displays the output of the PHP command, phpinfo. Later the tutorial shows you how to modify the PHP code so that it displays a list of managed servers. Because the tutorial provides the source code, prior knowledge of PHP is not required.

Complete the following tasks in order.

  1. Setting permissions and creating the tutorial folder
  2. Creating a new web application
  3. Importing the new web application into SA
  4. Running the new web application
  5. Modifying the web application
  6. Running the modified web application

Tutorial prerequisites

To complete this tutorial, you must have the following capabilities and environment:

  • The ability to log on to SA as admin or as another member of the Super Administrators group. Logging on as admin enables you to set permissions.
  • The ability to log on to SA as a user who belongs to the Advanced Users group.
  • Advanced users have permission to create and run the web application. In the example commands shown in this tutorial, the name of this user is jdoe.
  • An understanding of how to set client feature permissions in the SA Client.
  • For more information about permissions, see the "User and Group Setup" section in the the SA Administer section.
  • An understanding of how to create folders in the SA Client
  • For details on folders, see the SA Use section.
  • An understanding of how to open a Global Shell session.
  • An understanding of basic Unix commands such as ls and cd.
  • Experience developing web applications that run on HTTP servers.

Setting permissions and creating the tutorial folder

  1. Log on to the SA Client as a member of the Advanced Users group and create the following folder in the SA Library:

    /Dev/MyApp

    Later in the tutorial, you will upload a web application into the MyApp folder. In the non-tutorial environment, the name of this folder is arbitrary. You can create or choose any other folder to contain your web applications.
  2. Exit the SA Client.
  3. Log on to the SA Client as admin and open the Folder Properties of the MyApp folder.
  4. On the Permissions tab of Folder Properties, make sure that the Advanced Users group has the following permissions:
    • List Contents of Folder
    • Read Objects Within Folder
    • Write Objects Within Folder
    • Execute Objects Within Folder
  5. Exit the SA Client.

Creating a new web application

  1. Open a Global Shell session as an SA user who belongs to the Advanced Users group.
  2. In your core’s OGFS home directory, create a directory named mywebapp and then change to that directory:

    $ mkdir mywebapp
    $ cd mywebapp


    The web application files will be stored in the mywebapp directory.
  3. Using the apxtool new command, create the directory structure and default files for the web application as shown below.

    $ pwd
    /home/jdoe/mywebapp
    $ ls
    $
    $ apxtool new -tw -d "This is my first app." \
    -u com.hpe.sa.jdoe.mywebapp
    Create source directory /home/jdoe/mywebapp/com.hpe.sa.jdoe.mywebapp? Y/N y
    Info: Successfully created APX 'mywebapp' source directory: /home/jdoe/mywebapp.


    The -tw option indicates that the APX type is a web application, -d specifies a description, and -u specifies a unique name for the application.

    For more information about the apxtool new command options, see the online help:
    $ apxtool new -h
  4. Change directories into the new directory created by the apxtool new command and list the files there.

    $ pwd
    /home/jdoe/mywebapp
    $ cd com.hpe.sa.jdoe.mywebapp
    $ ls
    APX-INF cgi-bin css images index.php
    $ ls -R
    .:
    APX-INF cgi-bin css images index.php
    ./APX-INF:
    apx.cfg apx.perm description.txt interfaces usage.txt
    ./cgi-bin:
    ./css:
    hp_sa.css
    ./images:
  5. Display the contents of the default index.php file:

    $ cat index.php
    <?php
    // Show information about PHP
    phpinfo();
    ?>


    As with other web applications, you can replace the index.php file with an index.html file. However, this tutorial uses the index.php file, which you will modify in a later section.
  6. Examine some of the files in the APX-INF directory. For more information, see APX files.

    The APX-INF directory contains information that is specific to APX web applications. As shown by the following cat command, the description.txt file holds the text you specified with the -d option of apxtool new.

    $ ls APX-INF/
    description.txt apx.cfg apx.perm usage.txt
    $ cat APX-INF/description.txt
    This is my first app $


    The following grep command shows some of the properties in apx.cfg, the APX configuration file. The values for type and uniquename result from the -t and -u options of the apxtool new command. For details on the APX configuration file, see APX configuration file - apx.cfg.

    $ grep "=" APX-INF/apx.cfg
    type=webapp
    name=mywebapp
    unique_name=com.hpe.sa.jdoe.mywebapp

Importing the new web application into SA

Importing the web application performs the following actions:

  • Installs the web application on an HTTP server within SA.
  • Copies the web application to a folder that appears in the SA Library and in the Global Shell.
  • Assigns a version number to the web application.

Enter the apxtool import command and respond to the prompts with y, as shown below. The -f option specifies the folder in the SA Library where the web application will be stored. The -c option sets the current version of the web application.

$ pwd
/home/jdoe/mywebapp/com.hpe.sa.jdoe.mywebapp
$
$ apxtool import -f "/Dev/MyApp" -c
APX source is not specified.
Do you want to publish current directory: /home/jdoe/mywebapp/
com.hpe.sa.jdoe.mywebapp? Y/N y
APX with unique name 'com.hpe.sa.jdoe.mywebapp' does not exist.
Register it into the system? Y/N y
Info: Successfully registered APX 'mywebapp' (310001) in folder ‘/Dev/
MyApp’.
Info: Successfully published a new version '1' for APX 'mywebapp'.
Info: Successfully set APX 'mywebapp'(310001) current version as '1'.

Running the new web application

Now that you have published the web application, you are ready to run it from the SA Client, just as an end-user would.

  1. Log on to the SA Client as a user who belongs to the Advanced Users group.
  2. Select the Library tab and the By Type tab.
  3. Navigate to the Extensions > Web node where you should see the mywebapp extension.

    If you do not see mywebapp, make sure that you have the necessary permissions as described in Setting permissions and creating the tutorial folder.
  4. To run the web application, select mywebapp. and select the Actions > Run menu.

    The following figure appears. The web application displays the information generated by the phpinfo statement of the index.php file.

    Web Application Version 1


Modifying the web application

Running the default index.php file is a good way to check your development environment, but it does not take advantage of SA functionality. In this section, you modify the index.php file so that it lists the names of servers managed by SA.

  1. In the Global Shell session, locate the index.php file of the web application.

    $ cd /home/jdoe/mywebapp/com.hpe.sa.jdoe.mywebapp
    $ ls
    APX-INF cgi-bin css images index.php
  2. Open the index.php file in a text editor such as vi.
  3. Replace the contents of index.php with the following lines:

    <html>
    <head>
    <title>Servers</title>
    </head>
    <body>
    <p>List of servers:</p>
    <?php
    passthru("ls /opsw/Server/@");
    ?>
    </body>
    </html>


    The passthru statement above runs the ls command and passes stdout (without reinflates) back to the web page. The ls command lists the names of your managed servers as they appear in the OGFS.
  4. Save the index.php file and exit the text editor.
  5. Publish the modified web application.

    The following apxtool import command sets the current version to 2. The -F option suppresses the confirmation prompts.

    $ apxtool import -f "/home/jdoe/mywebapp/com.hpe.sa.jdoe.mywebapp" \
    -c --version=2 -F
    Info: Successfully published a new version '2' for APX 'mywebapp'
    Info: Successfully set APX 'mywebapp'(310001) current version as '2'.

Running the modified web application

  1. In the SA Client, use the View> Refresh menu to refresh the view of your web extensions, which should now contain version 2 of mywebapp.
  2. Select mywebapp and select the Actions > Run menu. The output should be similar to the Web Application Version 1 except it displays the output of the PHP passthru statement and the OGSH ls statement, which lists all your managed servers. Note that the passthru statement removes the line feeds that separate the server names returned by the ls command.