[Django] 리눅스서버상에서 Django 환경 구축하기 - SQLite 도 설치
필자의 Centos7 리눅스서버 환경에서 셋팅하였다.
1. Python3 설치
2. Django 설치
일단 새로운 django 가상환경을 위해 임의의 폴더 alzssol_django 을 만들었다.
mkdir alzssol_django
cd alzssol_djang
pip3 --version [pip3 버전확인]
virtualenv --version [virtualenv 버전확인]
virtualenv 설치한다.
pip3 install virtualenv
venv 이름으로 가상환경을 설정한다.
virtualenv venv
1
2
3
4
5
6
|
[root@localhost alzssol_django]# virtualenv venv
created virtual environment CPython3.6.8.final.0-64 in 715ms
creator CPython3Posix(dest=/var/alzssol_django/venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==21.3.1, setuptools==59.6.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
|
cs |
가상환경 활성화 / 비활성화
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
(venv) [root@localhost alzssol_django]# pip3 install django
Collecting django
Downloading Django-3.2.19-py3-none-any.whl (7.9 MB)
|████████████████████████████████| 7.9 MB 7.0 MB/s
Collecting pytz
Downloading pytz-2023.3-py2.py3-none-any.whl (502 kB)
|████████████████████████████████| 502 kB 11.1 MB/s
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.4.4-py3-none-any.whl (41 kB)
|████████████████████████████████| 41 kB 29 kB/s
Collecting asgiref<4,>=3.3.2
Downloading asgiref-3.4.1-py3-none-any.whl (25 kB)
Collecting typing-extensions
Using cached typing_extensions-4.1.1-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.4.1 django-3.2.19 pytz-2023.3 sqlparse-0.4.4 typing-extensions-4.1.1
|
cs |
최초 프로젝트 생성한다.
config 프로젝트 명으로 적고 한칸 띄우고 점(.) 찍는다. 현재폴더에서 생성한다는 뜻
1
|
(venv) [root@localhost alzssol_django]# django-admin startproject config .
|
cs |
django 서버를 실행해본다.
python manage.py runserver 0:8000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
(venv) [root@localhost alzssol_django]# python manage.py runserver 0:8000
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/apps/config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/models/options.py", line 207, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/utils.py", line 204, in create_connection
backend = load_backend(db['ENGINE'])
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 73, in <module>
check_sqlite_version()
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 69, in check_sqlite_version
'SQLite 3.9.0 or later is required (found %s).' % Database.sqlite_version
django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
|
cs |
그런데, 마지막 텍스트처럼 error 발생
File "/var/alzssol_django/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 69, in check_sqlite_version
'SQLite 3.9.0 or later is required (found %s).' % Database.sqlite_version
django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
SQLite 3.9 이상 버전으로 새로 설치하라는 내용
[SQLite 설치하기]
https://sqlite.org/download.html
sqlite 설치파일 확인
1
2
3
4
|
[root@localhost src]# find /usr/ -name libsqlite3.so.0.8.6
/usr/lib64/libsqlite3.so.0.8.6
[root@localhost src]# pwd
/usr/local/src
|
cs |
설치파일 다운로드 후 압축풀기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@localhost src]# wget https://sqlite.org/2021/sqlite-autoconf-3360000.tar.gz --no-check-certificate
--2023-06-12 10:28:44-- https://sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
Resolving sqlite.org (sqlite.org)... 45.33.6.223, 2600:3c00::f03c:91ff:fe96:b959
Connecting to sqlite.org (sqlite.org)|45.33.6.223|:443... connected.
WARNING: cannot verify sqlite.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
Length: 2977080 (2.8M) [application/x-gzip]
Saving to: ‘sqlite-autoconf-3360000.tar.gz’
100%[==============================================================================================>] 2,977,080 1.47MB/s in 1.9s
2023-06-12 10:28:47 (1.47 MB/s) - ‘sqlite-autoconf-3360000.tar.gz’ saved [2977080/2977080]
[root@localhost src]# ll
합계 2908
-rw-r--r-- 1 root root 2977080 11월 16 2021 sqlite-autoconf-3360000.tar.gz
[root@localhost src]# sudo tar -zxf sqlite-autoconf-3360000.tar.gz
[root@localhost src]# ll
합계 2912
drwxrwxr-x 3 test1 test1 4096 6월 19 2021 sqlite-autoconf-3360000
-rw-r--r-- 1 root root 2977080 11월 16 2021 sqlite-autoconf-3360000.tar.gz
|
cs |
설치파일 새로 설치하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@localhost src]# cd sqlite-autoconf-3360000/
[root@localhost sqlite-autoconf-3360000]# sudo ./configure
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/sqlite-autoconf-3360000':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
[root@localhost sqlite-autoconf-3360000]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/sqlite-autoconf-3360000':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
|
cs |
그런데 또 에러발생
관련 내용들 부가적으로 설치하여 보완하였다.
yum install gcc glibc glibc-common gd gd-devel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@localhost sqlite-autoconf-3360000]# yum install gcc glibc glibc-common gd gd-devel
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink | 7.1 kB 00:00:00
* base: mirror.kakao.com
* epel: mirror-icn.yuki.net.uk
* extras: mirror.kakao.com
* updates: mirror.kakao.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
mariadb | 3.4 kB 00:00:00
updates | 2.9 kB 00:00:00
webtatic | 3.6 kB 00:00:00
(1/7): epel/x86_64/group_gz | 99 kB 00:00:00
(2/7): extras/7/x86_64/primary_db | 249 kB 00:00:00
(3/7): mariadb/updateinfo | 5.9 kB 00:00:01
(4/7): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(5/7): mariadb/primary_db | 75 kB 00:00:01
(6/7): epel/x86_64/primary_db | 7.0 MB 00:00:02
(7/7): updates/7/x86_64/primary_db | 21 MB 00:00:02
|
cs |
다시 SQLite 설치 시도한다.
1
2
|
[root@localhost sqlite-autoconf-3360000]# sudo ./configure
[root@localhost sqlite-autoconf-3360000]# sudo make clean && sudo make -j 20 && sudo make install
|
cs |
새로 설치한 SQLite 파일들로 해당경로에 교체해 준다.
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@localhost sqlite-autoconf-3360000]# sudo /bin/cp -rf /usr/lib64/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6_bak
[root@localhost sqlite-autoconf-3360000]# sudo /bin/cp -rf /usr/local/lib/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6
[root@localhost sqlite-autoconf-3360000]# python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.36.0'
>>> exit()
|
cs |
가상환경 폴더내 settings.py 파일내 설정값 수정
모든 아이피에서 접근가능 (*)
1
2
3
4
5
6
|
...
ALLOWED_HOSTS = ['*']
...
TIME_ZONE = 'Asia/Seoul'
...
|
cs |
마지막으로 다시 django 를 재가동해본다.
1
|
(venv) [root@localhost alzssol_django]# python manage.py runserver 0:8000
|
cs |
Django 는 8000 포트를 기본으로 하는데, 외부서버에 셋팅하는 거라 방화벽으로 8000번을 풀어 주어야 한다.
1
2
|
firewall-cmd --permanent --zone=public --add-port=8000/tcp
firewall-cmd --reload
|
cs |
방화벽 관련 필자의 포스팅은 아래와 같다. 참고하길 바란다.
https://wonpaper.tistory.com/140