kang-rin 개발 일지(config) logo kang-rin 개발 일지(config)

============================================

 Amazon Linux2 (contos 기반)
 apache 2.4
 python 3.7
 django 2.2.3
 mod_wsgi 4.
 

주의)필요한 인프라를 다운받아 직업 소스 컴파일해서 설치 하는 밥법도 있으나 버그 및 설치 미스에 따른 취약점이 발생 직접 대응 해야하는 문제도 생기기때문에 패키지 설치권장

aws생성

yum update

-y 옵션을 사용하면 확인 여부를 묻지 않고 업데이트를 설치합니다. 설치 전에 업데이트 정보를 확인하려면 이 옵션을 생략합니다

 $ sudo yum update -y

apche 설치

http://progtrend.blogspot.com/2018/06/amazon-linux-2-apache-web-server.html

https://pypi.org/project/mod-wsgi/

If you are running Debian or Ubuntu Linux with Apache 2.4 system packages, regardless of which Apache MPM is being used, you would need both:
If you are running RHEL, CentOS or Fedora, you would need both:

$ sudo yum install httpd
$ sudo yum install httpd-devel 
$ systemctl stop httpd.service 
$ systemctl restart httpd.service
$ systemctl start httpd.service
$ systemctl start vsftpd@vsftpd.service
$ systemctl status httpd

* 2.소스 컴파일

 아파치설치 파일 <https://httpd.apache.org/download.cgi#apache24><br>
 설치파일  <https://apr.apache.org/download.cgi><br>
 APR 참고  <https://victorydntmd.tistory.com/220><br>
 
 
* 2.1 PCRE 설치
$ wget https://sourceforge.net/projects/pcre/files/pcre/8.36/pcre-8.36.tar.gz/download
$ tar xvfz download 
$ cd pcre-8.36
$ ./configure --prefix=/usr/local
$ make
$ make install

* 2.2 apache 설치
$ cd ..
$ wget http://mirror.navercorp.com/apache//httpd/httpd-2.4.39.tar.gz
$ tar xvfz httpd-2.4.39.tar.gz

* 2.3  apr 설치
$ wget http://mirror.navercorp.com/apache//apr/apr-1.7.0.tar.gz
$ tar xvfz apr-1.7.0.tar.gz

* 2.4 apr-util 설치
$ http://mirror.navercorp.com/apache//apr/apr-util-1.6.1.tar.gz
$ tar xvfz apr-util-1.6.1.tar.gz

* 2.5 apr과 apr-util을 아파치의 srclib 디렉터리 안으로 이동
$ mv apr-1.7.0 httpd-2.4.39/srclib/apr
$ mv apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

* 2.6 아파치 configure
$ cd httpd-2.4.39
$ ./configure \
$ --prefix=/usr/local/apache2.4 \
$ --with-included-apr \
$ -with-pcre=/usr/local/bin/pcre-config
$ make
$ make install

* 2.7에러시
$ yum install -y expat-devel
$ make clean
$ make

root@ip-172-31-46-69 httpd-2.4.39]# /usr/local/apache2.4/bin/apachectl start
[root@ip-172-31-46-69 httpd-2.4.39]# ps -aux | grep http
root      8342  0.0  0.4  74992  4316 ?        Ss   01:53   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    8343  0.0  0.3 822712  4016 ?        Sl   01:53   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    8344  0.0  0.3 822712  4016 ?        Sl   01:53   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    8345  0.0  0.3 822712  4016 ?        Sl   01:53   0:00 /usr/local/apache2.4/bin/httpd -k start
root      8428  0.0  0.2 123632  2468 pts/1    S+   01:53   0:00 grep --color=auto http
[root@ip-172-31-46-69 httpd-2.4.39]#

호스트설정

1 상위에 ec2-ser:apache www 생성
2 /etc/httpd/conf.d/vhost.conf 생성
3 도메인 연결전까지 (http.conf의 DocumentRoot를 수정할필요없이 vhost에서 포트별 DocumentRoot)

<VirtualHost *:80>
DocumentRoot "/www/test"
       <Directory "/www/test">
                AllowOverride all
                Require all granted
        </Directory>
</VirtualHost>

파이썬 설치

$ sudo yum install python3
현재기준으로 3.3.7
/lib/python3.7/

mod_wsgi

mod_wsgi를 설치하여 아파치로 파이썬을 띄울수있게
$ pip3 install mod_wsgi
에러 날경우
$ yum install python3-devel
* 2.1 mod_wsgi다운로드
$ wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.5.tar.gz
$ tar xvfz 4.6.5.tar.gz
$ cd mod_wsgi-4.6.5/
$ ./configure --with-apxs=/usr/bin/apxs \
  --with-python=/bin/python3.7
  
  헤더가 없다는 에러일경우
  $ yum install python3-devel
  
  find -name 'apxs' -print
  모듈추가
 LoadModule wsgi_module modules/mod_wsgi.so

http://www.fun25.co.kr/blog/python-django-apache-mod-wsgi-install https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html

<VirtualHost *:80>
	WSGIScriptAlias / /www/myapp/config/wsgi.py
	WSGIDaemonProcess myapp.io python-path=/lib/python3.7/site-packages
	WSGIProcessGroup myapp.io
   <Directory "/www/myapp/config">
       <Files wsgi.py>
		    AllowOverride None
		    Require all granted
		</Files>
    </Directory>
</VirtualHost>

파이썬 디폴드 변경

https://codechacha.com/ko/change-python-version/

[root@ip-122-00-00-00 bin]# python -V
Python 2.7.16
[root@ip-122-00-00-00 bin]# update-alternatives --install /bin/python python /bin/python2
python2           python2-config    python2.7         python2.7-config  
[root@ip-122-00-00-00 bin]# update-alternatives --install /bin/python python /bin/python2.7 1
[root@ip-122-00-00-00 bin]# update-alternatives --install /bin/python python /bin/python3 1
python3     python3.7   python3.7m  
[root@ip-122-00-00-00 bin]# update-alternatives --install /bin/python python /bin/python3 1
python3     python3.7   python3.7m  
[root@ip-122-00-00-00 bin]# update-alternatives --install /bin/python python /bin/python3 1
python3     python3.7   python3.7m  
[root@ip-122-00-00-00 bin]# update-alternatives --install /bin/python python /bin/python3.7 2
[root@ip-122-00-00-00 bin]# update-alternatives --config python


2 개의 프로그램이 'python'를 제공합니다.

  선택    명령
-----------------------------------------------
   1           /bin/python2.7
*+ 2           /bin/python3.7

현재 선택[+]을 유지하려면 엔터키를 누르고, 아니면 선택 번호를 입력하십시오:2
[root@ip-122-00-00-00 bin]# python -V
Python 3.7.3

기타에러

종합 설치

* 1. 아파치설치
 sudo yum install httpd
 sudo yum install httpd-devel
* 2. 파이썬
 sudo yum install python3
* 3.mod_wsgi설치
  pip3 install mod_wsgi 
* 4.mod_wsgi 등록 (왜 그런지 모르겠지만 pip로 설치하면 mod_wsgi.po가 모듈하위디렉토리에 생기지않음)
  cp -ai mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so /etc/httpd/modules/
  vim 01-cgi.conf
  LoadModule wsgi_module modules/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so
 * 장고설치
 pip3 install django==2.2.3