Deploying Django on Oracle Cloud with Ubuntu 22.04 provides an affordable, high-performance hosting solution for developers and startups. When combined with Apache, MySQL, and PhpMyAdmin, this stack offers a powerful and scalable setup for modern web applications.
In this guide, you’ll learn how to configure everything from server provisioning to Django deployment, ensuring your application is production-ready.
Why Use Oracle Cloud Infrastructure (OCI)?
Oracle Cloud is quickly becoming a favorite among developers for the following reasons:
- Free tier with generous limits (up to 4 cores and 24 GB RAM as of 2025).
- High-performance VMs with SSD-based storage.
- Reliable networking and built-in security tools.
- Direct support for popular Linux distributions, including Ubuntu 22.04.
Looking to set up a complete LAMP stack before deploying Django?
How to LAMP Install on Oracle Cloud Ubuntu 22.04 Server
Step 1: Provision a Virtual Machine on Oracle Cloud
- Log in to Oracle Cloud Console: Visit https://cloud.oracle.com and sign in.
- Navigate to Compute > Instances > Create Instance.
- Choose an Image: Select Ubuntu 22.04 Minimal.
- Select Shape: Use VM.Standard.E2.1.Micro for the free tier.
- Add SSH Key: Paste your SSH public key to enable terminal access.
- Launch the instance and note the public IP for SSH and browser access.
Step 2: Update Server & Configure UFW Firewall
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 443 -j ACCEPT
sudo netfilter-persistent save
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo netfilter-persistent save
sudo apt update && sudo apt upgrade -y
sudo ufw allow OpenSSH
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable
Step 3: Install Apache, MySQL, PhpMyAdmin
Install Apache
sudo apt install python3-pip python3-dev libapache2-mod-wsgi-py3 -y
Firewall Settings:
sudo ufw allow 'Apache Full'
sudo ufw enable
Install MySQL
sudo apt install mysql-server libmysqlclient-dev -y
sudo mysql_secure_installation
- In the next screen we will be asked whether we need to setup VALIDATE PASSWORD plugin. We selected no.
- Set the password for the root MySql account.
- Remove anonymous users? We selected yes.
- Disallow root login remotely? We selected no.
- Remove test database and access to it? We chose yes.
- Reload privilege tables now? We again chose yes.
This will prompt you to configure some basic security settings for MySQL.
Create a Django MySQL Database
CREATE DATABASE django_db;
CREATE USER 'django_user'@'localhost' IDENTIFIED BY 'securepassword';
GRANT ALL PRIVILEGES ON django_db.* TO 'django_user'@'localhost';
FLUSH PRIVILEGES;
Install PhpMyAdmin
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl -y
sudo phpenmod mbstring
sudo systemctl restart apache2
During setup, select Apache2 and enable database config.
Step 4: Install Python, Django & Virtual Environment
sudo apt install python3 python3-pip python3-dev python3-venv -y
Set Up Django App
sudo mkdir /var/www/mywebcode.com
sudo nano /var/www/mywebcode.com/index.html
<html>
<head>
<title>mywebcode.com</title>
</head>
<body>
<h1>Welcome to www.mywebcode.com website</h1>
</body>
</html>
First, ensure virtualenv
is installed. You can install it using pip
:
sudo pip3 install virtualenv
cd /var/www/mywebcode.com
virtualenv gvenv
or
sundo python3 -m venv gvenv
Activate the virtual environment:
source gvenv/bin/activate
Install Django and Other Dependencies
With the virtual environment activated, install Django and other required packages:
pip install mysqlclient for MySQL Database connections in Django app solve error for mysqlclient
sudo add-apt-repository universe
sudo apt-get install net-tools -y
sudo apt-get install python3 -y
sudo apt-get install python3-pip -y
pip install pkgconfig
sudo apt-get install pkg-config -y
pip install mysqlclient
You can also install any other dependencies listed in your requirements.txt
file:
pip install -r requirements.txt
Step 6: Deploy Django App with Apache
Adjust Apache Configuration to Use the Virtual Environment
Ensure your Apache configuration file points to the correct virtual environment. Open your Apache configuration file
Apache Virtual Host Configuration
sudo nano /etc/apache2/sites-available/mywebcode.com.conf
Ensure the WSGIDaemonProcess
directive points to the virtual environment you created:
Understood. Let’s proceed with the deployment instructions for your Django project named dydevops
but with the project directory named mywebcode.com
.
Paste the following:
<VirtualHost *:80>
ServerAdmin admin@mywebcode.com
ServerName mywebcode.com
ServerAlias www.mywebcode.com
DocumentRoot /var/www/mywebcode.com
Alias /media/ /var/www/mywebcode.com/media/
Alias /static /var/www/mywebcode.com/static
<Directory /var/www/mywebcode.com/media/>
Require all granted
</Directory>
<Directory /var/www/mywebcode.com/static>
Require all granted
</Directory>
<Directory /var/www/mywebcode.com/dydevops>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess dydevops python-path=/var/www/mywebcode.com python-home=/var/www/mywebcode.com/gvenv
WSGIProcessGroup dydevops
WSGIScriptAlias / /var/www/mywebcode.com/dydevops/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Restart Apache
After configuring Apache to use the virtual environment, restart Apache to apply the changes:
sudo systemctl restart apache2
Check TEMPLATES
Setting in settings.py
Ensure that your TEMPLATES
setting in settings.py
is correctly configured to look for templates in the appropriate directories. Here is an example configuration:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Enable Site and Restart Apache
sudo a2ensite mywebcode.com.conf
sudo a2enmod wsgi
sudo systemctl restart apache2
Possible Deployment Issues
To avoid deployment errors, we will take following actions:
Add allowed host, release media folder, run collectstatic and create requirements.txt from the local project.
ALLOWED_HOSTS = ['SERVER_IP_ADDRESS', 'localhost', '127.0.0.1']
Remove 'media' from .gitignore file
python manage.py collectstatic
pip freeze > requirements.txt
Clone your Django project:
Navigate to the directory where you want to store your project
cd /var/www/mywebcode.com
upload Your project using filezilla

