A
A
Alexey2015-01-03 00:39:08
linux
Alexey, 2015-01-03 00:39:08

How to setup ubuntu+apache2+python bundle?

Suggest good resources on this topic. New to Linux, and generally new to setting up web servers. In general, what is required is to develop an API based on this bundle, so something on this topic is also desirable. I searched on the Internet, but there are many things that it is not clear whether this is correct or not.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Bezpalov, 2015-01-03
@Priest512

On the example of Ubuntu 14.04 LTS, Python 3.4.0, Django 1.7.1 for the development machine.
Install Apache 2
Install mod_wsgi for Python 3 (Apache 2 - Python 3 bundle)
Install PIP for Python 3 (package manager)
Install Django
Create a Django project

Создаем проект
$ mkdir -p /home/user/site.ru/
$ mkdir -p /home/user/site.ru/static/
$ mkdir -p /home/user/site.ru/media/
$ mkdir -p /home/user/site.ru/logs/
$ cd /home/user/site.ru/
$ django-admin.py startproject project

Setting up Apache
In it we write
<VirtualHost *:80>
     ServerAdmin [email protected]
     ServerName site.ru
     ServerAlias www.site.ru
     ErrorLog /home/user/site.ru/logs/error.log
     CustomLog /home/user/site.ru/logs/access.log combined
     Alias /robots.txt /home/user/site.ru/static/robots.txt
     Alias /favicon.ico /home/user/user.ru/static/favicon.ico
     AliasMatch ^/([^/]*\.css) /home/user/site.ru/static/styles/$1
     Alias /media/ /home/user/site.ru/media/
     Alias /static/ /home/user/site.ru/static/
     <Directory /home/user/site.ru/static>
          Require all granted
     </Directory>
     <Directory /home/user/site.ru/media>
          Require all granted
     </Directory>
     WSGIScriptAlias / /home/user/site.ru/project/project/wsgi.py
     <Directory /home/user/site.ru/project/project>
         <Files wsgi.py>
             Require all granted
         </Files>
     </Directory>
</VirtualHost>

Editing the project's wsgi file
import os
import sys
sys.path.append('/home/user/site.ru/project/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Restart Apache
Accordingly, site.ru and user are changed to your own.
UPD: I don't remember now: most likely for the first run you will need to create a Django superuser.
$ cd /home/user/site.ru/project
$ python3 manage.py createsuperuser
$ python3 manage.py migrate

I
Ilya, 2015-01-03
@FireGM

Or maybe you should use nginx+uwsgi?

Y
Yuri Shikanov, 2015-01-03
@dizballanze

It's better to focus on Nginx + gunicorn/uwsgi/etc. This is a more modern and flexible solution.

S
serrrgggeee, 2015-06-30
@serrrgggeee

Hello, I can’t figure out for the second day what is the reason I do everything according to the instructions and several times, but I constantly get this message

Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at site.ru Port 80

Maybe I screwed something up, but I don't remember.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question