Apache + Django

動作環境

Rocky Linux 8
MySQL 8.0.25
Apache 2.4.46
Python 3.7.2
Django 3.2.3
mod-wsgi 4.8.0
MySQL 8.0.25
mysqlclient 2.0.3

EC2起動

割愛

# dnf install epel-release
# dnf install screen

Apache,mod_wsgiのインストール

# yum update -y
# yum -y install httpd httpd-devel openssl mod_ssl
# systemctl start httpd
# systemctl enable httpd.service
# systemctl status httpd.service

Pythonのインストール

# yum install -y httpd-devel python3-devel gcc gcc-c++ redhat-rpm-config
# yum install -y python3
$ python3 -V 

Djangoのインストール

# pip3 install django mod_wsgi
# pip3 list

MySQL,mysqlclientのインストール

# dnf check-update
# dnf -y module disable mysql
# dnf search mysql-community-server

# rpm -qa | grep -i mysql
# dnf remove mysql80-community-release-el7-1
# rpm -ivh https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm
# yum install --enablerepo=mysql80-community mysql-community-server -y

# systemctl start mysqld.service
# systemctl enable mysqld.service
# systemctl status mysqld.service

# yum install -y mysql-devel
# pip3 install mysqlclient

# mysql --version

DBに接続

# fgrep 'password' /var/log/mysqld.log
# mysql -u root -p
パスワードを変更しておく

Djnagoアプリの配置

割愛

公開用設定

# find / -name mod_wsgi*.so
/usr/local/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
# which python3
/bin/python3
# vi /etc/httpd/conf.d/django.conf
LoadModule wsgi_module /usr/local/lib64/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so

#EC2インスタンスのパブリックIPを記載します。
ServerName <パブリックIP>

WSGIScriptAlias / /var/www/webapp/webapp/wsgi.py
WSGIPythonPath /var/www/webapp:/bin/python3

Alias /static "/var/www/webapp/static"
<Directory "/var/www/webapp/static">
    Require all granted
</Directory>

<Directory "/var/www/webapp/webapp/">
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>
# systemctl restart httpd