Additional Considerations
Set up a virtual environment for your Django project:
source gvenv/bin/activate
pip install -r requirements.txt
Step 5: Configure Django for MySQL
In myproject/settings.py
, update DATABASES
:
Configure Django to use MySQL:
Edit your settings.py
file to configure the database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mywebcode',
'USER': 'dydevops',
'PASSWORD': 'your_password',
'HOST': 'localhost',
'PORT': '3306',
}
}
Configure Django settings for production (e.g., DEBUG = False
, configure ALLOWED_HOSTS
, set up proper logging, etc.).
Secure your application by enabling HTTPS with a tool like Let’s Encrypt:
Step 7: Enable HTTPS with Let’s Encrypt SSL
sudo service apache2 restart
sudo iptables -save >/etc/iptables/rules.v4
sudo apt install certbot
sudo mkdir /var/www/mywebcode.com/.well-known
sudo chown -R ubuntu /var/www/mywebcode.com
sudo charp www-data/var/www/mywebcode.com
sudo chmod g+s /var/www/mywebcode.com
sudo apt install certbot python3-certbot-apache
sudo certbot --apache
or
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Auto-renewal check:
sudo certbot renew --dry-run
Following these steps should help you deploy your Django application named dydevops
in the mywebcode.com
directory on an Ubuntu server in Oracle Cloud Infrastructure using MySQL, Apache, and PHPMyAdmin.
python manage.py makemigrations
python manage.py migrate
Update CSRF_TRUSTED_ORIGINS
Ensure CSRF_TRUSTED_ORIGINS
is correctly set in your settings.py
:
# settings.py
CSRF_TRUSTED_ORIGINS = [
'https://www.mywebcode.com',
]
ALLOWED_HOSTS = ['www.mywebcode.com','mywebcode.com']
Step 8: Setup Apache2 with mod_wsgi
Create a WSGI file for your project:
Create /path/to/mywebcode.com/dydevops/wsgi.py
:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dydevops.settings')
application = get_wsgi_application()
Permissions:
sudo chown -R ubuntu /var/www/mywebcode.com
sudo chmod -R 755 /var/www/mywebcode.com
sudo chmod -R 777 /var/www/mywebcode.com
sudo chown -R www-data:www-data /var/www/mywebcode.com
sudo chmod 664 /var/www/mywebcode.com/media/
sudo chmod 775 /var/www/mywebcode.com/media/
sudo chown www-data:www-data /var/www/mywebcode.com/media/
sudo chown -R www-data:www-data /var/www/mywebcode.com/media/
Step 8: Access PhpMyAdmin and Django
- PhpMyAdmin:
http://yourdomain.com/phpmyadmin
- Django App:
http://yourdomain.com
- Admin Panel:
http://yourdomain.com/admin
Bonus Tips for Production
- Set
DEBUG = False
insettings.py
. - Use
ALLOWED_HOSTS = ['yourdomain.com']
. - Enable HTTPS with secure cookies.
- Use a gunicorn+Nginx setup for high performance if preferred.
Conclusion
By following this complete guide, you’ve successfully deployed a Django application on Oracle Cloud using Apache, MySQL, and PhpMyAdmin on Ubuntu 22.04. This stack ensures performance, scalability, and security for your web applications.