Bookmark this page

Lab: Troubleshooting Application Issues

Debug a third-party containerized application.

Outcomes

You should be able to diagnose and troubleshoot library dependency and application runtime issues.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start application-review

This command confirms that the required hosts for this exercise are accessible and deploys the containerized application.

Instructions

A system administrator deployed the showviews.php application on the servera machine by using the /var/www/html/showviews.php file, but it is not working. The application uses a web service with a containerized database service. Resolve the issue and verify that the containerized service is working and accessible on the servera machine.

  1. Verify the newly deployed application and observe its behavior.

    1. Log in to servera and switch to the root user.

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera ~]$ sudo -i
      [sudo] password for student: student
      [root@servera ~]#
    2. View the web service status.

      The service status shows an error in a missing library dependency, libaprutil-1.so.0.

      [root@servera ~]# systemctl status httpd
      ● httpd.service - The Apache HTTP Server
         Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
        Drop-In: /usr/lib/systemd/system/httpd.service.d
                 └─php-fpm.conf
         Active: failed (Result: exit-code) since Thu 2021-11-04 20:51:43 EDT; 43s ago
           Docs: man:httpd.service(8)
        Process: 7455 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=127)
       Main PID: 7455 (code=exited, status=127)
      
      Nov 04 20:51:43 servera.lab.example.com systemd[1]: Starting The Apache HTTP Server...
      Nov 04 20:51:43 servera.lab.example.com httpd[7455]: /usr/sbin/httpd: error while loading shared libraries: libaprutil-1.so.0: cannot open shared object file: No such file>
      Nov 04 20:51:43 servera.lab.example.com systemd[1]: httpd.service: Main process exited, code=exited, status=127/n/a
      Nov 04 20:51:43 servera.lab.example.com systemd[1]: httpd.service: Failed with result 'exit-code'.
      Nov 04 20:51:43 servera.lab.example.com systemd[1]: Failed to start The Apache HTTP Server.
  2. View the dynamic libraries of the web service for missing libraries. Install the packages that provide the shared library requirements.

    1. View the shared libraries for the httpd binary.

      All of the shared libraries resolved except for one: libaprutil-1.so.0.

      [root@servera ~]# which httpd
      /usr/sbin/httpd
      [root@servera ~]# ldd /usr/sbin/httpd
      	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f3b9539a000)
      	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f3b95170000)
      	libsystemd.so.0 => /lib64/libsystemd.so.0 (0x00007f3b94e29000)
      	libaprutil-1.so.0 => not found
      ...output omitted...
    2. Locate the packages to install that provide the library.

      [root@servera ~]# yum provides libaprutil-1.so.0
      apr-util-1.6.1-6.el8.i686 : Apache Portable Runtime Utility library
      Repo        : rhel-8.4-for-x86_64-appstream-rpms
      Matched from:
      Provide    : libaprutil-1.so.0
    3. Install the package that provides the libaprutil-1.so.0 library.

      [root@servera ~]# yum install apr-util
      ...output omitted...
    4. Restart the web service and verify the service status.

      [root@servera ~]# systemctl restart httpd
      [root@servera ~]# systemctl status httpd
      ● httpd.service - The Apache HTTP Server
         Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
        Drop-In: /usr/lib/systemd/system/httpd.service.d
                 └─php-fpm.conf
         Active: active (running) since Thu 2021-11-04 21:03:16 EDT; 3s ago
           Docs: man:httpd.service(8)
       Main PID: 7582 (httpd)
         Status: "Started, listening on: port 80"
      ...output omitted...
    5. Query the web service with the localhost default.

      The application exposes the showviews.php URL.

      [root@servera ~]# curl localhost
      <meta http-equiv="refresh" content="0; URL=showviews.php">
    6. Query the web service at the showviews.php URL.

      The service displays a page about views and visits, which verifies that the service is functioning.

      However, the application is not obtaining data from the database. You must resolve the database connection issues.

      [root@servera ~]# curl localhost/showviews.php
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <body>
      
      <table border="1" align="center">
      <tr>
        <td>Site Name</td>
        <td>Views</td>
        <td>Details</td>
      </tr>
  3. Resolve the issues that prevent the application from obtaining the database information.

    1. View the showviews.php file and verify the connection to the database.

      [root@servera ~]# cat /var/www/html/showviews.php
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <body>
      <?php
      
      $hostname = "10.89.0.7";
      $username = "site_monitor";
      $password = "reviews";
      $db = "sitemonitor";
      
      $dbconnect=mysqli_connect($hostname,$username,$password,$db);
      ...output omitted...
    2. View the status of the containerized database.

      [root@servera ~]# podman ps -a
      CONTAINER ID  IMAGE                                                      COMMAND     CREATED         STATUS             PORTS   NAMES
      da31cd1291c1  registry.access.redhat.com/rhscl/mariadb-101-rhel7:latest  run-mysqld  7 minutes ago  Up 7 minutes ago          mariadb-service
    3. Verify the IP address of the database container.

      [root@servera ~]# podman inspect mariadb-service | jq '.[].NetworkSettings.Networks' | grep IPAddress
          "IPAddress": "10.89.0.2",
    4. Modify the showviews.php file to use the correct IP address.

      [root@servera ~]# cat /var/www/html/showviews.php
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <body>
      <?php
      
      $hostname = "10.89.0.2";
      ...output omitted...
  4. Verify that the application runs correctly and displays data for the views and visits.

    1. Verify that the application obtains data from the database.

      [root@servera ~]# curl localhost/showviews.php
      ...output omitted...
      <table border="1" align="center">
      <tr>
        <td>Site Name</td>
        <td>Views</td>
        <td>Details</td>
      </tr>
      
      <tr>
          <td>example.com</td>
          <td>15</td>
          <td>Example site</td>
         </tr>
      <tr>
          <td>site-test.com</td>
          <td>18</td>
          <td>Test site</td>
         </tr>
      </table>
      ...output omitted...
    2. Return to workstation as the student user.

      [root@servera ~]# exit
      [student@servera ~]$ exit
      [student@workstation ~]$
    3. On the workstation machine, open a web browser and navigate to http://servera/showviews.php.

Evaluation

On the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the script until you receive a passing grade.

[student@workstation ~]$ lab grade application-review

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish application-review

Revision: rh342-8.4-6dd89bd