Questions about Deploying django for production using apache and mod_wsgi.

38 views
Skip to first unread message

Bruce Whealton

unread,
May 26, 2016, 2:12:45 PM5/26/16
to Django users
Hello all,
        I have a few questions of which I am not finding answers.
1) If I export my development db (Postgresql) and then import it into production database,
won't I be pulling in a very weak password that I used for development?  I guess I can
just change that.
2) Should I export all the content and structure from my development server to my
production server?  Or should I just create the database connection and then run migrations and
then create the data content on the production server?  Obviously, my development server has
minimal content.

3) Should I just upload the other packages that I installed with pip on my development server or
should I instead run pip install on the production server to get all the packages needed on the
production server?  

4) Is it a best practice ( continuing from #3) to create a requirement file and use that to install
with pip all the packages, as opposed to uploading the packages from development to production?  
Note: I am developing on Ubuntu but deploying to Centos.  

5) I suppose, even if I had a Centos development environment, I would still want to install the required
packages on the production server instead of just uploading everything.

Regarding #5, I am liking Python better than what I have used for some time, PHP based application
development.  However, for the longest time, things were much simpler with php in that most php code is
just text and so there isn't the notion of "installing" a package.  One could expect things to work fine
if one just uploaded the site from development to production (perhaps certain new OO features are changing
this situation for php sites, e.g. the use of autoloaders but that's another topic).

6) Is there anything else, in addition to the top level assets (with js/css) that I would want apache to serve directly
versus going through mod_wsgi?  It seems like I read something to this effect relating to parts of the admin, 
that need to be served directly by apache.  I could be wrong.  

Thanks in advance for any help,
Bruce  

P.S. If anyone wants to develop a course on udemy.com on a python framework, please don't develop with
sqlite3 since we won't use that in production and please discuss deployment on a server besides 
something like pythonanywhere.com.  The issues of setting things up on one's own vps server are not 
trivial at all.  (smile).

Gergely Polonkai

unread,
May 26, 2016, 4:07:57 PM5/26/16
to Django users


On May 26, 2016 20:12, "Bruce Whealton" <futurewavewe...@gmail.com> wrote:
>
> Hello all,
>         I have a few questions of which I am not finding answers.
> 1) If I export my development db (Postgresql) and then import it into production database,
> won't I be pulling in a very weak password that I used for development?  I guess I can
> just change that.

Yes you can, and yes, you will. I usually start prod with an empn]ty DB, I consider that safer.

> 2) Should I export all the content and structure from my development server to my
> production server?  Or should I just create the database connection and then run migrations and
> then create the data content on the production server?  Obviously, my development server has
> minimal content.

See my previous answer. If your dev data is production-ready, I don’t see the downside though.

>
> 3) Should I just upload the other packages that I installed with pip on my development server or
> should I instead run pip install on the production server to get all the packages needed on the
> production server?  

If you use virtualenv, you should use pip install. I suggest creating a requirements.txt file (you can create one with pip freeze) and update it regularly.

>
> 4) Is it a best practice ( continuing from #3) to create a requirement file and use that to install
> with pip all the packages, as opposed to uploading the packages from development to production?  
> Note: I am developing on Ubuntu but deploying to Centos.  

See previous answer.

>
> 5) I suppose, even if I had a Centos development environment, I would still want to install the required
> packages on the production server instead of just uploading everything.
>
> Regarding #5, I am liking Python better than what I have used for some time, PHP based application
> development.  However, for the longest time, things were much simpler with php in that most php code is
> just text and so there isn't the notion of "installing" a package.  One could expect things to work fine
> if one just uploaded the site from development to production (perhaps certain new OO features are changing
> this situation for php sites, e.g. the use of autoloaders but that's another topic).

PHP has its package system, too, it is called composer. It also has binary modules (although they require much more effort on the server side)

>
> 6) Is there anything else, in addition to the top level assets (with js/css) that I would want apache to serve directly
> versus going through mod_wsgi?  It seems like I read something to this effect relating to parts of the admin, 
> that need to be served directly by apache.  I could be wrong.  

Take a look at the collectstatic management command. Also, if you use django-compress, e.g. for less,sass, css/js minimizing), you need to run that.

>
> Thanks in advance for any help,
> Bruce  

Also, you may want to check this page[1] for other possible caveats and best practises.

[1] https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

>
> P.S. If anyone wants to develop a course on udemy.com on a python framework, please don't develop with
> sqlite3 since we won't use that in production and please discuss deployment on a server besides 
> something like pythonanywhere.com.  The issues of setting things up on one's own vps server are not 
> trivial at all.  (smile).
>

> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50b71c19-10a1-4610-8050-191bde7facda%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter of the Norse

unread,
Jun 26, 2016, 2:44:48 PM6/26/16
to django...@googlegroups.com
On May 26, 2016, at 12:12 PM, Bruce Whealton <futurewavewe...@gmail.com> wrote:

Hello all,
        I have a few questions of which I am not finding answers.
1) If I export my development db (Postgresql) and then import it into production database,
won't I be pulling in a very weak password that I used for development?  I guess I can
just change that.

Don’t do that.

2) Should I export all the content and structure from my development server to my
production server?  Or should I just create the database connection and then run migrations and
then create the data content on the production server?  Obviously, my development server has
minimal content.

Run the migrations and add the data.  There should be completely different data on the Production server as the dev server.


3) Should I just upload the other packages that I installed with pip on my development server or
should I instead run pip install on the production server to get all the packages needed on the
production server?  

Pip, pip, forever pip

4) Is it a best practice ( continuing from #3) to create a requirement file and use that to install
with pip all the packages, as opposed to uploading the packages from development to production?  
Note: I am developing on Ubuntu but deploying to Centos.  

Yes.  That way you can make changes to your install and just do `pip install -U -r requirements.txt` when there’s a bug fix to one of your things.

5) I suppose, even if I had a Centos development environment, I would still want to install the required
packages on the production server instead of just uploading everything.

Pip doesn’t use your distro.  It downloads from https://pypi.python.org/pypi

Regarding #5, I am liking Python better than what I have used for some time, PHP based application
development.  However, for the longest time, things were much simpler with php in that most php code is
just text and so there isn't the notion of "installing" a package.  One could expect things to work fine
if one just uploaded the site from development to production (perhaps certain new OO features are changing
this situation for php sites, e.g. the use of autoloaders but that's another topic).

First of all, that’s not quite true.  For many PHP features you have to install a package from your Linux distro.  Or figure out how to compile PHP yourself.  Of course, many people just install all of the things, so that even if you don’t use a feature, it’s still a part of your monolithic PHP install.  This has been the case for over a decade.

6) Is there anything else, in addition to the top level assets (with js/css) that I would want apache to serve directly
versus going through mod_wsgi?  It seems like I read something to this effect relating to parts of the admin, 
that need to be served directly by apache.  I could be wrong.  

Anything that doesn’t change.  That includes images too.  The admin has it’s own CSS, JS, etc. that should be served by Apache.

Thanks in advance for any help,
Bruce  

P.S. If anyone wants to develop a course on udemy.com on a python framework, please don't develop with
sqlite3 since we won't use that in production and please discuss deployment on a server besides 
something like pythonanywhere.com.  The issues of setting things up on one's own vps server are not 
trivial at all.  (smile).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50b71c19-10a1-4610-8050-191bde7facda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter of the Norse



Reply all
Reply to author
Forward
0 new messages