Linode/Django Can't see site when I runserver at ip:8000 - django

I had started a fresh linode running ubuntu 19.04 and the first time I used the directions at:
https://www.rosehosting.com/blog/how-to-install-mezzanine-cms-on-ubuntu-18-04/
To install Mezzanine CMS it worked just fine, I could run the runserver command and see the django website. Eventually it started giving me a problem after trying 50 ways to deploy the site using apache and mod_wsgi.
I gave up and rebuilt the server and then still couldn't see the new install at the IP when I ran run server. I figured maybe it was because I accidentally installed some things using "python" and others with "python3" so I rebuilt the server.
This third time I followed the direction perfectly, the only difference is I didn't install a mysql server just kept the default SQLlite server and created a DB and Django Superuser.
I have added my ip as a host in settings.py and local_settings.py
I have already ran makemigrations and migrate
I did check to see if maybe the IP had changed when I rebuilt, it hadn't
My local environment on my laptop works fine, just not the linode
Any suggestions on anything I'm missing?

Deployment Guide
Step 1 (Installation)
Install apache2 mod_wsgi
Install virtualenv
Install virtualenv
Install Nginx for asynchronous event-driven approach to handle multiple client requests
Install mysql
sudo apt-get update
sudo apt-get install python3-pip python3-dev apache2 libapache2-mod-wsgi-py3
sudo apt-get install virtualenv ufw
sudo apt-get install nginx
sudo apt-get install mysql-server libmysqlclient-dev
sudo mysql_secure_installation
Step 2 (Apache & Hostname & User)
Set hostname and add it into /etc/hosts with hostname and your Server IP
Create new user and give add to the group sudo for safety
sudo adduser username
sudo usermod -aG sudo
Enable SSH authentication for login & Edit default port of ssh in /etc/ssh/sshd_config. https://askubuntu.com/questions/1074034/not-able-to-change-ssh-port-on-ubuntu-18-04-1-lts
Edit /etc/apache2/site-availabledefault-000.conf for your new Django configuration
Step 3 (Firewall)
sudo ufw allow 8000
sudo ufw allow http
sudo ufw allow ssh
sudo ufw default allow outgoing
sudo ufw default deny incoming
Enable all other required port numbers
ssh sudo ufw enable
Step 4 (Django configuration)
Chown static and media forlders and edit it's permission recursively
Add allowed host in settings.py
Checkout deployment checklist in django official website and do it.
Step 5 (Please checkout)
For apache configuration please visit https://pythonprogramming.net/deploying-to-server-django-tutorial/
Edit the path given in your apache configuration (path for WSGI Script,python-path, python-home ) if any errors found like Internal server error, miss configuration etc
For reference of python-home path please refer Get virtualenv's bin folder path from script
You can also add python-path to WSGIDaemonProcess
Additionally, you can visit puttygen for public and private key generation to login through SSH

For this particular problem turned out I just needed to suddenly bind dev server to 0.0.0.0
the command to do so was
python manage.py runserver 0.0.0.0:8000
Rinshans answers is definetley the details for deployment, I've followed those steps just kept making some mistake in the config and wsgi scripts. I'm going to try deploying with Gunicorn or use the Fabric self-deployment tools built in to Mezzanine CMS, just haven't done so yet.

Related

How to Deploy Multiple Django Apps on Single server using Ngnix & GUnicorn?

I am trying to Deploy Two Django apps with single AWS EC2 Instance having same IP.
But it always failed when I have added the second App.sock and test Supervisor.
I fond some body asked similar question before. but Not answered properly, and my use case is little different. ( Run multiple django project with nginx and gunicorn )
I have followed these steps:
.
Cloned my project from Git *
pip install -r requiernments.txt
pip3 install gunicorn
sudo apt-get install nginx -y
sudo apt-get install supervisor -y
cd /etc/supervisor/conf.d
sudo touch testapp2.conf
sudo nano testapp2.conf
Updated config file same as below
[program:gunicorn]
directory=/home/ubuntu/projects/testapp2/testerapp
command=/home/ubuntu/projects/testapp2/venv/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/projects/testapp2/testerapp/app.sock testerapp.wsgi:application
autostart=true
autorestart=true
stderr_logfile=/home/ubuntu/projects/testapp2/log/gunicorn.err.log
stdout_logfile=/home/ubuntu/projects/testapp2/log/gunicorn.out.log
[group:guni]
programs:gunicorn
*----------
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl status
The below steps will work and Site available on browser if there is only One configuration above. But when i have added an additional configuration, it shows 502 Bad Gateway on the Browser. Please help me to solve this issue.
You can add one more config file in supervisor conf.d and use different port numbers in the different Django apps.

Move Redmine Server whilst keeping external database

