No results found

Your search did not match any results.

We suggest you try the following to help find what you’re looking for:

  • Check the spelling of your keyword search.
  • Use synonyms for the keyword you typed, for example, try “application” instead of “software.”
  • Try one of the popular searches shown below.
  • Start a new search.
Trending Questions

Create an Application on Oracle Cloud Infrastructure

This tutorial shows how straightforward it is to set up an Oracle Cloud Infrastructure Compute VM and create a Python Flask “hello world” application.

Here are the high-level steps:

  1. Create an SSH key pair
  2. Create a Compute VM instance
  3. Open a port in your virtual cloud network (VCN)
  4. Open a port in the Linux firewall
  5. Create the Flask application
  6. Test the application
  7. Clean up your environment

Before you begin

To successfully perform this tutorial, you must have an Oracle Cloud account. If you don’t have one, you can sign up for the Oracle Cloud Infrastructure Free Tier.

Create an SSH key pair in Cloud Shell

1. In the Oracle Cloud Infrastructure Console, click the Cloud Shell icon in the Console header.
Cloud Shell opens in a "drawer" at the bottom of the Console. It provides a preconfigured VM that you will use to access and set up your project.

2. If you don’t already have a key pair that you can use, follow these steps to create one:

A. Create the .ssh directory, if it doesn’t exist:

 
mkdir ~/.ssh
chmod 700 ~/.ssh

B. Create an SSH key pair in Cloud Shell:

 
ssh-keygen -t rsa -N "" -b 2048 -C "" -f ~/.ssh/id_rsa

3. Display your public key:

 
cat ~/.ssh/id_rsa.pub

4. Highlight the public key and use CTRL-C to copy it. You will use it in the next section.

5. Minimize Cloud Shell.

Figure 1.

Create a VM instance

Perform the following steps in the Console.

1. In the Quick Actions section of the Console dashboard, click Create a VM instance.

Figure 1.

2. Enter a name or keep the default.

Figure 1.

3. Accept the default values for all the other sections.

4. Scroll to the Add SSH keys section, and select Paste SSH keys.

Figure 1.

5. Paste your public key from your Cloud Shell.

6. Click Create.

Open port 5000 in your virtual cloud network (VCN)

  1. On the VM instance details page, click Public Subnet.
  2. Figure 1.

  3. Click the default security list.
  4. Figure 1.

  5. Click Add Ingress Rules.
  6. Figure 1.

  7. For Source CIDR, enter 0.0.0.0/0.
  8. For Destination Port Range, enter 5000.
  9. Click Add Ingress Rules.
  10. Figure 1.

  11. Return to the VM instance details page.

Use SSH to connect to your VM instance

After your instance is running, perform the following steps to access it:

1. Copy the public IP address.

Figure 1.

2. Maximize your Cloud Shell.

Figure 1.

3. Use SSH to log in to the instance:

ssh opc@<yourPublicIP>

Open port 5000 in the Linux firewall

Run the following commands to open port 5000:



sudo firewall-cmd --permanent --zone=public --add-port=5000/tcp
sudo firewall-cmd --reload




Create the Flask application

1. Create a directory to work in:

 
mkdir flaskexample
cd flaskexample

2. Create and activate a Python virtual environment:

 
python3 -m venv venv
source venv/bin/activate

3. Install Flask:

 
pip install flask

4. Use nano to create your application:

 
nano flaskexample.py

5. Copy the following code and paste it into Cloud Shell (ensure that the indentation is correct):

 
from flask import Flask
app = Flask(__name__)

@app.route("/")
def index():
    return "Web App with Python Flask!"

if __name__ == "__main__":
    app.run(host='0.0.0.0')

6. Exit and save the file: press Ctrl-X, type y, and then press Enter.

7. Run the application:

 
python flaskexample.py

Test the application

Open the application in a browser by entering http://:5000.

Screenshot that shows the Flask application running in a web browser

Clean up your environment

  1. On the VM instance details page, click Public Subnet.
  2. Screenshot that shows the Flask application running in a web browser

  3. Click the default security list.
  4. Screenshot that shows the Flask application running in a web browser

  5. Under Ingress Rules, select the check box for the 5000 rule.
  6. Click Remove.
  7. Screenshot that shows the location of the Remove button and the rule selection check box.

  8. Click Remove.
  9. Return to the VM instance details page.
  10. Click More Actions.
  11. Click Terminate.
  12. Select Permanently Delete the Attached Boot Volume.
  13. Click Terminate Instance.

Watch the video version of this tutorial (3:35)

Try Oracle Cloud Free Tier