見出し画像

[Python]DjangoでWebサーバを立ち上げる

1.前回の記事

今回は以下の記事の続きです。
前回は仮想環境上のPythonを3系にし、Webフレームワークである
Djangoをインストールしたところまで行いました。


2.今回おこなう事

Djangoを使って実際にWebサーバを稼働し、
ホストOSのWebブラウザからWebサーバにアクセスしてみます。
イメージは以下になります。
色々詰まったので備忘録としてnoteに書いておこうと思います。

画像1


3.参考書籍

私はDjangoについては以下の書籍で学習をしております。


4.環境セットアップ

Djangoの関連ファイルを置くためのディレクトリを仮想サーバに作成
します。以下のコマンドをrootで実行し、/root/djangoという
ディレクトリを作成。そのディレクトリに移動します。

[root@localhost ~]# mkdir django
[root@localhost ~]# cd django/


django-admin startprojectコマンドでプロジェクトを作成します。
startprojectの後に作成したいプロジェクトの名前を記載してあげます。
作成出来たかをlsコマンドで確認します。

[root@localhost django]# django-admin startproject helloworldproject
[root@localhost django]# ls
helloworldproject


treeコマンドでディレクトリの構造を確認してみます。
treeコマンドをインストールします。インストールが完了したら、
実際に実行して確認してみます。

[root@localhost helloworldproject]# yum -y install tree
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                | 9.9 kB  00:00:00
* base: ftp-srv2.kddilabs.jp
* epel: ftp.iij.ad.jp
* extras: ftp-srv2.kddilabs.jp
* updates: ftp-srv2.kddilabs.jp
base                                                                | 3.6 kB  00:00:00
epel                                                                | 4.7 kB  00:00:00
extras                                                              | 2.9 kB  00:00:00
ius                                                                 | 1.3 kB  00:00:00
updates                                                             | 2.9 kB  00:00:00
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ tree.x86_64 0:1.6.0-10.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================
Package           アーキテクチャー    バージョン                  リポジトリー       容量
===========================================================================================
インストール中:
tree              x86_64              1.6.0-10.el7                base               46 k

トランザクションの要約
===========================================================================================
インストール  1 パッケージ

総ダウンロード容量: 46 k
インストール容量: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                        |  46 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 インストール中          : tree-1.6.0-10.el7.x86_64                                   1/1
 検証中                  : tree-1.6.0-10.el7.x86_64                                   1/1

インストール:
 tree.x86_64 0:1.6.0-10.el7

完了しました!

[root@localhost django]# tree --charset=C helloworldproject/
helloworldproject/
|-- helloworldproject
|   |-- __init__.py
|   |-- asgi.py
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- manage.py


DjangoでWebサーバを稼働させるためには、manage.pyを実行しなくては
なりません。またその時、runserverという引数を指定します。
そしてさらに、runserver引数の後にIPアドレスとポートを指定することで、
そのIPアドレスとポートでサーバにアクセスすることが出来ます。
これを指定しないと127.0.0.1:8000というIPアドレスとポートになりますが、
このIPアドレスだとホストOSからアクセスすることが出来ません。

今回は仮想サーバに自動で割り当てられたIPアドレスを指定しました。
実行結果は以下になります。
最後の行を見るとわかるのですが、CentOS7上にデフォルトで存在する
SQLiteのバージョンが古くて実行出来ないようです。

[root@localhost helloworldproject]# python manage.py runserver 192.168.184.138:8000
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):

~~~省略~~~

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 "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 73, in <module>
   check_sqlite_version()
 File "/usr/local/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の最新パッケージを入手するためにwgetコマンドを使用したいので、
まずwgetをインストールします。

[root@localhost work]# yum -y install wget 
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp-srv2.kddilabs.jp
* epel: nrt.edge.kernel.org
* extras: ftp-srv2.kddilabs.jp
* updates: ftp-srv2.kddilabs.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ wget.x86_64 0:1.14-18.el7_6.1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================
Package          アーキテクチャー   バージョン                     リポジトリー      容量
===========================================================================================
インストール中:
wget             x86_64             1.14-18.el7_6.1                base             547 k

トランザクションの要約
===========================================================================================
インストール  1 パッケージ