I currently have redmine running on an nginx server. The actual MySQL database is on an external server and everything is working fine.
Now I would like to move it to an Apache Server on a different machine, ideally without changing/moving the database.
Is this possible, or do I always need to export/import the database regardless? Happy to stick with the same version of redmine (in my case 4.0.1., Ruby 2.5.1-p57, Rails 5.2.2, no plugins installed). If positive, what are the conditions on Ruby/Rails versions? Do they all have to be exactly what I had on the old one?
Database scheme is not affected by ruby version, only by Redmine's version, because new versions might add or remove stuff in database.
So in your case, copy-pasting your old Redmine to new server should work.
However you must ensure that new Redmine server (probably new IP) has proper privileges to access MySQL database.
And you must follow upgrade tutorial, because your new server needs to pull and install Ruby Gems, clear old cache from tmp folder etc...
https://www.redmine.org/projects/redmine/wiki/RedmineUpgrade
Aleksander's answers gave me confidence that it can be done, but I ended up persevering with my initial approach until I got that working rather than changing to his proposals.
I am afraid that I lost track of the sources for various bits, its primarily from the redmine help pages.
My complete solution was
sudo apt update
sudo apt upgrade
sudo apt install build-essential libmysqlclient-dev imagemagick libmagickwand-dev ruby-full
sudo apt install apache2 libapache2-mod-passenger
sudo gem update
sudo gem install bundler
sudo curl -L https://www.redmine.org/releases/redmine-4.0.1.tar.gz -o /tmp/redmine.tar.gz
sudo tar zxf /tmp/redmine.tar.gz
sudo mv redmine-4.0.1 /opt/redmine
sudo touch /opt/redmine/Gemfile.lock
sudo chown www-data:www-data /opt/redmine/Gemfile.lock
sudo chmod a+w /opt/redmine/Gemfile.lock
sudo cp /opt/redmine/config/database.yml.example /opt/redmine/config/database.yml
sudo ln -s /opt/redmine/public /var/www/html/redmine
cd /opt/redmine
mkdir -p /opt/redmine/app/assets/config && echo '{}' > /opt/redmine/app/assets/config/manifest.js
bundle install
bundle exec rake generate_secret_token
Note the manifest line above only applies to my particular redmine version which was incompatible with later sprockets versions. Also note that changing the permissions a+w is possibly excessive, but I struggled with permissions otherwise.
Then we have to do a few more manual tweaks. Open the file with your text editor:
sudo nano /opt/redmine/config/database.yml
and change production to be the following
production:
adapter: mysql2
database: myredminedatabasename
host: mysqlserver.somewhere.com
username: dbusername
password: "dbpassword"
encoding: utf8
Need to add the PassengerDefaultUser line to /etc/apache2/mods-available/passenger.conf (leave the other two lines the same even if slightly different)
<IfModule mod_passenger.c>
PassengerDefaultUser www-data
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
</IfModule>
Change /etc/apache2/sites-available/000-default.conf to insert the following with the other sections so that apache knows to follow the symlink into Rails. Also note the first line setting DocumentRoot, which was oone of my personal stumbling blocks.
DocumentRoot /var/www/html/redmine
<Directory /var/www/html/redmine>
RailsBaseURI /redmine
PassengerResolveSymlinksInDocumentRoot on
</Directory>
We also need to copy the contents of files folder from /opt/redmine/files on older server to the new server in same location.
Also copy the email settings across in /opt/redmine/config/configuration.yml.
Then restart your server and it should be working.

Gunicorn not working on Amazon ec2 server

I am trying to deploy a django website on an aws ec2 instance (ubuntu 18.04) following this tutorial that is consistent with other online resources. Everything is working fine but there is some issue with gunicorn. The worker doesn't seem to boot.
I figured there was something wrong with my installation and I tried uninstalling and installing with different commands-
inisde my virtualenv with
pip install gunicorn
and
sudo -H pip install gunicorn
I even physically deleted all gunicorn files and reinstalled gunicorn but its always the same. Where have I gone wrong?
p.s: I had initially done sudo apt-get
From the screenshot you attached, it seems that gunicorn is installed correctly, but perhaps you have not passed a configuration file. The command to run gunicorn with a configuration is
gunicorn -c /path/to/gunicorn.conf.py myapp.wsgi:application

superset server not running

I am following the below instructions to install superset. In this step "superset runserver -d" getting an error below. How do I fix this issue. Thanks
[DEPRECATED] As of Flask >=1.0.0, this command is no longer supported, please use flask run instead, as documented in our CONTRIBUTING.md
[example]
flask run -p 8080 --with-threads --reload --debugger
# Install superset
pip install superset
# Create an admin user (you will be prompted to set a username, first and last name before setting a password)
fabmanager create-admin --app superset
# Initialize the database
superset db upgrade
# Load some data to play with
superset load_examples
# Create default roles and permissions
superset init
# To start a development web server on port 8088, use -p to bind to another port
superset runserver -d
Yesterday commit https://github.com/apache/incubator-superset/pull/5966 fixed similiar issue with docker install. Try to clone repo from scratch and go trough the following steps:
git clone https://github.com/apache/incubator-superset/
cd incubator-superset/contrib/docker
# prefix with SUPERSET_LOAD_EXAMPLES=yes to load examples:
docker-compose run --rm superset ./docker-init.sh
# you can run this command everytime you need to start superset now:
docker-compose up
New installation doc: https://github.com/apache/incubator-superset/blob/master/docs/installation.rst
Try the below steps:
$ pip install flask==1.0.0
$ pip install sqlalchemy==1.2.18
$ pip uninstall pandas
$ pip install pandas==0.23.4

How to install xsendfile for httpd 2.4 on amazon linux ami?

How to install xsendfile for httpd 2.4 on amazon linux ami? Default package repositories from amazon and epel do not have a package for httpd 2.4, only for httpd 2.2. I would prefer not to compile the module if possible. Thank you.
I'm not aware of a quick Yum/apt-get style install for X-sendfile for Apache24 on an EC2 instance at the time of writing this answer, however compiling and installing the module your self is super easy:
Prepwork
Download mod_xsendfile.c from download section the link below
https://tn123.org/mod_xsendfile/
Install GCC for compiling
sudo yum install gcc
We need httpd24-devel for apxs
sudo yum install httpd24-devel.x86_64
Compiling and installation
sudo apxs -cia mod_xsendfile.c
Edit your http.conf add
<IfModule mod_xsendfile.c>
XSendFile on
XSendFilePath /home/path/to/private/files/to/serve/
</IfModule>
Restart Apache24
sudo service httpd restart
Done !
Check your phpinfo or apache_modules() to confirm all good and modify settings to your liking.
Enjoy efficient downloads :)