2017-03-20 39 views
0

我遵循django教程和mod_wsgi安裝指南在LinuxMint18.1上使用Apache和mod_wsg,但是當我運行apache2ctl start時出現錯誤。在Linux上使用mod_wsgi時爲什麼發生錯誤?

Current thread 0x00007f88c10c7780 (most recent call first): 
[Mon Mar 20 21:23:28.781270 2017] [core:notice] [pid 32458:tid 140225331099520] AH00052: child pid 7962 exit signal Aborted (6) 
Fatal Python error: Py_Initialize: can't initialize sys 

我怎麼了?

我按照下面的步驟來安裝Apache和mod_wsgi的:

  1. 易於得到安裝的Apache2
  2. 的apt-get安裝的apache2-dev的
  3. 的apt-get安裝python3.5-dev的
  4. wget的https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.15.tar.gz
  5. 焦油-zxvf mod_wsgi的-4.5.15.tar.gz
  6. CD mod_wsgi的-4.5.15
  7. 的./configure --with-蟒=的/ usr /斌/ python3.5
  8. 使
  9. 使安裝

ls /usr/bin/ -aoh |grep python輸出是:

lrwxrwxrwx 1 root 26 3月 18 09:40 dh_pypy -> ../share/dh-python/dh_pypy 
-rwxr-xr-x 1 root 1.1K 12月 10 2015 dh_python2 
lrwxrwxrwx 1 root 29 3月 18 09:40 dh_python3 -> ../share/dh-python/dh_python3 
lrwxrwxrwx 1 root 23 3月 18 09:40 pdb2.7 -> ../lib/python2.7/pdb.py 
lrwxrwxrwx 1 root 23 3月 18 09:40 pdb3.5 -> ../lib/python3.5/pdb.py 
lrwxrwxrwx 1 root 31 3月 18 09:40 py3versions -> ../share/python3/py3versions.py 
lrwxrwxrwx 1 root 26 3月 18 09:40 pybuild -> ../share/dh-python/pybuild 
lrwxrwxrwx 1 root 18 3月 20 18:36 python -> /usr/bin/python2.7 
lrwxrwxrwx 1 root  9 3月 18 09:40 python2 -> python2.7 
-rwxr-xr-x 1 root 3.4M 11月 19 17:35 python2.7 
lrwxrwxrwx 1 root  9 3月 18 09:40 python3 -> python3.5 
-rwxr-xr-x 1 root 4.3M 11月 18 03:23 python3.5 
lrwxrwxrwx 1 root 33 11月 18 03:23 python3.5-config -> x86_64-linux-gnu-python3.5-config 
-rwxr-xr-x 1 root 4.3M 11月 18 03:23 python3.5m 
lrwxrwxrwx 1 root 34 11月 18 03:23 python3.5m-config -> x86_64-linux-gnu-python3.5m-config 
lrwxrwxrwx 1 root 10 3月 18 09:40 python3m -> python3.5m 
lrwxrwxrwx 1 root 29 3月 18 09:40 pyversions -> ../share/python/pyversions.py 
lrwxrwxrwx 1 root 34 11月 18 03:23 x86_64-linux-gnu-python3.5-config -> x86_64-linux-gnu-python3.5m-config 
-rwxr-xr-x 1 root 3.2K 11月 18 03:20 x86_64-linux-gnu-python3.5m-config 

/etc/apache2/apache2.conf

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so 

WSGIScriptAlias//home/jeffrey/桌面/Workspace/django-env/hello_django/hello_django/wsgi.py 
WSGIPythonHome /home/jeffrey/桌面/Workspace/django-env 
WSGIPythonPath /home/jeffrey/桌面/Workspace/django-env/hello_django 

<Directory /home/jeffrey/桌面/Workspace/django-env/hello_django/hello_django> 
<Files wsgi.py> 
Require all granted 
</Files> 
</Directory> 

項目文件結構:

django-env 
├── hello_django 
│   ├── hello_django 
│   │   └── wsgi.py 
+0

您使用的是virtualenv嗎?什麼是httpd.conf和你的wsgi文件的適當部分? –

+0

這通常表示您已經使用非標準位置中的Python安裝從源代碼構建了mod_wsgi,但是在系統中安裝了具有相同主/次版本的Python版本,並且它正在拾取錯誤的Python共享庫。詳細說明您正在使用的Python版本以及它的安裝位置。 –

+0

@GrahamDumpleton我有詳細的問題,你可以看看它嗎? – Jeffery

回答

0

我遇到了一堆類似的問題,花了相當多的時間解決它們。最後,我寫了下面的說明來使用RHEL7。您可能正在使用Ubuntu,因此請閱讀下面的配方並相應地進行更改。它可能有幫助。

Setup: RHEL 7, Apache 2.4, Python3.5 
------------------------------------------------------------------------- 
1. mod_wsgi-------------------------------------------------------------- 
------------------------------------------------------------------------- 
See how I used my python3.5 interpreter to install mod_wsgi. 
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.5.14.tar.gz 
tar -zxvf 4.5.14.tar.gz 
cd mod_wsgi-4.5.14 
./configure --with-python=/usr/bin/python3.5 
make 
make install 
chmod 755 /usr/lib64/httpd/modules/mod_wsgi.so 

------------------------------------------------------------------------- 
2. conf file------------------------------------------------------------- 
------------------------------------------------------------------------- 
My website conf file in /etc/httpd/conf.d dir 
portal.conf 

LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName portal 
    ServerAlias portal.com 
    DocumentRoot /var/www/html/portal/src/ 

    WSGIDaemonProcess portal python-path=/var/www/html/portal/src:/var/www/html/portal/venv/lib/python3.5/site-packages 
    WSGIApplicationGroup portal 
    WSGIScriptAlias//var/www/html/portal/src/portal/wsgi.py process-group=portal 

    <Directory /var/www/html/portal/src> 
    Require all granted 
    </Directory> 

    <Directory /var/www/html/portal/src/portal> 
    <Files wsgi.py> 
     Require all granted 
    </Files> 
    </Directory> 

    Alias /static /var/www/html/portal/src/static 
    <Directory /var/www/html/portal/src/static> 
    Require all granted 
    </Directory> 

    Alias /static /var/www/html/portal/src/templates 
    <Directory /var/www/html/portal/src/templates> 
    Require all granted 
    </Directory> 

    Alias /static /var/www/html/portal/src/media 
    <Directory /var/www/html/portal/src/media> 
    Require all granted 
    </Directory> 

</VirtualHost> 
------------------------------------------------------------------------- 
Correct permissions on /var/www/html/------------------------------------ 
------------------------------------------------------------------------- 
chgrp -R apache /var/www/html 
find /var/www/html -type d -exec chmod g+rx {} + 
find /var/www/html -type f -exec chmod g+r {} + 

chown -R user1 /var/www/html/ 
find /var/www/html -type d -exec chmod u+rwx {} + 
find /var/www/html -type f -exec chmod u+rw {} + 

find /var/www/html -type d -exec chmod g+s {} + 
+0

當指定虛擬環境用於守護進程模式進程時,不要使用''python-path''來引用''site-packages'',請使用單獨的''python-home''選項來引用虛擬環境的根源。閱讀有關使用mod_wsgi設置虛擬環境的文檔。 http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html –

+0

也推薦你使用''WSGIApplicationGroup%{GLOBAL}''。如果可以的話,避免使用應用程序組的子解釋器。 –

+0

@GrahamDumpleton感謝您的意見。 – nomad

相關問題