総ダウンロード容量: 547 k
インストール容量: 2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                     | 547 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 インストール中          : wget-1.14-18.el7_6.1.x86_64                                1/1
 検証中                  : wget-1.14-18.el7_6.1.x86_64                                1/1

インストール:
 wget.x86_64 0:1.14-18.el7_6.1

完了しました!


その後wgetコマンドでSQLiteを入手しに行きます。
wget以降はURLを入力しないといけませんが、以下のサイトを確認し、
最新版となるURLを確認して適宜置き換えて下さい。
入手出来たら、lsコマンドで一応確認します。

[root@localhost work]# wget https://www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz 
--2021-05-19 16:52:52--  https://www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz
www.sqlite.org (www.sqlite.org) をDNSに問いあわせています... 45.33.6.223
www.sqlite.org (www.sqlite.org)|45.33.6.223|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 2956627 (2.8M) [application/x-gzip]
`sqlite-autoconf-3350500.tar.gz' に保存中

100%[=================================================>] 2,956,627    923KB/s 時間 3.1s

2021-05-19 16:52:56 (923 KB/s) - `sqlite-autoconf-3350500.tar.gz' へ保存完了 [2956627/2956627]

[root@localhost python]# ls
sqlite-autoconf-3350500.tar.gz


拡張子がtar.gzとなっているので解凍/展開し、併せてリネームします。
※リネームは別にやらなくても問題ないですが、私が参考にされた方が
 やっておりましたので私も一応行いました。

[root@localhost work]# tar zxvf sqlite-autoconf-3350500.tar.gz 
sqlite-autoconf-3350500/
sqlite-autoconf-3350500/sqlite3.rc
sqlite-autoconf-3350500/README.txt
sqlite-autoconf-3350500/aclocal.m4
sqlite-autoconf-3350500/sqlite3.c
sqlite-autoconf-3350500/Makefile.am
sqlite-autoconf-3350500/configure
sqlite-autoconf-3350500/configure.ac
sqlite-autoconf-3350500/config.guess
sqlite-autoconf-3350500/Makefile.in
sqlite-autoconf-3350500/config.sub
sqlite-autoconf-3350500/install-sh
sqlite-autoconf-3350500/sqlite3rc.h
sqlite-autoconf-3350500/sqlite3.1
sqlite-autoconf-3350500/shell.c
sqlite-autoconf-3350500/sqlite3.pc.in
sqlite-autoconf-3350500/Replace.cs
sqlite-autoconf-3350500/depcomp
sqlite-autoconf-3350500/missing
sqlite-autoconf-3350500/ltmain.sh
sqlite-autoconf-3350500/sqlite3ext.h
sqlite-autoconf-3350500/Makefile.msc
sqlite-autoconf-3350500/sqlite3.h
sqlite-autoconf-3350500/Makefile.fallback
sqlite-autoconf-3350500/tea/
sqlite-autoconf-3350500/tea/aclocal.m4
sqlite-autoconf-3350500/tea/configure
sqlite-autoconf-3350500/tea/configure.ac
sqlite-autoconf-3350500/tea/Makefile.in
sqlite-autoconf-3350500/tea/README
sqlite-autoconf-3350500/tea/generic/
sqlite-autoconf-3350500/tea/generic/tclsqlite3.c
sqlite-autoconf-3350500/tea/tclconfig/
sqlite-autoconf-3350500/tea/tclconfig/tcl.m4
sqlite-autoconf-3350500/tea/tclconfig/install-sh
sqlite-autoconf-3350500/tea/doc/
sqlite-autoconf-3350500/tea/doc/sqlite3.n
sqlite-autoconf-3350500/tea/pkgIndex.tcl.in
sqlite-autoconf-3350500/tea/win/
sqlite-autoconf-3350500/tea/win/rules.vc
sqlite-autoconf-3350500/tea/win/nmakehlp.c
sqlite-autoconf-3350500/tea/win/makefile.vc
sqlite-autoconf-3350500/tea/license.terms
sqlite-autoconf-3350500/INSTALL
sqlite-autoconf-3350500/compile

