Trying to deploy Django on SiteGround - django

I am trying to deploy a Django app on Siteground through SSH. I have transferred all the files through Filezilla. Everything is setup.
I have developed several apps on AWS using ubuntu. But in siteground Fedora OS is provided in SSH, I am not familiar with that much. I can't have superuser privileges.
Running my Django server on port 8000:
python manage.py runserver 0.0.0.0:8000
Host name is already added in ALLOWED_HOST of setting.py:
ALLOWED_HOSTS = ["himeshp7.sg-host.com","*"]
The server is running in SSH, but I am unable to open my web app on the browser. In AWS we get the option to enable ports in Security Groups, but I couldn't find anything like that on Siteground, I also talked with customer care but they are telling to upgrade, I still doubt that if it will work or not after that as I couldn't find anything proper for deploying Django on Siteground.

You need to add your server ip address to ALLOWED_HOSTS and do python manage.py runserver <your_server_ip_address>:8000 to simply run your app in Debug mode. (Replace <your_server_ip_address>). You can then access your app over port 8000
To host your app in production you need to do further more than running the app through command like installing WSGI HTTP Server, configuring to run your app on port 80 or some other port, etc.
Amazon AWS has UI for most of the things so that you could easily enable ports and such other things. This is not the case of other hosting providers.
Unless you don't have the sudo privileges there are no options to run Django app in shared hosting. Hosting providers that gives SSH/terminal access for shared hosting will not give sudo privileges for security reasons. You should be having a VPS/Dedicated account for that which costs higher to have higher control over your server.
Why do I need sudo privileges ?
You may need to install additional packages/dependencies.
To add additional apache/nginx config for your domain. etc
Otherwise you can go for hosting providers where they provide additonal "Setup Python App" in "Software" section in CPanel for their Shared Hosting Plans. You don't need to worry about server configuration.
There are many providers that gives this option in their Shared Hosting. Two of such providers that I know of:
namecheap refer
a2hosting refer
Based on the exp that I had on deploying python app on Hostgator VPS link.

Related

How to run a Django's application server on a VPS server

I have an application that should run via VPS terminal-based so that the web app can be online permanently.
The command: python manage.py runserver 173.249.8.237:8000 should be executed via the VPS terminal because when I use putty via my laptop, whenever I switch off my putty software via my laptop, the application won't be accessible.
Please, suggest to me a way open a terminal in order to run the Django application server.
Or, is there any method that can allow me to my Django web application on VPS?
Thanks in advence
Don't do that.
runserver according Django Docs
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone
through security audits or performance tests. (And that’s how it’s
gonna stay. We’re in the business of making web frameworks, not web
servers, so improving this server to be able to handle a production
environment is outside the scope of Django.)
You need to configure your Django application to run in production environments. You change choose docker for that.
Or simple running with gunicorn.
Access your VPS through SSH or Putty.
Copy your application code inside VPS
Configure your application to run with gunicorn or docker
Access your VPS address in your browser.
And turn of the DEBUG mode, by setting DEBUG=False

cannot access a development server on a server im ssh'd into

I am deploying a django app from a Centos server. When i do a python3.6 manage.py runserver 8000 command it starts a development server no problem. I am not able to access this page from my local computer to test it.
so the steps i take are: i ssh into the server by doing ssh <user>#url.com and then run the dev server with the above command. I then go to the browser on my laptop and type url.com:8000 and will come up with Unable to connect
I also have this problem when running my apache server for production. i would have no problems putting up the server on the server im ssh'd into but cannot access the webpage.
I know this is very little information to go on but does this sound like a server side issue at url.com? Should i be contacting the administrators with this, or is this something on my end possibly?
Maybe i need to configure the address my settings.py in my django app?
You probably want to run it so it listens on any interface. From the documentation:
Note that the default IP address, 127.0.0.1, is not accessible from
other machines on your network. To make your development server
viewable to other machines on the network, use its own IP address
(e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).
By example, you should start the server with
python3.6 manage.py runserver 0.0.0.0:8000
In general, it is probably not wise to keep such a thing running on the web, particularly with debug on. From the same documentation link:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone
through security audits or performance tests. (And that’s how it’s
gonna stay. We’re in the business of making Web frameworks, not Web
servers, so improving this server to be able to handle a production
environment is outside the scope of Django.)

