This would mean we have to update the ALLOWED_HOSTS variable in our project settings.py file each time the IP address changes per reboot. Note that this IP address is temporary and will change each time we reboot the instance. When we first created a Lightsail instance on AWS, we were given an IP address, for example, 192.0.2.143. Obtain a Static IP address for our Django Server If we secure our production server with SSL (a good recommendation), we will need to add the same multiple-project configuration in nf under. Notice the last line that includes the nf file. For example: WSGIScriptAlias /project1 /opt/bitnami/projects/project1/project1/wsgi.py AllowOverride all Require all granted Options FollowSymlinks WSGIScriptAlias /project2 /opt/bitnami/projects/project2/project2/wsgi.py AllowOverride all Require all granted Options FollowSymlinks Include "/opt/bitnami/apache/conf/bitnami/nf" We can extend the bitnami configuration found in /opt/bitnami/apache2/conf/bitnami/nf, to include other projects. Instead of this: os.tdefault("PYTHON_EGG_CACHE", "/opt/bitnami/projects/tutorial/egg_cache") os.tdefault("DJANGO_SETTINGS_MODULE", "ttings")ĭo this: os.environ = "/opt/bitnami/projects/tutorial/egg_cache" os.environ = "ttings" Doing so for multiple projects will lead to unexpected results. If we want to run multiple projects on the same server, it’s best to not set the default DJANGO_SETTINGS_MODULE and PYTHON_EGG_CACHE to point to a particular project. import os import sys ('/opt/bitnami/projects/tutorial') os.tdefault("PYTHON_EGG_CACHE","/opt/bitnami/projects/tutorial/egg_cache") os.tdefault("DJANGO_SETTINGS_MODULE", "ttings") from import get_wsgi_application application = get_wsgi_application() Recall a section of the AWS tutorial that addresses configuring our project wsgi.py file which looks like this. Deploying Multiple Projects On the Same Server I would refer you to this link to change the timezone. It's helpful to align the server timezone with our local timezone to make debugging easier. The Apache server’s default timezone is in UTC. To see if the database error goes away, try reloading the Django app on the browser. For example: $ sudo chmod g+w project_directory project_directory/database_file Make the project root directory and the database file writable by the daemon group. $ sudo chgrp daemon project_directory project_directory/database_fileĢ. Change group ownership of the project root directory and the database file to daemon.To get to the database file, the daemon process also needs the same permissions for the project root directory. To enable the daemon process to read from and write to our default database, we need to configure the read and write permissions to the database file. When we deployed Django on AWS, we were logged in as the user, bitnami. There is also a daemon user and group associated with this process.
daemon as defined by Linux is a service process that operates in the background servicing other processes. Since we ran the apache server as sudo, we will find multiple server processes - One that is owned by root and the others by the user daemon. If we were to locate the apache process on our terminal with ps -ef | grep apache we will see something like this: ps -ef | gre p apache root 26520 1 0 16:17 ? 00:00:00 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/nf daemon 26523 26520 0 16:17 ? 00:00:01 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/nf daemon 26524 26520 0 16:17 ? 00:00:01 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/nf daemon 26525 26520 0 16:17 ? 00:00:01 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/nf daemon 26526 26520 0 16:17 ? 00:00:00 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/nf daemon 26527 26520 0 16:17 ? 00:00:00 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/nf As noted in the AWS tutorial, the command would be: $ sudo /opt/bitnami/ctlscript.sh restart apache Running a production server using Apache requires a different command than python manage.py runserver.
If our project uses a database like mine, we will most likely encounter this error - Attempt to write a readonly database while the DEBUG=True setting is enabled in settings.py. Since the AWS tutorial is for a barebones Django app, it doesn’t provide documentation for apps with databases. Error: Attempt to write a read-only database If we run into any trouble deploying Django that is Bitnami-related, we can find support from Bitnami.