To host a Django website on an Oracle Cloud Virtual Machine (VM), you'll need to follow these steps:

  1. Create an Oracle Cloud VM: Log in to your Oracle Cloud account and create a new VM instance. You can choose the desired OS image, such as Oracle Linux, Ubuntu, etc. Make sure to select appropriate resources (CPU, RAM, etc.) based on your website's requirements.

  2. Connect to the VM: Once the VM is created, you can connect to it using SSH. Use a tool like ssh on macOS/Linux or PuTTY on Windows to establish an SSH connection.

  3. Update the System: After connecting to the VM, update the system packages and install necessary dependencies like Python, PostgreSQL, etc.

  4. Upload Django Project: You need to upload your Django project to the VM. You can use SCP (Secure Copy Protocol) to transfer the files from your local machine to the VM.

    For example, to copy the entire project directory to the VM, use the following command (replace your-vm-ip and your-vm-username with your VM's IP address and username):

    scp -r /path/to/your/django/project your-vm-username@your-vm-ip:/path/on/vm/
  5. Set Up a Virtual Environment: Once the project is uploaded, navigate to the project directory on the VM and create a virtual environment to isolate the project dependencies:

    cd /path/on/vm/your-django-project python3 -m venv venv source venv/bin/activate
  6. Install Project Dependencies: Install the project dependencies from the requirements.txt file:

    pip install -r requirements.txt
  7. Configure Database: If your Django project uses a database, configure the database settings in your project's file to use the appropriate database credentials.

  8. Collect Static Files: If your project uses static files (CSS, JavaScript, etc.), collect them into a single directory using the following command:

    python collectstatic
  9. Run Django Server: Start the Django development server to test if everything is working as expected:

    python runserver
  10. Set Up a Web Server (Optional): For production use, it's recommended to set up a web server like Nginx or Apache to serve the Django application. Configure the web server to reverse proxy requests to the Django development server.

  11. Set Up a Process Manager (Optional): For production use, consider using a process manager like Gunicorn or uWSGI to manage the Django application process.

  12. Open Ports: Ensure that port 8000 (or whichever port you are using for the Django development server) is open in the VM's security group to allow incoming traffic.

  13. Domain Name and SSL (Optional): If you have a domain name, point it to your VM's IP address. For HTTPS, obtain an SSL certificate and configure the web server to use it.

After completing these steps, your Django website should be accessible on the VM's IP address and port 8000 (or the port you configured). For production use, make sure to secure your server, configure firewall rules, and follow best practices to ensure the server's stability and security.

Have questions or queries?
Get in Touch