How to configure Elastic IP with django app in aws?

I am building an app using django in EC2-ubuntu and i have associated Elastic ip with my instance.
i have done following steps :
1. first created instance of ubuntu in ec2 free tier.
2. installed python.
3. installed pip.
4. installed django.
5. create a django project using django-admin startproject.
6. run server using these commads python manage.py runserver 0.0.0.0:80
7. created an elastic ip and associated to the instance.
8. configure security inbound settings with http 0.0.0.0:80 address.
9. able to ping my project using any browser.
But the problem is when i am closing my putty session where i supplied runserver command, django project is also stopped. i did not stop it manually.
Please, help me to keep on running after closing putty session as well.
Thanks,
Kripa Sharma
Take a look at this Answer
I highly recommend that you start using Elastic Beanstalk (Python instance) to take care of all these steps for you. Very simple to setup, and no need to worry about any of the steps you listed.
You can use this instruction to see how you can deploy a Django app in less than 5 minutes.
The problem
You are trying to persist the debug server for a remotely deployed application.
You probably need to review the runserver command documentation. Here are the relevant parts:
django-admin runserver [addrport]
Starts a lightweight development Web server on the local machine. By default, the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an IP address and port number explicitly.
...
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
A webserver
Having skimmed the above docs, you may want to look at "How to deploy with WSGI" section, which gives a few recommendations for commonly used Web servers. My favorite, Gunicorn, includes a usage example:
$ pip install gunicorn
$ gunicorn myproject.wsgi
Having decided, and installed a webserver, you'd need to "daemonize" it and expose it to the world.
The former is usually done by creating a service on your OS, for ubuntu it would be either upstart or systemd depending on the version. Gunicorn docs have examples for both.
The latter is usually achieved with an http-server/proxy such as nginx or apache httpd. And again, Gunicorn has an example for us.
You can see why I like it so much ☺️
Epilogue
While technically possible to run the debug server as a service or even in a terminal multiplexer such as GNU screen or tmux, it's not a recommended or stable long term solution.
That said, these are very useful to know about, so read on the above tools and learn to use them, since they would be invaluable to have in your toolset in the future, for example to avoid accidentally terminating a long running command (such as migration), etc.

Setup django test server with port forwarding

I want to setup django test server so it can be accessed through web address (mainly for facebook testing). For this I'm using the no-ip service wich works fine with apache. But when I try starting the test server on port 80 access from the same web URL gives Problem loading page.
I've already concluded that the router is properly configured (port forwarding works with apache) and that the test server is running locally.
So what should I do? Do you have any suggestions about developing django project with facebook integration?
Thanks!
I would also recommend using the localtunnel Ruby gem. It will provide you with a publicly accessible web address that routes requests to a locally bound port:
$ python manage.py runserver
$ localtunnel 8000
This localtunnel service is brought to you by Twilio.
Port 8000 is now publicly accessible from http://qw1e3.localtunnel.com ...
I prefer it over other approaches, especially in instances where even for development work your application is required to be publicly accessible due to some remote services that your using, in which case you can programmatically instantiate localtunnel and do all the necessary configurations, without having to document it or go through the pain of performing it manually over and over again.
Are you running python manage.py runserver?
Try doing python manage.py runserver 192.168.1.2:80 (or whatever your IP is instead of 192.168.1.2).

Why is flask app throwing an error in cpanel

Can anyone let me know how to deploy a flask app on a personal website using CPanel
I have tried running it through the virtualenv but did not work
Flask is a micro framework that runs in a Python instance, and not as a set of files that are served from a web server, like HTML or PHP. Most likely you will need another hosting provider that hosts web applications like Heroku or use a VPS instead.
On the other hand, most shared hosting providers do not allow you to install custom libraries that need to be compiled.