Setup Development Environment¶
If you would like any help setting up these environments, why not join our discord - https://discord.gg/64uhRztS6n
This environment setup is designed for UAT/DEV environments on server environments. The settings.py file will have a unique secret_key, and the settings.py file can be customized without any chance of an accidently upload into source.
These instructions will help you install a development environment. Setup is slightly different to a production environment.
It is recommended to install NearBeach on a Long Term Support (LTS) version of Django. Security fixes/patches are applied for a longer period of time, helping keep your server secure.
NearBeach currently supports the following Django versions;
- Django Version 3.2+
More information about upgrading Django can be found found in the Django Documentation
The following instructions are for Ubuntu 18.04. If you are using a different operating system, modify the instructions to suit that operating system.
Download Git Repository¶
- In a terminal, navigate to your project development folder
- Use Git to download NearBeach source code
git clone https://github.com/robotichead/NearBeach
- First update and upgrade the system so you are working with the latest packages;
sudo apt-get update && sudo apt-get upgrade -y
- Install the required system libraries for Django and NearBeach to working
sudo apt install python3-dev curl build-essential python3-setuptools shared-mime-info libjpeg-dev zlib1g-dev
- Install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo python3 get-pip.py
- After installing the required packages, you will need to update pip
sudo pip3 install --upgrade pip
- Once pip is upgraded, you will need to create a virtual environment
sudo pip3 install virtualenv
- Create your own virtual environment for python
This will create a directory called “<<project_environment>>”, this will store NearBeach’s libraries for python
- Activate the virtual environment using the following command
You terminal prompt will change to indicate that it is working in the virtual environment now. It should look like the following(<<project_environment>>)user@computer:
- Install Django
pip install django
- Create your project
djangoadmin startproject <<django_project>>
Please do NOT call the <<django_project>> NearBeach, or any variation of it.
- Adjust the project’s settings to allow debugging and accept ALL allowed hosts
- Change the following lines to reflect the following
This will allow us to test the web server.
Save the settings file and exit
- Run the following command to see if Django is running
python3 ./manage.py runserver
If the server runs fine - then we can proceed.
- Symbolic link in NearBeach’s source code
ln -s /<<project-dev-folder>>/NearBeach/NearBeach /<<project-dev-folder>>/<<django_project>>
This code will place the core NearBeach code into the Django’s project directory.
- Navigate to your project’s folder
$ cd <<django_project_location>>
- Install all required python files using pip
pip3 install -r ./NearBeach/requirements.txt
- Edit the project’s settings.py to include NearBeach
$ nano ./<<django_project>>/<<django_project>/settings.py
- Add the following line to the top of “INSTALLED_APPS” section
Now save the document
- Email - optional however required for resetting passwords
$ nano ./<<project name>>/settings.py
Add the following lines of code into the settings.pyEMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_USE_TLS = True EMAIL_HOST = '<< your email host >>' EMAIL_PORT = 25 EMAIL_HOST_USER = '<< your username >>' EMAIL_HOST_PASSWORD = '<< your password >>' DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
- Private Documents
nano ./<<project name>>/settings.py
Add the following lines of code into the settings.pyPRIVATE_MEDIA_URL = '/private/' #Can change if DEBUG: # dev import os PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) PRIVATE_MEDIA_ROOT = os.path.join(PROJECT_PATH, 'private') PRIVATE_MEDIA_SERVER = 'DefaultServer' else: # prod PRIVATE_MEDIA_ROOT = '<< private documents location >>' PRIVATE_MEDIA_SERVER = 'ApacheXSendfileServer'
The following redundant code will need to be used at the moment.STATIC_URL = '/static/' STATIC_ROOT= os.path.join(BASE_DIR,'static/') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
- Edit the project’s URL.py to include NearBeach
Please make sure that the following import in included at the top of the filefrom django.urls import path, include
Either of the following can be entered into the “urlpatterns” sectionpath('', include('NearBeach.urls')), path('tinymce/', include('tinymce.urls')), path('select2/', include('django_select2.urls')),
- Create Database/Migrations
The database will need to be setup. Please note by default Django uses sqlite3, however it is possible to setup NearBeach to use a mysql database.python ./manage.py migrate python ./manage.py migrate NearBeach
If you have setup NearBeach with an SQLite database, you will need to change it’s permissions so nginx can access itsudo chmod 7777 ./db.sqlite
- Create superuser
A superuser will need to be created. This superuser will be able to enter the ADMIN site of Django, which from there will be able to do administration items.python ./manage.py createsuperuser
Enter in the correct details for the superuser
- Collect the static
- Create the private media folder
$ mkdir ./private_media/
The NearBeach development environment should now be setup on your local.
The first user to log in will automatically get administration permissions. It is recommended to get the system admin to log in first before importing any user data from other sources. This also allows the admin to setup groups and permissions.