Base server of multiple uses - like IoT - made totally in Python+Django from a maker to makers
The project was totally created to be used in a Raspberry PI board with linux system in order to provide for developers and makers a base django server to change and add their own server with their own requeriments. For this reason, the project has simply a totally python+django backend in order to control the web pages, a full admin page in order to manipulate users and a simple database to record the logins and logouts of users with webpages to view these datas.
- Raspberry PI with linux installed
- Python 3
- pip3
- Django 3
- Apache 2
- Desire to learn and try
Linux:
-
Instaling requirements, downloading and starting project
sudo apt-get install apache2 -y # install apache2 sudo apt-get install libapache2-mod-wsgi-py3 # requirements of apache sudo apt-get install libapache2-mod-wsgi # if using Python2 git clone https://github.com/Wanghley/Raspberry-Home-Server.git djpitime #clone repository cd djpitime virtualenv . -p python3 #start the virtual environment pip3 install -r REQUIREMENTS # install the requiremets of python source bin/activate cd src python manage.py makemigrations python manage.py migrate
-
Settings of Apache2:
sudo nano /etc/apache2/sites-available/000-default.conf
Note: If errors happen with below, just do the following and it will re-install apache
<VirtualHost *:80> ServerName www.example.com ServerAdmin webmaster@localhost Alias /static <PATH TO FOLDER>/djpitime/static <Directory <PATH TO FOLDER>/djpitime/static> Require all granted </Directory> <Directory <PATH TO FOLDER>/djpitime/src/cfehome> <Files wsgi.py> Require all granted </Files> </Directory> WSGIDaemonProcess djpitime python-path=<PATH TO FOLDER>/djpitime/src:<PATH TO FOLDER>/djpitime/lib/<pythonX.Y>/site-packages WSGIProcessGroup djpitime WSGIScriptAlias / <PATH TO FOLDER>/djpitime/src/cfehome/wsgi.py ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
-
Allow use of local database:
sudo adduser $USER www-data sudo chown www-data:www-data /home/$USER/Dev/cfehome sudo chown www-data:www-data /home/$USER/Dev/cfehome/src/db.sqlite3 sudo chmod -R 775 ~/Dev/cfehome # if above fails, try (thanks Mike!): sudo chown -R www-data:www-data ~/Dev/cfehome sudo chown www-data:www-data /home/pi/Dev/cfehome/src
-
Allow use of local IP Address: First of all is get the IP address of your raspberry pi with
ifconfig
then use:sudo nano <PATH TO FOLDER>/djpitime/src/djpitime/settings.py
and find the line: ALLOWED_HOSTS = ['127.0.0.1'] and add yours IP address, like: ALLOWED_HOSTS = ['127.0.0.1','192.168.1.xxx']
-Restart apache2 and have fun!
This project can be used in so many puposes as your need. It can be used since a simple backup server to an IoT server of your smarthouse project.
For more examples and usage, please refer to the [Wiki][wiki].
To develop, follow these steps.
sudo apt-get install apache2 -y # install apache2
sudo apt-get install libapache2-mod-wsgi-py3 # requirements of apache
sudo apt-get install libapache2-mod-wsgi # if using Python2
git clone https://github.com/Wanghley/Raspberry-Home-Server.git djpitime #clone repository
cd djpitime
virtualenv . -p python3 #start the virtual environment
pip3 install -r REQUIREMENTS # install the requiremets of python
source bin/activate
cd src
python manage.py makemigrations
python manage.py migrate
python manage.py runserver # this will start the server in localhost to development purposes
then, start programming in yuor preferred IDE. Keep Coding! ;)
Wanghley Soares Martins – @Wanghley – [email protected]
Distributed under the MIT license. See LICENSE
for more information.
- Fork it (https://github.com/Wanghley/Raspberry-Home-Server/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request