Skip to Content

This tutorial describes how you can run a simple HelloWorld web application on an SAP Cloud Platform virtual machine using Apache.

Prerequisites

The hello_world_apache.sh file, that we are going to use in this tutorial, contains the following code. Create a blank .txt file, transfer the code there, and save it as an .sh file with the exact same file name.

#!/bin/bash

zypper -n ar -f $1 SLES
zypper --no-gpg-checks --non-interactive -n install apache2 openssl

#### Enable SSL
echo "Setup apache for SSL"
a2enmod ssl
a2enflag SSL

#### Generate ss cert for apache, you can tweak the attributes below
echo "Generate self-signed cert"

cat > /tmp/openssl.cnf <<EOF
 [ req ]
 default_bits           = 2048
 distinguished_name     = req_distinguished_name
 attributes             = req_attributes
 prompt                 = no
 output_password        =

 [ req_distinguished_name ]
 C                      = BG
 ST                     = Test State or Province
 L                      = Test Locality
 O                      = Organization Name
 OU                     = Organizational Unit Name
 CN                     = Common Name
 emailAddress           = test@email.address

 [ req_attributes ]
 challengePassword              =
EOF

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl.key/server.key -out /etc/apache2/ssl.crt/server.crt -config /tmp/openssl.cnf
chmod 600 /etc/apache2/ssl.key/server.key /etc/apache2/ssl.crt/server.crt
rm /tmp/openssl.cnf

##### Generating default vhost for your site, worning dose not support SNI
echo "Generate vhost for your website"

cat > /etc/apache2/vhosts.d/openstack-ssl.conf <<EOF
<IfDefine SSL>
<IfDefine !NOSSL>
Listen 8041

<VirtualHost _default_:8041>
        DocumentRoot "/srv/www/htdocs"
        ErrorLog /var/log/apache2/error_log
        TransferLog /var/log/apache2/access_log
        SSLEngine on
        SSLProtocol all -SSLv2 -SSLv3
        SSLCertificateFile /etc/apache2/ssl.crt/server.crt
        SSLCertificateKeyFile /etc/apache2/ssl.key/server.key
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory "/srv/www/cgi-bin">
            SSLOptions +StdEnvVars
        </Directory>

        BrowserMatch "MSIE [2-5]" \
                 nokeepalive ssl-unclean-shutdown \
                 downgrade-1.0 force-response-1.0

        CustomLog /var/log/apache2/ssl_request_log   ssl_combined

</VirtualHost>

</IfDefine>
</IfDefine>
EOF

echo "Creating test page"
echo "Hello World" > /srv/www/htdocs/index.html

echo "Restart apache"

service apache2 restart
#systemctl reload apache2

Steps

1. Create a virtual machine.

1.1 Open your console client and go to the tools folder of your SDK by executing the cd <path to your SDK tools folder> command.

1.2 Create your virtual machine:

neo create-vm --size x-small --name myvmname --account mysubaccountname --host hana.ondemand.com --user myemail@example.com

After your virtual machine is created, look for the virtual machine key usually located in your SDK folder. Follow the instructions in step 2 to convert that autogenerated key from .key to .ppk format.

2. Connect to the virtual machine.

We will use both PuTTY and WinSCP for this tutorial, but you may also try it out using other SSH clients. In both cases, you need to have:

– PuTTYgen installed

– An open SSH tunnel to the virtual machine

For PuTTY, follow these steps:

  1. Convert the key using PuTTYgen.
  2. Load the autogenerated key (select Load or Conversations  Import key).
  3. Save the private key.
  4. In PuTTY, open the Connection → SSH → Auth tab and add the converted private key.
  5. Open the Session tab.
  6. Enter host name: root@localhost.
  7. Enter port: the tunnel port.
  8. Open the connection.

For WinSCP, follow these steps:

  1. Convert the key using PuTTYgen.
  2. Load the autogenerated key (select Load or Conversations Import key).
  3. Save the private key.
  4. Open WinSCP.
  5. Enter host name: localhost.
  6. Enter port: the tunnel port.
  7. Enter username: root.
  8. Open Advanced settings and then open SSH Authentication.
  9. Add the converted private key and click OK.
  10. Log in.

The idea behind using the WinSCP client in this tutorial, is to allow you to transfer the hello_world_apache.sh script file from your local file system to the virtual machine.

The .key file conversion together with the PuTTY and WinSCP login steps are also described in Setting up an SSH client to connect to HCP Virtual Machines.

3. Open an SSH tunnel to the virtual machine.

neo open-ssh-tunnel --port XXXXX --vm-id c29d0f4d-b755-43c9-aaf4-fdaa1b049ed8 --account mysubaccountname --host hana.ondemand.com --user myemail@example.com

You can find the ID of your virtual machine in the SAP Cloud Platform cockpit:

Оr in the output of the list-vms command:

neo list-vms --account mysubaccountname --host hana.ondemand.com --user myemail@example.com

4. Upload the hello_world_apache.sh file in the virtual machine.

After you have started a WinSCP session, find and open the local folder containing the .sh file. Then, drag and drop it, for example, in the root folder of the virtual machine.

5. Execute commands in PuTTY.

Note: First, make sure that you are in the right folder. Let’s assume that the .sh file is transferred to the root folder of the virtual machine as mentioned in step 4. In this case, run the cd /root command in PuTTY to go to that folder. And if you want to double-check that the .sh file is there, run the ls command to list all available files in that folder.

Once you are in the correct folder, you are ready to execute the following two commands:

The first command gives you the right to run the script.

chmod a+x hello_world_apache.sh

The second command executes the script.

./hello_world_apache.sh https://slesrepo.hana.ondemand.com/repo/SUSE/Products/SLE-SERVER/12/x86_64/product/

Note: The hana.ondemand.com region host is valid for the Europe (Rot/Germany) region. If your virtual machine is hosted on another SAP Cloud Platform region host, choose one of the other available options at Regions and Hosts.

6. Register an access point for the virtual machine.

You can do that in two ways:

– Go to the overview page of the virtual machine in the cockpit and select Expose to Web.

– Run the following console client command:

neo register-access-point --account mysubaccountname --user myemail@example.com --host hana.ondemand.com --name myvmname

Result: In either case, you should receive a URL like this one: https://[myvmname][mysubaccountname].vms.hana.ondemand.com. This is what the URL of the virtual machine should look like.

7. Open the URL of the virtual machine.

Open the URL in a browser of your choice. You should be able to see your HelloWorld web application displayed there:

I hope that this tutorial was helpful to you. If you run into some problems while going through the steps, don’t hesitate to share your feedback!

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply