GNOME – Django, MySQL & PyCharm


At first update your system.

sudo apt-get update
sudo apt-get upgrade

install PyCharm

sudo snap install pycharm-professional --classic

create project

Create a new django project in PyCharm. In case PyCharm was not able to create the virtual environment, you might need to install the Python package for it. Probably pip is missing then too.

sudo apt install python3-pip
sudo pip install virtualenv

Run the configuration and check:

Change now the host in the run/debug configurations to “”.

In the add the IP to the allowed hosts.


In case you are using multiple ways to access the website, add the other IP’s too.

open ports

As the website should be visible from outside we need to open the ports.

sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 8000

Restart Django server.

router and DNS

It depends a little bit on your provider and your setup at home. Usually you can activate a remote access to your router and forward the port 80 to 8000. To use a URL create an A Record to forward the request from your URL to your personal IP.

Now you should be able to access the website through your own URL.

MySQL database & apache

sudo apt-get install mysql-server
sudo mysql_secure_installation
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

Check the status of both.

sudo service mysql status
sudo systemctl status apache2

Add this to your “etc/apache2/apache2.conf”:

Include /etc/phpmyadmin/apache.conf

Change the password of the root user:

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '[PASSWORD]';

Now phpmyadmin should be reachable through “localhost/phpmyadmin”.

Login and create a database with your projects name.

Add this to your instead of the existing database configuration:

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': '[PROJECTNAME]',
        'USER': 'root',
        'PASSWORD': '[PASSWORD]',
        'HOST': '',
        'PORT': '3306',
        'OPTIONS': {"init_command": "SET foreign_key_checks = 0;"},

Do not use localhost as this won’t work.

Now in PyCharm install:

pip install pymysql

And add:

import pymysql

to your in the project folder.

The database is now used through the root user. You can change this by creating a new user in phpmyadmin and adjusting the database settings in your django project. Also you should protect the root user with a password.

autostart server

As your server should be running all the time it needs to autostart.

Create a file containing the following code and safe it as “” in the PycharmProjects folder.

cd /home/[USERNAME]/PycharmProjects/[PROJECTNAME]
source /home/[USERNAME]/PycharmProjects/[PROJECTNAME]/venv/bin/activate
python /home/[USERNAME]/PycharmProjects/[PROJECTNAME]/ runserver &
exit 0

Check if it is working by using:

sudo -u [USERNAME] /home/[USERNAME]/PycharmProjects/

Now we add the script to the crontabs to be executed on startup.

sudo crontab -e


@reboot /home/[USERNAME]/PycharmProjects/

to the file.


Watch out that the DEBUG mode is still activated in your Drango project (


Enable SSH:

sudo apt install openssh-server

No further actions needed.