[root@localhost work]# mv sqlite-autoconf-3350500 sqlite-3.35.5 
[root@localhost work]# ls 
sqlite-3.35.5  sqlite-autoconf-3350500.tar.gz


SQLiteをアップデートする為に./configureを実行しようと
下のですがgccが無いとエラーを吐かれてしまいました。

[root@localhost work]# cd sqlite-3.35.5/ 
[root@localhost sqlite-3.35.5]# ./configure --prefix=/usr/local
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 `/root/python/sqlite-3.35.5':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details


gccをCentOSにインストールします。
gccとはGNU Compiler Collectionの略で様々なプログラミング言語の
コンパイラの詰め合わせみたいです。
…にしてもログが長い汗

[root@localhost sqlite-3.35.5]# yum install gcc
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp-srv2.kddilabs.jp
* epel: nrt.edge.kernel.org
* extras: ftp-srv2.kddilabs.jp
* updates: ftp-srv2.kddilabs.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ gcc.x86_64 0:4.8.5-44.el7 を インストール
--> 依存性の処理をしています: libgomp = 4.8.5-44.el7 のパッケージ: gcc-4.8.5-44.el7.x86_64
--> 依存性の処理をしています: cpp = 4.8.5-44.el7 のパッケージ: gcc-4.8.5-44.el7.x86_64
--> 依存性の処理をしています: libgcc >= 4.8.5-44.el7 のパッケージ: gcc-4.8.5-44.el7.x86_64
--> 依存性の処理をしています: glibc-devel >= 2.2.90-12 のパッケージ: gcc-4.8.5-44.el7.x86_64
--> 依存性の処理をしています: libmpfr.so.4()(64bit) のパッケージ: gcc-4.8.5-44.el7.x86_64
--> 依存性の処理をしています: libmpc.so.3()(64bit) のパッケージ: gcc-4.8.5-44.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ cpp.x86_64 0:4.8.5-44.el7 を インストール
---> パッケージ glibc-devel.x86_64 0:2.17-324.el7_9 を インストール
--> 依存性の処理をしています: glibc-headers = 2.17-324.el7_9 のパッケージ: glibc-devel-2.17-324.el7_9.x86_64
--> 依存性の処理をしています: glibc = 2.17-324.el7_9 のパッケージ: glibc-devel-2.17-324.el7_9.x86_64
--> 依存性の処理をしています: glibc-headers のパッケージ: glibc-devel-2.17-324.el7_9.x86_64
---> パッケージ libgcc.x86_64 0:4.8.5-39.el7 を 更新
---> パッケージ libgcc.x86_64 0:4.8.5-44.el7 を アップデート
---> パッケージ libgomp.x86_64 0:4.8.5-39.el7 を 更新
---> パッケージ libgomp.x86_64 0:4.8.5-44.el7 を アップデート
---> パッケージ libmpc.x86_64 0:1.0.1-3.el7 を インストール
---> パッケージ mpfr.x86_64 0:3.1.1-4.el7 を インストール
--> トランザクションの確認を実行しています。
---> パッケージ glibc.x86_64 0:2.17-307.el7.1 を 更新
--> 依存性の処理をしています: glibc = 2.17-307.el7.1 のパッケージ: glibc-common-2.17-307.el7.1.x86_64
---> パッケージ glibc.x86_64 0:2.17-324.el7_9 を アップデート
---> パッケージ glibc-headers.x86_64 0:2.17-324.el7_9 を インストール
--> 依存性の処理をしています: kernel-headers >= 2.2.1 のパッケージ: glibc-headers-2.17-324.el7_9.x86_64
--> 依存性の処理をしています: kernel-headers のパッケージ: glibc-headers-2.17-324.el7_9.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ glibc-common.x86_64 0:2.17-307.el7.1 を 更新
---> パッケージ glibc-common.x86_64 0:2.17-324.el7_9 を アップデート
---> パッケージ kernel-headers.x86_64 0:3.10.0-1160.25.1.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===========================================================================================
Package                アーキテクチャー
                                      バージョン                    リポジトリー     容量
===========================================================================================
インストール中:
gcc                    x86_64         4.8.5-44.el7                  base             16 M
依存性関連でのインストールをします:
cpp                    x86_64         4.8.5-44.el7                  base            5.9 M
glibc-devel            x86_64         2.17-324.el7_9                updates         1.1 M
glibc-headers          x86_64         2.17-324.el7_9                updates         691 k
kernel-headers         x86_64         3.10.0-1160.25.1.el7          updates         9.0 M
libmpc                 x86_64         1.0.1-3.el7                   base             51 k
mpfr                   x86_64         3.1.1-4.el7                   base            203 k
依存性関連での更新をします:
glibc                  x86_64         2.17-324.el7_9                updates         3.6 M
glibc-common           x86_64         2.17-324.el7_9                updates          12 M
libgcc                 x86_64         4.8.5-44.el7                  base            103 k
libgomp                x86_64         4.8.5-44.el7                  base            159 k

トランザクションの要約
===========================================================================================
インストール  1 パッケージ (+6 個の依存関係のパッケージ)
更新                       ( 4 個の依存関係のパッケージ)

総ダウンロード容量: 49 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/11): glibc-devel-2.17-324.el7_9.x86_64.rpm                       | 1.1 MB  00:00:02
(2/11): glibc-headers-2.17-324.el7_9.x86_64.rpm                     | 691 kB  00:00:00
(3/11): kernel-headers-3.10.0-1160.25.1.el7.x86_64.rpm              | 9.0 MB  00:00:08
(4/11): glibc-2.17-324.el7_9.x86_64.rpm                             | 3.6 MB  00:00:17
(5/11): glibc-common-2.17-324.el7_9.x86_64.rpm                      |  12 MB  00:00:34
(6/11): cpp-4.8.5-44.el7.x86_64.rpm                                 | 5.9 MB  00:00:34
(7/11): libgomp-4.8.5-44.el7.x86_64.rpm                             | 159 kB  00:00:00
(8/11): libgcc-4.8.5-44.el7.x86_64.rpm                              | 103 kB  00:00:00
(9/11): libmpc-1.0.1-3.el7.x86_64.rpm                               |  51 kB  00:00:00
(10/11): mpfr-3.1.1-4.el7.x86_64.rpm                                | 203 kB  00:00:00
(11/11): gcc-4.8.5-44.el7.x86_64.rpm                                |  16 MB  00:01:07
-------------------------------------------------------------------------------------------
合計                                                       736 kB/s |  49 MB  00:01:07
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 更新します              : libgcc-4.8.5-44.el7.x86_64                                1/15
 更新します              : glibc-common-2.17-324.el7_9.x86_64                        2/15
 更新します              : glibc-2.17-324.el7_9.x86_64                               3/15
 インストール中          : mpfr-3.1.1-4.el7.x86_64                                   4/15
 インストール中          : libmpc-1.0.1-3.el7.x86_64                                 5/15
 インストール中          : cpp-4.8.5-44.el7.x86_64                                   6/15
 更新します              : libgomp-4.8.5-44.el7.x86_64                               7/15
 インストール中          : kernel-headers-3.10.0-1160.25.1.el7.x86_64                8/15
 インストール中          : glibc-headers-2.17-324.el7_9.x86_64                       9/15
 インストール中          : glibc-devel-2.17-324.el7_9.x86_64                        10/15
 インストール中          : gcc-4.8.5-44.el7.x86_64                                  11/15
 整理中                  : libgomp-4.8.5-39.el7.x86_64                              12/15
 整理中                  : glibc-common-2.17-307.el7.1.x86_64                       13/15
 整理中                  : glibc-2.17-307.el7.1.x86_64                              14/15
 整理中                  : libgcc-4.8.5-39.el7.x86_64                               15/15
 検証中                  : kernel-headers-3.10.0-1160.25.1.el7.x86_64                1/15
 検証中                  : glibc-2.17-324.el7_9.x86_64                               2/15
 検証中                  : glibc-common-2.17-324.el7_9.x86_64                        3/15
 検証中                  : mpfr-3.1.1-4.el7.x86_64                                   4/15
 検証中                  : glibc-headers-2.17-324.el7_9.x86_64                       5/15
 検証中                  : cpp-4.8.5-44.el7.x86_64                                   6/15
 検証中                  : glibc-devel-2.17-324.el7_9.x86_64                         7/15
 検証中                  : gcc-4.8.5-44.el7.x86_64                                   8/15
 検証中                  : libmpc-1.0.1-3.el7.x86_64                                 9/15
 検証中                  : libgcc-4.8.5-44.el7.x86_64                               10/15
 検証中                  : libgomp-4.8.5-44.el7.x86_64                              11/15
 検証中                  : glibc-common-2.17-307.el7.1.x86_64                       12/15
 検証中                  : libgcc-4.8.5-39.el7.x86_64                               13/15
 検証中                  : libgomp-4.8.5-39.el7.x86_64                              14/15
 検証中                  : glibc-2.17-307.el7.1.x86_64                              15/15

インストール:
 gcc.x86_64 0:4.8.5-44.el7

依存性関連をインストールしました:
 cpp.x86_64 0:4.8.5-44.el7                glibc-devel.x86_64 0:2.17-324.el7_9
 glibc-headers.x86_64 0:2.17-324.el7_9    kernel-headers.x86_64 0:3.10.0-1160.25.1.el7
 libmpc.x86_64 0:1.0.1-3.el7              mpfr.x86_64 0:3.1.1-4.el7

依存性を更新しました:
 glibc.x86_64 0:2.17-324.el7_9            glibc-common.x86_64 0:2.17-324.el7_9
 libgcc.x86_64 0:4.8.5-44.el7             libgomp.x86_64 0:4.8.5-44.el7

完了しました!

gccについては以下も参考ください


gccをインストールしたので改めて./configureを実行します。

[root@localhost sqlite-3.35.5]# ./configure --prefix=/usr/local
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... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for fdatasync... yes
checking for usleep... yes
checking for fullfsync... no
checking for localtime_r... yes
checking for gmtime_r... yes
checking whether strerror_r is declared... yes
checking for strerror_r... yes
checking whether strerror_r returns char *... no
checking editline/readline.h usability... no
checking editline/readline.h presence... no
checking for editline/readline.h... no
checking readline/readline.h usability... no
checking readline/readline.h presence... no
checking for readline/readline.h... no
checking for library containing pthread_create... -lpthread
checking for library containing pthread_mutexattr_init... none required
checking for library containing dlopen... -ldl
checking for whether to support dynamic extensions... yes
checking SQL math functions... enabled
checking for library containing ceil... -lm
checking FTS4 extension... enabled
checking FTS3 extension... disabled
checking FTS5 extension... enabled
checking for library containing log... none required
checking JSON functions... enabled
checking RTREE extension... enabled
checking Session extension... disabled
checking Build type... release
checking for posix_fallocate... yes
checking zlib.h usability... no
checking zlib.h presence... no
checking for zlib.h... no
checking for library containing system... none required
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating sqlite3.pc
config.status: executing depfiles commands
config.status: executing libtool commands


次にmakeコマンドでコンパイルし、完了後make installを実行します。

[root@localhost sqlite-3.35.5]# make
/bin/sh ./libtool  --tag=CC   --mode=compile gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.35.5\" -DPACKAGE_STRING=\"sqlite\ 3.35.5\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.35.5\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -I.    -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY  -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c -o sqlite3.lo sqlite3.c
libtool: compile:  gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.35.5\" "-DPACKAGE_STRING=\"sqlite 3.35.5\"" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.35.5\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c sqlite3.c  -fPIC -DPIC -o .libs/sqlite3.o
libtool: compile:  gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.35.5\" "-DPACKAGE_STRING=\"sqlite 3.35.5\"" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.35.5\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -g -O2 -MT sqlite3.lo -MD -MP -MF .deps/sqlite3.Tpo -c sqlite3.c -o sqlite3.o >/dev/null 2>&1
mv -f .deps/sqlite3.Tpo .deps/sqlite3.Plo
/bin/sh ./libtool  --tag=CC   --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY  -g -O2 -no-undefined -version-info 8:6:8  -o libsqlite3.la -rpath /usr/local/lib sqlite3.lo  -lm -ldl -lpthread
libtool: link: gcc -shared  -fPIC -DPIC  .libs/sqlite3.o   -lm -ldl -lpthread  -g -O2   -Wl,-soname -Wl,libsqlite3.so.0 -o .libs/libsqlite3.so.0.8.6
libtool: link: (cd ".libs" && rm -f "libsqlite3.so.0" && ln -s "libsqlite3.so.0.8.6" "libsqlite3.so.0")
libtool: link: (cd ".libs" && rm -f "libsqlite3.so" && ln -s "libsqlite3.so.0.8.6" "libsqlite3.so")
libtool: link: ar cru .libs/libsqlite3.a  sqlite3.o
libtool: link: ranlib .libs/libsqlite3.a
libtool: link: ( cd ".libs" && rm -f "libsqlite3.la" && ln -s "../libsqlite3.la" "libsqlite3.la" )
gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.35.5\" -DPACKAGE_STRING=\"sqlite\ 3.35.5\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.35.5\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -I.    -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY  -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB  -g -O2 -MT sqlite3-shell.o -MD -MP -MF .deps/sqlite3-shell.Tpo -c -o sqlite3-shell.o `test -f 'shell.c' || echo './'`shell.c
mv -f .deps/sqlite3-shell.Tpo .deps/sqlite3-shell.Po
gcc -DPACKAGE_NAME=\"sqlite\" -DPACKAGE_TARNAME=\"sqlite\" -DPACKAGE_VERSION=\"3.35.5\" -DPACKAGE_STRING=\"sqlite\ 3.35.5\" -DPACKAGE_BUGREPORT=\"http://www.sqlite.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"sqlite\" -DVERSION=\"3.35.5\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -I.    -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY  -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB  -g -O2 -MT sqlite3-sqlite3.o -MD -MP -MF .deps/sqlite3-sqlite3.Tpo -c -o sqlite3-sqlite3.o `test -f 'sqlite3.c' || echo './'`sqlite3.c
mv -f .deps/sqlite3-sqlite3.Tpo .deps/sqlite3-sqlite3.Po
/bin/sh ./libtool  --tag=CC   --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY  -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB  -g -O2   -o sqlite3 sqlite3-shell.o sqlite3-sqlite3.o  -lm -ldl -lpthread
libtool: link: gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB -g -O2 -o sqlite3 sqlite3-shell.o sqlite3-sqlite3.o  -lm -ldl -lpthread

[root@localhost sqlite-3.35.5]# make install
make[1]: ディレクトリ `/root/work/sqlite-3.35.5' に入ります
/usr/bin/mkdir -p '/usr/local/lib'
/bin/sh ./libtool   --mode=install /usr/bin/install -c   libsqlite3.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libsqlite3.so.0.8.6 /usr/local/lib/libsqlite3.so.0.8.6
libtool: install: (cd /usr/local/lib && { ln -s -f libsqlite3.so.0.8.6 libsqlite3.so.0 || { rm -f libsqlite3.so.0 && ln -s libsqlite3.so.0.8.6 libsqlite3.so.0; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libsqlite3.so.0.8.6 libsqlite3.so || { rm -f libsqlite3.so && ln -s libsqlite3.so.0.8.6 libsqlite3.so; }; })
libtool: install: /usr/bin/install -c .libs/libsqlite3.lai /usr/local/lib/libsqlite3.la
libtool: install: /usr/bin/install -c .libs/libsqlite3.a /usr/local/lib/libsqlite3.a
libtool: install: chmod 644 /usr/local/lib/libsqlite3.a
libtool: install: ranlib /usr/local/lib/libsqlite3.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
  /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
  - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
    during execution
  - add LIBDIR to the 'LD_RUN_PATH' environment variable
    during linking
  - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
  - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/mkdir -p '/usr/local/bin'
 /bin/sh ./libtool   --mode=install /usr/bin/install -c sqlite3 '/usr/local/bin'
libtool: install: /usr/bin/install -c sqlite3 /usr/local/bin/sqlite3
/usr/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 sqlite3.h sqlite3ext.h '/usr/local/include'
/usr/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 sqlite3.1 '/usr/local/share/man/man1'
/usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 sqlite3.pc '/usr/local/lib/pkgconfig'
make[1]: ディレクトリ `/root/work/sqlite-3.35.5' から出ます


./configure、make、make install辺りは自分もあまりよくわかっていません。
以下のサイトが分かりやすそうなので勉強ですね・・・汗


SQLiteがアップデートされているかを確認します。
エラーの時はSQLite自身は3.7.17となっていたのですが3.35.5となっており、
問題なさそうですね。

[root@localhost sqlite-3.35.5]# /usr/local/bin/sqlite3 --version
3.35.5 2021-04-19 18:32:05 1b256d97b553a9611efca188a3d995a2fff712759044ba480f9a0c9e98fae886
[root@localhost sqlite-3.35.5]# /usr/bin/sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@localhost sqlite-3.35.5]# sqlite3 --version
3.35.5 2021-04-19 18:32:05 1b256d97b553a9611efca188a3d995a2fff712759044ba480f9a0c9e98fae886


新しいSQLiteと古いSQLiteを入れ替えます。
(そういうイメージで良いと思う。。。)
併せてPATHを通します。

[root@localhost sqlite-3.35.5]# mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
[root@localhost sqlite-3.35.5]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
[root@localhost sqlite-3.35.5]# export LD_LIBRARY_PATH="/usr/local/lib"


これで再度manage.pyを実行すると、実行出来たことが分かります。
しかし、まだこれだけだとアクセスすることが出来ません。
このサーバはポート8000で受け付けるのですが、そのポートが開放
されていない為です。

[root@localhost helloworldproject]# python manage.py runserver 192.168.184.138:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 19, 2021 - 09:22:29
Django version 3.2.3, using settings 'helloworldproject.settings'
Starting development server at http://192.168.184.138:8000/
Quit the server with CONTROL-C.


firewall-cmdコマンド辺りでポートを開放していきます。
デフォルトのポート開放状態は以下です。
sshとdhcpv6は受け付けていますが、他は拒否しています。

[root@localhost helloworldproject]# firewall-cmd --list-all
public (active)
 target: default
 icmp-block-inversion: no
 interfaces: ens33
 sources:
 services: dhcpv6-client ssh
 ports:
 protocols:
 masquerade: no
 forward-ports:
 source-ports:
 icmp-blocks:
 rich rules:


Djangoで使用するポートは8000になるので、その番号のポートを
開放していきます。
開放した後再度設定を見てみるとportsの部分に8000が出力されています。

[root@localhost helloworldproject]# firewall-cmd --zone=public --add-port=8000/tcp --perman
ent
success
[root@localhost helloworldproject]# firewall-cmd --reload
success
[root@localhost helloworldproject]# firewall-cmd --list-all
public (active)
 target: default
 icmp-block-inversion: no
 interfaces: ens33
 sources:
 services: dhcpv6-client ssh
 ports: 8000/tcp
 protocols:
 masquerade: no
 forward-ports:
 source-ports:
 icmp-blocks:
 rich rules:


再度manage.pyを実行して、ホストOSのChromeからDjangoWebサーバに
アクセスします。まずCLI画面では正常に稼働していることを確認。

[root@localhost helloworldproject]# python manage.py runserver 192.168.184.138:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 19, 2021 - 09:22:29
Django version 3.2.3, using settings 'helloworldproject.settings'
Starting development server at http://192.168.184.138:8000/
Quit the server with CONTROL-C.


しかしWebブラウザでは以下の様にアクセス出来ないエラーが
吐かれてしまいました。
ALLOWED HOSTSと書いていることからアクセス設定を正しくすることで
アクセス出来そうだなと目星をつけることが出来ますね。

画像2


軽くググって確認してみるとプロジェクトディレクトリの中にsettings.pyと
いう設定ファイルがあるのですが、この中にあるALLOWED_HOSTSに適切な
設定を入れてあげることで上記の問題は解消されます。
今回は全てのユーザからアクセスを許可するという意味の'*'を入力します。

ALLOWED_HOSTS = ['*']


再度DjangoWebサーバにアクセスしてみます。
今度はDjangoの画面が表示されているのが分かります。
これでDjangoを検証する用の環境が出来上がりました。
長かった・・・汗

画像3


この記事が参加している募集

この記事が気に入ったらサポートをしてみませんか?