7 Replies Latest reply on Apr 12, 2018 9:01 AM by DougBaer

    Problems building sample 3 tier application

    drharrold Novice

      I am trying to build the sample 3 tier application documented by Doug Baer on the Hands On Labs blog. 

       

      I've noticed a few differences from the article (HOL Three-Tier Application, Part 2 - DB server - VMware Hands-On Lab (HOL) Blog - VMware Blogs ).  Things like Photon is now V2.0, not V1.  Sqlite3 wasn't installed by default.

       

      I'm having an issue with building the DB server with the web server.  When I enable the mod_cgi.so plugin, I get an internal server error from the webserver when I try to access the page.

       

      root@db-01a [ /etc/httpd/cgi-bin ]# curl http://db-01a/cgi-bin/data.py

      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

      <html><head>

      <title>500 Internal Server Error</title>

      </head><body>

      <h1>Internal Server Error</h1>

      <p>The server encountered an internal error or

      misconfiguration and was unable to complete

      your request.</p>

      <p>Please contact the server administrator at

      admin@localhost to inform them of the time this error occurred,

      and the actions you performed just before this error.</p>

      <p>More information about this error may be available

      in the server error log.</p>

      </body></html>

       

      But it I comment that module out, it will print the contents of the data.py module.

       

      root@db-01a [ /etc/httpd ]# curl http://db-01a/cgi-bin/data.py

      #!/usr/bin/env python

      import cgi

      import sqlite3

       

      conn=sqlite3.connect('/etc/httpd/db/clients.db')

      curs=conn.cursor()

       

      print ("Content-type:text/plain\n\n");

       

      form = cgi.FieldStorage()

      querystring = form.getvalue("querystring")

      if querystring != None:

         queryval = "%" + querystring + "%"

         select = "SELECT * FROM clients WHERE name LIKE '" + queryval + "'"

      else:

         select = "SELECT * FROM clients"

       

      for row in curs.execute(select):

         if len(row) == 4:

            for item in row:

              print (item,'|')

            print ("#")

       

      conn.close()

       

      Any pointers on how to fix this?

       

      Thanks,

      Dave Harrold

        • 1. Re: Problems building sample 3 tier application
          DougBaer Master
          VMware Employees

          Hi Dave,

           

          The first pointer I'd have is to stick with the v1.0 build that I used in the article. If you're going to try and follow it step by step, all of that works. You can still download this version at the bottom of the PhotonOS download page: Downloading Photon OS · vmware/photon Wiki · GitHub  in the "PhotonOS Original Binaries section"

           

          This is the link to the version I used for the article:

          https://bintray.com/vmware/photon/download_file?file_path=photon-custom-hw10-1.0-13c08b6.ova

           

          As for the issue you are seeing, it looks to me like Python is not being executed by the CGI module, which is the "misconfiguration" being reported. It is possible that Python is not installed, or is not in the path.

           

          It looks like I'm going to need to look at the Photon 2.x release. I'll take a quick look to see what I can find, but I need to download the new version, so it may take me a bit.

           

          Thanks for using the HOL blog and that article 

           

          -Doug

          • 2. Re: Problems building sample 3 tier application
            DougBaer Master
            VMware Employees

            It looks like you may make some headway by replacing the

             

            /usr/bin/env python

             

            line at the top of the python scropt(s) with

             

            /usr/bin/env python3

             

            It looks like they have replaced python 2.x with 3.x in v2.0 of PhotonOS.

             

            Because it is Python 3.x now, you also need to put all of the "print" parameters in parentheses. So, for example,

             

             

            #!/usr/bin/env python3

            import cgi

            import sqlite3

             

            conn=sqlite3.connect('/etc/httpd/db/clients.db')

            curs=conn.cursor()

             

            print ("Content-type:text/plain\n\n");

             

            form = cgi.FieldStorage()

            querystring = form.getvalue("querystring")

            if querystring != None:

               queryval = "%" + querystring + "%"

               select = "SELECT * FROM clients WHERE name LIKE '" + queryval + "'"

            else:

               select = "SELECT * FROM clients"

             

            for row in curs.execute(select):

               if len(row) == 4:

                  for item in row:

                    print (item,'|')

                  print ("#")

             

            conn.close()

             

             

            Let me know if that works out for you

             

            -Doug

            • 3. Re: Problems building sample 3 tier application
              drharrold Novice

              Thanks Doug,

               

              I downloaded the 1.0 version and everything went as you documented in the article.

               

              I was just trying to be current/bleeding edge with using V2.0, I didn't think some of those things would have changed so much.

               

              And, Thanks You!!! for publishing these.  The app will be really handy as I build my lab to demo NSX to customers.

               

              Thanks again!

               

              Dave

              • 4. Re: Problems building sample 3 tier application
                drharrold Novice

                OK, thanks for the pointer.

                 

                I'm going to continue down the path of using the Photon 1.0 stuff, just because I need something quick.

                 

                I'll probably look at updating the Photon 2.0 stuff when I have a little more time.

                 

                Thanks for the great work!

                • 5. Re: Problems building sample 3 tier application
                  drharrold Novice

                  I got the db server working on Photon 2.0

                   

                  1.) Had to install sqlite

                   

                  2.) Made the python changes you highlighted below

                   

                  3.) Changes to httpd.conf file

                   

                  This is how the cgi section of the httpd.conf file looks.

                  <IfModule !mpm_prefork_module>

                          #LoadModule cgid_module /usr/lib/httpd/modules/mod_cgid.so

                  </IfModule>

                  <IfModule mpm_prefork_module>

                         #LoadModule cgi_module /usr/lib/httpd/modules/mod_cgi.so

                  </IfModule>

                   

                  If I just uncommented the LoadModule line for the mod_cgi.so file, it still gave the error.  I had to comment out all of the IfModule statements and then it worked.

                   

                  #<IfModule !mpm_prefork_module>

                          #LoadModule cgid_module /usr/lib/httpd/modules/mod_cgid.so

                  #</IfModule>

                  #<IfModule mpm_prefork_module>

                          LoadModule cgi_module /usr/lib/httpd/modules/mod_cgi.so

                  #</IfModule>

                   

                  So, I expect I'll have to make similar changes on the app and web server VMs.

                   

                  I'll update when those are working.

                   

                  Dave

                  • 6. Re: Problems building sample 3 tier application
                    drharrold Novice

                    So I finished building the app and web server VMs with Photon 2.0.  The only updates needed were the changes to the Python scripts similar to the db VM: Change the environment to python3, update the print commands.

                     

                    So, it's all working using the PhotonOS 2.0 OVAs.

                     

                    Thanks,

                    Dave

                    • 7. Re: Problems building sample 3 tier application
                      DougBaer Master
                      VMware Employees

                      Excellent!  Nice job and thanks for the update.

                      -Doug