☆☆ 新着記事 ☆☆

2018年12月20日木曜日

* (失敗)SCLからPython3.6 をインストールしてFlaskを動かす試み

mod_wsgiの動作する環境を作る。

Step: 1 Installing mod_wsgi
Step: 2Creating a .wsgi file
Step3: Configuring Apache


Step1 :pipでmod_wsgiをインストールする際の、SCLを使ったPython を利用している場合の
     必要なパッケージの事前インストール。
    https://pypi.org/project/mod_wsgi/
    
    If you are using the Software Collections Library (SCL) packages with RHEL, CentOS or
    Fedora, you would need:
    ・httpd24
    ・httpd24-httpd-devel
    [root@  /]# yum list available | grep httpd24
    httpd24.x86_64                             1.1-18.el7         centos-sclo-rh
    httpd24-httpd-devel.x86_64          2.4.34-7.el7  centos-sclo-rh
    [root@ip2h3wsy /]# yum install httpd24 httpd24-httpd-devel


Step2:  Installing mod_wsgi

  ・pipでインストールするか、yumでインストールするかの確認
   (Windowsにインストールする場合、pipでインストール以外の選択肢はない。)

  (pipの場合)
   [root@ /]# pip install mod_wsgi==
  Collecting mod_wsgi==
  Could not find a version that satisfies the requirement mod_wsgi== (from versions: 4.1.0, 4.1.1, 
 4.1.2, 4.1.3, --略--4.6.4, 4.6.5)

 (yumの場合)
 [root@/]# yum list available | grep mod_wsgi
 mod_wsgi.x86_64                               3.4-18.el7               base
 python27-mod_wsgi.x86_64                   4.5.13-2.el7           centos-sclo-rh
 python33-mod_wsgi.x86_64                   3.4-13.el7             centos-sclo-rh
 rh-python34-mod_wsgi.x86_64                4.4.3-2.el7            centos-sclo-rh
 rh-python35-mod_wsgi.x86_64                4.4.21-1.el7           centos-sclo-rh
 rh-python36-mod_wsgi.x86_64                4.5.18-1.el7           centos-sclo-rh

 結果、最新版を入手できるpipでインストールしてみる。

 $ pip install mod_wsgi==4.6.5
 Successfully installed mod-wsgi-4.6.5

 「成功すると、/etc/httpd/modules 内に mod_wsgi.so が追加されます。」と書いているブログがありますが、
  自分の場合は、この段階でmodulesフォルダをチェックしてもmod_wsgi.soはありません。


Step: 2 Creating a .wsgi file a

 次に、拡張子 「.wsgi 」をつけたwsgiファイルを作成します。

 設置場所:アプリケーション・ファイルを設置するのと同じディレクトリ
        (今回は、var/www/html/flaskpj
  ファイル名:mossymob.wsgi
  記述内容:

1) For most applications the following file should be sufficient.

  from yourapplication import app as application


Store that file somewhere that you will find it again (e.g.: /var/www/yourapplication) and make sure that yourapplication and all the libraries that are in use are on the python load path. If you don’t want to install it system wide consider using a virtual python instance. Keep in mind that you will have to actually install your application into the virtualenv as well. Alternatively there is the option to just patch the path in the .wsgi file before the import:

 import sys sys.path.insert(0, '/path/to/the/application')

( '代替的に、' と書いてあるので、venv内に設置すればこの記述は不要、と理解。)

2) Working with Virtual Environments (仮想環境用)
   For Python 3 add the following lines to the top of your .wsgi file:

   activate_this = '/path/to/env/bin/activate_this.py'
   with open(activate_this) as file_:
       exec(file_.read(), dict(__file__=activate_this))


   Keep in mind that the path has to be absolute.

以上のことから、mossymob.wsgi ファイルの記述内容は、

  from yourapplication import app as application
  
    activate_this = 'var/www/html/flaskpj/bin/activate_this.py'
    with
open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))


参考)
1) Flask:mod_wsgi (Apache)
http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/
2) mod_wsgi : Quick Installation Guide
https://modwsgi.readthedocs.io/en/develop/user-guides/quick-installation-guide.html
3) mod_wsgi 4.6.5       
https://pypi.org/project/mod_wsgi/
3) Setting up a web-server for flask-app deployment in mod_wsgi :: Part-2 ::
https://codeflu.blog/2014/10/11/setting-up-a-web-server-for-flask-app-deployment-in-mod_wsgi-part-2/

https://blog.mktia.com/how-to-run-python-scripts-in-apache-using-mod-wsgi/

0 件のコメント:

コメントを投稿