apache配置部署django和php項目


關於apache設置,一台服務器支持多網站多域名,同一域名下也可以訪問多個端口

當apache在讀取httpd.conf過程中遇到NameVirtuaHost指令時,它為指定的IP地址建立一個虛擬主機表;當apache分析 httpd.conf時,每當它遇見一個<VirtualHost>指令,該指令指定的IP地址與前面分配給虛擬主機駐留的IP地址相同時, 它都在虛擬主機列表上為該IP地址添加虛擬主機;當它找到一個虛擬主機,其  ServerName指令與輸入請求的Host頭部匹配時,apache就使用該虛擬主機容器中的配置來響應該請求,即使用多個名字指向同一個ip地址。 在本例中,Web主機只擁有一個IP地址(合法地址)200.1.1.1,使用基於主機名稱的方式設定多個虛擬主機。

我配置時候出現過很多問題,我的php項目是5.4.45,32位的,Django項目是python36,64位下創建的

使用過:系統win7_64位,windows server 2012 R2_64位,apache2.4_32位,apache2.4_64位,php5.6.40_vc11_32位,php_7.1.26_vc14_64位,php7_vc14_32位,php5.4.45_vc11_32位,python36_64位,python36_32位,mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl,mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win_amd64.whl,

得到結果:因為擔心vc環境影響,直接安裝編譯vc11,vc14. 所有問題與系統位數,django版本沒有關系,和apache位數有直接關系。mod_wsgi的位數下載安裝時候,一定要和Python環境相對應。php項目版本過低,加載php文件時,無法使用ThinkPHP框架,及無論怎么配置,無法和php7.X配合使用。

成功案例:

apache2.4_64位+mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win_amd64.whl+python36_64位;

apache2.4_32位+php5.4.45_vc11_32位;

apache2.4_32位+mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl+python36_32位

apache2.4_32位+mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl+python36_32位+php5.6.40_vc11_32位

...

下載

下載地址:
http://php.net/

windows版下載地址:
http://windows.php.net/download

官網里Windows的版本有很多。選擇哪個版本呢?

如果你的PHP應用程序以FastCGI方式運行,請選擇Non-Thread Safe (NTS) 版本;
如果你的PHP應用程序和Apache一起,請選擇 Thread Safe (TS) 版本。

本文用的apache+php組合,所以選擇ts(Thread Safe)版本。根據操作系統選擇x64或者x86。

大多數版本的PHP使用VC9, VC11 or VC14 (Visual Studio 2008, 2012 or 2015分別編譯)進行編譯的,所以你電腦上需要安裝VC運行環境。

電腦需要VC運行環境:


VC9 x86 :http://www.microsoft.com/en-us/download/details.aspx?id=5582


VC9 x64 :http://www.microsoft.com/en-us/download/details.aspx?id=15336


VC11 x86 or x64:http://www.microsoft.com/en-us/download/details.aspx?id=30679


VC14 x86 or x64 :http://www.microsoft.com/en-us/download/details.aspx?id=48145

配置PHP

本文以php-5.6.40-Win32-VC11-x86為例

我是下載之后直接解壓到C盤。

1.復制一份php.ini-development文件為php.ini

2.

需要修改以下地方:

  • 更改自定義擴展目錄。
    找到
;extension_dir = "ext"

更改為:

 extension_dir = "C:\php-5.6.40-Win32-VC11-x86\ext"

提示:與apache搭配使用需要寫絕對位置。否則擴展加載不了。

  • 開啟擴展
    往下看,再找到:

去掉部分注釋:

extension=php_bz2.dll extension=php_curl.dll extension=php_fileinfo.dll extension=php_gd2.dll extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ;extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_ldap.dll extension=php_mbstring.dll extension=php_exif.dll ; Must be after mbstring as it depends on it extension=php_mysql.dll extension=php_mysqli.dll ;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client extension=php_openssl.dll ;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll extension=php_pdo_odbc.dll extension=php_pdo_pgsql.dll extension=php_pdo_sqlite.dll extension=php_pgsql.dll ;extension=php_shmop.dll ; The MIBS data available in the PHP distribution must be installed. ; See http://www.php.net/manual/en/snmp.installation.php ;extension=php_snmp.dll extension=php_soap.dll extension=php_sockets.dll extension=php_sqlite3.dll ;extension=php_sybase_ct.dll extension=php_tidy.dll extension=php_xmlrpc.dll extension=php_xsl.dll
  • 設置默認時區
date.timezone=PRC
  • 設置ssl(可選)
openssl.cafile= cacert.pem

注意是絕對路徑。

注意是絕對路徑。

  • 添加自定義擴展(根據自己需要)
[memcache] extension=php_memcache.dll [redis] extension=php_redis.dll

注意,需要下載對應版本的擴展:
php_redis-2.2.7-5.6-ts-vc11-x86
區分ts,x86。

下載地址
http://pecl.php.net/package/redis/
http://pecl.php.net/package/memcache
http://pecl.php.net/package/SeasLog
http://pecl.php.net/package/xdebug
http://pecl.php.net/package/yar

apache的安裝與配置

下載apache

PHP官網里說明了,apache.org只提供舊的VC6版本,且不能使用 VC9+版本。apache.org已經不提供適合php的版本了。apache windows版本下載地址也給了下載建議:

PHP官網也建議到Apache Lounge下載。Apache Lounge提供了建立在x86和x64系統的VC9,vc14 VC11版本。PHP官方使用了他們提供的二進制文件構建Apache SAPIs。

Apache Lounge提供的下載地址:
http://www.apachelounge.com/download/VC11/

http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.20-win64-VC11.zip
http://www.apachelounge.com/download/VC11/binaries/httpd-2.4.20-win32-VC11.zip

這里選擇httpd-2.4.38-win32-VC14.zip

安裝配置

把下載好的httpd-2.4.38-win32-VC14.zip的包同樣解壓到C:/Apache目錄下。

接下來,我們來配置apache,讓它能夠和php協同工作。

進入apache的conf目錄,打開apache的配置文件httpd.conf。

修改apache軟件所在目錄:

ServerRoot "c:/Apache"

修改主機名:

ServerName localhost:80

修改根目錄:htdocs是我php文件的根目錄

DocumentRoot "C:\myphp\Apache\htdocs" <Directory "C:\myphp\Apache\htdocs">

修改默認索引以支持PHP:

DirectoryIndex index.php index.html index.htm 

開啟rewrite功能:

LoadModule rewrite_module modules/mod_rewrite.so

自定義404頁面(可選):

ErrorDocument 404 /missing.html

加載PHP模塊,注意絕對路徑:

LoadModule php5_module C:\php-5.6.40-Win32-VC11-x86/php5apache2_4.dll 
<IfModule php5_module> 
    PHPIniDir "C:/php-5.6.40-Win32-VC11-x86/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

如果是php7,相應更改即可:

#php7
LoadModule php7_module D:/phpsetup/php/php-7.0.13-Win32-VC14-x64/php7apache2_4.dll
<IfModule php7_module> 
    PHPIniDir "D:/phpsetup/php/php-7.0.13-Win32-VC14-x64/" 
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
</IfModule>

注意:如果是PHP5.4版本,php目錄里只有php5apache2_2.dll,需要和Apache2.2搭配。
所以,安裝php5.6一定要確認PHP安裝包里是否有php5apache2_4.dll文件。

網上還有一種對於php7的配置方法是(本人沒有使用):

  phpinidir "C:/www/php7"
  loadfile "C:/www/php7/php7ts.dll"
  loadfile "C:/www/php7/ssleay32.dll"
  loadfile "C:/www/php7/libeay32.dll"
  loadmodule php7_module "C:/www/php7/php7apache2_4.dll"

  就是多三行代碼,引入了3個文件,如果上面方法還是不行,可以試試這個方法,因為php7發布沒多長時間,后續這些問題肯定會解決的

可以開啟虛擬主機配置文件:

Include conf/extra/httpd-vhosts.conf

默認httpd-vhosts.conf文件里面寫的是供參考的,一但啟用該文件,請正確配置,否則無法啟用apache服務。

虛擬主機示例:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com     #自己郵箱
    DocumentRoot "C:\myphp\Apache\htdocs"            #項目路徑
    ServerName example.cn                            #域名
    #erverAlias example.com                           # 別名
    DirectoryIndex index.html                            #主進入口
    ServerAlias www.17ai-trade.cn
    ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log ## 錯誤日志記錄的位置
    CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common # 訪問日志的記錄位置
</VirtualHost>

其中DocumentRoot設置項目所在路徑,ServerName設置主機名,DirectoryIndex設置入口文件;

-----------------------------------------------------------------------------------------------------------------

這部分我沒有用,參考文章里面的,

可以開啟主機別名配置文件:

Include conf/extra/httpd-alias.conf

如果安裝的PHP x64位版本,Apache也需要是x64位版本的。然后還要將php目錄下的libeay32.dllssleay32.dlllibssh2.dll以及ext目錄下的php_curl.dll等四個文件,都復制放到System32目錄下。否則curl擴展無法使用。(http://my.oschina.net/lsfop/blog/496181)

--------------------------------------------------------------------------------------------------------------------

運行apache+php

運行方式一:
手動運行bin目錄下的ApacheMonitor.exe

運行方式二:
將apache安裝為系統服務,可以開機自動啟動。

以管理員權限運行cmd。

進入apache的bin目錄,安裝Apache 服務:apache24是你起的名字,這個隨意起

httpd -k install -n apache24

停止Apache

httpd -k stop apache24 

重啟Apache

httpd -k restart

卸載Apache服務

httpd -k uninstall -n apache24 或者sc delete apache24 

測試Apache配置文件httd.conf

httpd -t

查看Apache版本

httpd -V

Apache命令行幫助

httpd -h

刪除服務:

sc delete Apache2.4

測試Apache和PHP

成功啟動Apache后,在C:\myphp\Apache\htdocs目錄編寫phpinfo.php:

<?php echo phpinfo();

瀏覽器地址欄輸入localhost/phpinfo.php,顯示PHP相關信息即表明成功了。具體問題,后面解答

版本選擇總結

Linux下安裝推薦編譯安裝,不用考慮TS、NTS區別。版本建議64位(看機器是否支持)。
PHP7: http://php.net/get/php-7.0.13.tar.bz2/from/a/mirror
php5: http://php.net/get/php-5.6.28.tar.bz2/from/a/mirror
Nginx: http://nginx.org/download/nginx-1.10.2.tar.gz

Windows下安裝時注意:

需要先安裝VC11或VC14:
1)VC11: https://www.microsoft.com/en-us/download/details.aspx?id=30679
2)VC14: https://www.microsoft.com/en-us/download/details.aspx?id=48145

1、如果使用Apache,請使用TS版本PHP:
PHP7:
1)VC14_x86: http://windows.php.net/downloads/releases/php-7.0.13-Win32-VC14-x86.zip
2)VC14_x64:http://windows.php.net/downloads/releases/php-7.0.13-Win32-VC14-x86.zip

PHP5:
1)VC11_x86: http://windows.php.net/downloads/releases/php-5.6.28-Win32-VC11-x86.zip
1)VC11_x64: http://windows.php.net/downloads/releases/php-5.6.28-Win32-VC11-x64.zip

Apache:
1、VC14_x64: https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.23-win64-VC14.zip
2、VC14_x86: https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.23-win32-VC14.zip
3、VC11_x64:https://www.apachelounge.com/download/VC11/binaries/httpd-2.4.23-win64-VC11.zip
4、VC11_x86:https://www.apachelounge.com/download/VC11/binaries/httpd-2.4.23-win32-VC11.zip

搭配原則是:VC14+PHP7_TS+Apache_VC14 、VC11+PHP5_TS+Apache_VC11。

2、如果使用Nginx,請使用NTS版本PHP:

PHP7:
1)VC14_x86: http://windows.php.net/downloads/releases/php-7.0.13-nts-Win32-VC14-x86.zip
2)VC14_x64:http://windows.php.net/downloads/releases/php-7.0.13-nts-Win32-VC14-x64.zip

PHP5:
1)VC11_x86: http://windows.php.net/downloads/releases/php-5.6.28-nts-Win32-VC11-x86.zip
1)VC11_x64: http://windows.php.net/downloads/releases/php-5.6.28-nts-Win32-VC11-x64.zip

Nginx: http://nginx.org/download/nginx-1.10.2.zip

安裝python及其mod_wsgi

安裝python36_32位

網上有很多方式,這里不做敘述,只是需要注意下載和apache版本一致的

安裝mod_wsgi

1.注意,因為apache是32位的,所以mod_wsgi也應該選擇32位的。mod_wsgi的官網在這里(https://code.google.com/p/modwsgi/)。但是因為沒有windows編譯版本(自己編譯幾乎都是以失敗告終),所幸在這里可以下載到編譯版本(http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi),這里選擇mod_wsgi-4.6.5+ap24vc14-cp36-cp36m-win32.whl

2.將你下載的.whl 文件,放在一個目錄中,我放在了 python的 \Scripts 文件夾中,然后 使用cmd cd命令到這個目錄

    使用pip 命令進行安裝 :pip install mod_wsgi-4.6.4+ap24vc14-cp36-none-win_amd64.whl

注意,現在目錄一個在  python的 \Scripts 因為這東西安裝完,你會發現在這個目錄有一個 mod_wsgi-express.exe 的東西哦

安裝完畢之后,執行命令:mod_wsgi-express module-config 

命令執行完畢之后 你會得到以下內容

LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll" LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd" WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"

把這三行目錄加載到apache的配置文件當中,即httpd.conf文件中,相當於apache加載mod_wsgi模塊。

3.添加監聽端口,這里要部署兩個項目,一個php一個django,所以設置兩個端口:

Listen80

Listen8080

4.打開conf/extra/httpd-vhosts.conf文件,添加對每個項目的參數設置,跟單個項目設置差不多

<VirtualHost *:8080> ServerAdmin webmaster@dummy-host2.example.com ServerName 17ai-trade.cn ServerAlias www.17ai-trade.cn ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common #設置wsgi路徑 WSGIScriptAlias / C:/myphp/Apache/mypro/mypro/wsgi.py # 根目錄 DocumentRoot "C:/myphp/Apache/mypro" <Directory C:/myphp/Apache/mypro/mypro> <Files wsgi.py> Require all granted </Files> </Directory> #設置靜態文件路徑 Alias /static C:/myphp/Apache/mypro/static <Directory C:/myphp/Apache/mypro/static> AllowOverride None Options None Require all granted </Directory> #設置根目錄 #<Directory "C:/myphp/Apache/mypro"> # Options Indexes FollowSymLinks #AllowOverride None #Require all granted #</Directory> </VirtualHost>

遇到的問題:

demo01:    apache配置php 頁面運行完輸出php源代碼是什么原因

網上說,php沒有加載上,也可能php.ini中的配置里面short_open_tag默認是off要改成on才行,我這里都修改過一遍,都不行,最后我把apache跟換成和php版本一致的,32位。才可以訪問。

demo02:     You don't have permission to access / on this server

參考:https://blog.csdn.net/qq_21956483/article/details/78732160

demo03:    Cant load modules/mod_wsgi.so

加載模塊的方式不對,請參考本文的方式,或查閱更多。

demo04:    解決apache開始時出現的“ (OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次” 這個錯誤

Installing the 'apache' service

The 'apache' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
(OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次。  : AH00072: mak
e_sock: could not bind to address [::]:443
(OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次。  : AH00072: mak
e_sock: could not bind to address 0.0.0.0:443
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs

方法一: 
      通過 netstat -a -o 查看端口占用情況,關閉調用相關端口的進程。 
c:\> netstat -a -o 

http默認用的是80端口,通過該http協議去查看對應的PID。 
      通過打開“進程管理器”,發現80端口對應的PID=4676的進程號所對應的是迅雷的一個端口號。 
      查看迅雷的端口設置,“配置”→“BT/端口設置”,可以看到TCP端口使用的是 80號端口。點擊一下“隨機生成”,或者 關閉迅雷。再啟動 Apache,一切就OK了。

方法二: 
      通過 修改conf/httpd.conf 中相應的監聽端口來處理。 

打開Apache 的配置文件  Apache安裝目錄下的conf/httpd.conf

找到Listen 80 將80改為 5001

重啟Apache訪問 http://localhost:5001

方法三:

    我把上面兩步全部嘗試,最后還是那個問題,最后發覺是我虛擬機的干擾,應該關閉就好,我沒嘗試,直接卸載了。重啟訪問,OK。網上有效的解決方式是:

windows下啟動apache報make_sock: could not bind to address [::]:443錯誤!
由於安裝了虛擬機VMWare,被占用443端口
解決方法:
打開虛擬機VMware,打開菜單 編輯→首選項(Edit–> Preferences)
點擊共享虛擬機后,找到右邊的更改設置,點擊它
在端口號處,輸入444,點擊確定,大功告成

demo05:   訪問php成功,但訪問django是服務無法訪問,配置出錯,單獨訪問,不加虛擬主機時,即只在httpd.conf文件配置時,沒有問題。查看日志,連續行出現一堆問題,說什么mod_wsgi的問題,原本以為是沒有加載這個模塊,但單獨配置又是可以,猜測是wsgi文件問題,嘗試修改了一下,成功。

 

[Fri Jan 25 10:35:29.036672 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] mod_wsgi (pid=3692): Failed to exec Python script file 'C:/myphp/Apache/mypro/mypro/wsgi.py'. [Fri Jan 25 10:35:29.036672 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] mod_wsgi (pid=3692): Exception occurred processing WSGI script 'C:/myphp/Apache/mypro/mypro/wsgi.py'. [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] Traceback (most recent call last):\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "C:/myphp/Apache/mypro/mypro/wsgi.py", line 16, in <module>\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] application = get_wsgi_application()\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "c:\\users\\administrator\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] django.setup(set_prefix=False)\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "<frozen importlib._bootstrap>", line 971, in _find_and_load\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked\r [Fri Jan 25 10:35:29.037653 2019] [wsgi:error] [pid 3692:tid 1060] [client ::1:57168] ModuleNotFoundError: No module named 'mypro'\r

wsgi.py文件中添加以下語句

import sys root = os.path.join(os.path.dirname(__file__), '..') # add parent path sys.path.insert(0, root) # add to sys path

 

 

附加:

apache的配置文件httpd.conf:

  1 #
  2 # This is the main Apache HTTP server configuration file.  It contains the
  3 # configuration directives that give the server its instructions.
  4 # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
  5 # In particular, see 
  6 # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
  7 # for a discussion of each configuration directive.
  8 #
  9 # Do NOT simply read the instructions in here without understanding
 10 # what they do.  They're here only as hints or reminders.  If you are unsure
 11 # consult the online docs. You have been warned.  
 12 #
 13 # Configuration and logfile names: If the filenames you specify for many
 14 # of the server's control files begin with "/" (or "drive:/" for Win32), the
 15 # server will use that explicit path.  If the filenames do *not* begin
 16 # with "/", the value of ServerRoot is prepended -- so "logs/access_log"
 17 # with ServerRoot set to "/usr/local/apache2" will be interpreted by the
 18 # server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" 
 19 # will be interpreted as '/logs/access_log'.
 20 #
 21 # NOTE: Where filenames are specified, you must use forward slashes
 22 # instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
 23 # If a drive letter is omitted, the drive on which httpd.exe is located
 24 # will be used by default.  It is recommended that you always supply
 25 # an explicit drive letter in absolute paths to avoid confusion.
 26 
 27 #
 28 # ServerRoot: The top of the directory tree under which the server's
 29 # configuration, error, and log files are kept.
 30 #
 31 # Do not add a slash at the end of the directory path.  If you point
 32 # ServerRoot at a non-local disk, be sure to specify a local disk on the
 33 # Mutex directive, if file-based mutexes are used.  If you wish to share the
 34 # same ServerRoot for multiple httpd daemons, you will need to change at
 35 # least PidFile.
 36 #
 37 Define SRVROOT "c:/Apache"
 38 
 39 ServerRoot "${SRVROOT}"
 40 
 41 #
 42 # Mutex: Allows you to set the mutex mechanism and mutex file directory
 43 # for individual mutexes, or change the global defaults
 44 #
 45 # Uncomment and change the directory if mutexes are file-based and the default
 46 # mutex file directory is not on a local disk or is not appropriate for some
 47 # other reason.
 48 #
 49 # Mutex default:logs
 50 
 51 #
 52 # Listen: Allows you to bind Apache to specific IP addresses and/or
 53 # ports, instead of the default. See also the <VirtualHost>
 54 # directive.
 55 #
 56 # Change this to Listen on specific IP addresses as shown below to 
 57 # prevent Apache from glomming onto all bound IP addresses.
 58 #
 59 #Listen 12.34.56.78:80
 60 Listen 80
 61 Listen 8080
 62 
 63 #
 64 # Dynamic Shared Object (DSO) Support
 65 #
 66 # To be able to use the functionality of a module which was built as a DSO you
 67 # have to place corresponding `LoadModule' lines at this location so the
 68 # directives contained in it are actually available _before_ they are used.
 69 # Statically compiled modules (those listed by `httpd -l') do not need
 70 # to be loaded here.
 71 #
 72 # Example:
 73 # LoadModule foo_module modules/mod_foo.so
 74 #
 75 LoadModule access_compat_module modules/mod_access_compat.so
 76 LoadModule actions_module modules/mod_actions.so
 77 LoadModule alias_module modules/mod_alias.so
 78 LoadModule allowmethods_module modules/mod_allowmethods.so
 79 LoadModule asis_module modules/mod_asis.so
 80 LoadModule auth_basic_module modules/mod_auth_basic.so
 81 #LoadModule auth_digest_module modules/mod_auth_digest.so
 82 #LoadModule auth_form_module modules/mod_auth_form.so
 83 #LoadModule authn_anon_module modules/mod_authn_anon.so
 84 LoadModule authn_core_module modules/mod_authn_core.so
 85 #LoadModule authn_dbd_module modules/mod_authn_dbd.so
 86 #LoadModule authn_dbm_module modules/mod_authn_dbm.so
 87 LoadModule authn_file_module modules/mod_authn_file.so
 88 #LoadModule authn_socache_module modules/mod_authn_socache.so
 89 #LoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so
 90 #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
 91 LoadModule authz_core_module modules/mod_authz_core.so
 92 #LoadModule authz_dbd_module modules/mod_authz_dbd.so
 93 #LoadModule authz_dbm_module modules/mod_authz_dbm.so
 94 LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
 95 LoadModule authz_host_module modules/mod_authz_host.so
 96 #LoadModule authz_owner_module modules/mod_authz_owner.so
 97 LoadModule authz_user_module modules/mod_authz_user.so
 98 LoadModule autoindex_module modules/mod_autoindex.so
 99 #LoadModule brotli_module modules/mod_brotli.so
100 #LoadModule buffer_module modules/mod_buffer.so
101 #LoadModule cache_module modules/mod_cache.so
102 #LoadModule cache_disk_module modules/mod_cache_disk.so
103 #LoadModule cache_socache_module modules/mod_cache_socache.so
104 #LoadModule cern_meta_module modules/mod_cern_meta.so
105 LoadModule cgi_module modules/mod_cgi.so
106 #LoadModule charset_lite_module modules/mod_charset_lite.so
107 #LoadModule data_module modules/mod_data.so
108 #LoadModule dav_module modules/mod_dav.so
109 #LoadModule dav_fs_module modules/mod_dav_fs.so
110 #LoadModule dav_lock_module modules/mod_dav_lock.so
111 #LoadModule dbd_module modules/mod_dbd.so
112 #LoadModule deflate_module modules/mod_deflate.so
113 LoadModule dir_module modules/mod_dir.so
114 #LoadModule dumpio_module modules/mod_dumpio.so
115 LoadModule env_module modules/mod_env.so
116 #LoadModule expires_module modules/mod_expires.so
117 #LoadModule ext_filter_module modules/mod_ext_filter.so
118 #LoadModule file_cache_module modules/mod_file_cache.so
119 #LoadModule filter_module modules/mod_filter.so
120 #LoadModule http2_module modules/mod_http2.so
121 #LoadModule headers_module modules/mod_headers.so
122 #LoadModule heartbeat_module modules/mod_heartbeat.so
123 #LoadModule heartmonitor_module modules/mod_heartmonitor.so
124 #LoadModule ident_module modules/mod_ident.so
125 #LoadModule imagemap_module modules/mod_imagemap.so
126 LoadModule include_module modules/mod_include.so
127 #LoadModule info_module modules/mod_info.so
128 LoadModule isapi_module modules/mod_isapi.so
129 #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
130 #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
131 #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
132 #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
133 #LoadModule ldap_module modules/mod_ldap.so
134 #LoadModule logio_module modules/mod_logio.so
135 LoadModule log_config_module modules/mod_log_config.so
136 #LoadModule log_debug_module modules/mod_log_debug.so
137 #LoadModule log_forensic_module modules/mod_log_forensic.so
138 #LoadModule lua_module modules/mod_lua.so
139 #LoadModule macro_module modules/mod_macro.so
140 #LoadModule md_module modules/mod_md.so
141 LoadModule mime_module modules/mod_mime.so
142 #LoadModule mime_magic_module modules/mod_mime_magic.so
143 LoadModule negotiation_module modules/mod_negotiation.so
144 #LoadModule proxy_module modules/mod_proxy.so
145 #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
146 #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
147 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
148 #LoadModule proxy_express_module modules/mod_proxy_express.so
149 #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
150 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
151 #LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
152 #LoadModule proxy_html_module modules/mod_proxy_html.so
153 #LoadModule proxy_http_module modules/mod_proxy_http.so
154 #LoadModule proxy_http2_module modules/mod_proxy_http2.so
155 #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
156 #LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
157 #LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
158 #LoadModule ratelimit_module modules/mod_ratelimit.so
159 #LoadModule reflector_module modules/mod_reflector.so
160 #LoadModule remoteip_module modules/mod_remoteip.so
161 #LoadModule request_module modules/mod_request.so
162 #LoadModule reqtimeout_module modules/mod_reqtimeout.so
163 LoadModule rewrite_module modules/mod_rewrite.so
164 #LoadModule sed_module modules/mod_sed.so
165 #LoadModule session_module modules/mod_session.so
166 #LoadModule session_cookie_module modules/mod_session_cookie.so
167 #LoadModule session_crypto_module modules/mod_session_crypto.so
168 #LoadModule session_dbd_module modules/mod_session_dbd.so
169 LoadModule setenvif_module modules/mod_setenvif.so
170 #LoadModule slotmem_plain_module modules/mod_slotmem_plain.so
171 #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
172 #LoadModule socache_dbm_module modules/mod_socache_dbm.so
173 #LoadModule socache_memcache_module modules/mod_socache_memcache.so
174 #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
175 #LoadModule speling_module modules/mod_speling.so
176 #LoadModule ssl_module modules/mod_ssl.so
177 #LoadModule status_module modules/mod_status.so
178 #LoadModule substitute_module modules/mod_substitute.so
179 #LoadModule unique_id_module modules/mod_unique_id.so
180 #LoadModule userdir_module modules/mod_userdir.so
181 #LoadModule usertrack_module modules/mod_usertrack.so
182 #LoadModule version_module modules/mod_version.so
183 #LoadModule vhost_alias_module modules/mod_vhost_alias.so
184 #LoadModule watchdog_module modules/mod_watchdog.so
185 #LoadModule xml2enc_module modules/mod_xml2enc.so
186 
187 <IfModule unixd_module>
188 #
189 # If you wish httpd to run as a different user or group, you must run
190 # httpd as root initially and it will switch.  
191 #
192 # User/Group: The name (or #number) of the user/group to run httpd as.
193 # It is usually good practice to create a dedicated user and group for
194 # running httpd, as with most system services.
195 #
196 User daemon
197 Group daemon
198 
199 </IfModule>
200 
201 # 'Main' server configuration
202 #
203 # The directives in this section set up the values used by the 'main'
204 # server, which responds to any requests that aren't handled by a
205 # <VirtualHost> definition.  These values also provide defaults for
206 # any <VirtualHost> containers you may define later in the file.
207 #
208 # All of these directives may appear inside <VirtualHost> containers,
209 # in which case these default settings will be overridden for the
210 # virtual host being defined.
211 #
212 
213 #
214 # ServerAdmin: Your address, where problems with the server should be
215 # e-mailed.  This address appears on some server-generated pages, such
216 # as error documents.  e.g. admin@your-domain.com
217 #
218 ServerAdmin admin@example.com
219 
220 #
221 # ServerName gives the name and port that the server uses to identify itself.
222 # This can often be determined automatically, but we recommend you specify
223 # it explicitly to prevent problems during startup.
224 #
225 # If your host doesn't have a registered DNS name, enter its IP address here.
226 #
227 ServerName localhost:80
228 
229 #
230 # Deny access to the entirety of your server's filesystem. You must
231 # explicitly permit access to web content directories in other 
232 # <Directory> blocks below.
233 #
234 <Directory />
235     AllowOverride none
236     Require all denied
237 </Directory>
238 
239 #
240 # Note that from this point forward you must specifically allow
241 # particular features to be enabled - so if something's not working as
242 # you might expect, make sure that you have specifically enabled it
243 # below.
244 #
245 
246 #
247 # DocumentRoot: The directory out of which you will serve your
248 # documents. By default, all requests are taken from this directory, but
249 # symbolic links and aliases may be used to point to other locations.
250 #
251 DocumentRoot "C:\myphp\Apache\htdocs"
252 <Directory "C:\myphp\Apache\htdocs">
253     #
254     # Possible values for the Options directive are "None", "All",
255     # or any combination of:
256     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
257     #
258     # Note that "MultiViews" must be named *explicitly* --- "Options All"
259     # doesn't give it to you.
260     #
261     # The Options directive is both complicated and important.  Please see
262     # http://httpd.apache.org/docs/2.4/mod/core.html#options
263     # for more information.
264     #
265     Options Indexes FollowSymLinks
266 
267     #
268     # AllowOverride controls what directives may be placed in .htaccess files.
269     # It can be "All", "None", or any combination of the keywords:
270     #   AllowOverride FileInfo AuthConfig Limit
271     #
272     AllowOverride None
273 
274     #
275     # Controls who can get stuff from this server.
276     #
277     Require all granted
278 </Directory>
279 
280 #
281 # DirectoryIndex: sets the file that Apache will serve if a directory
282 # is requested.
283 #
284 <IfModule dir_module>
285     DirectoryIndex index.html index.htm index.php
286 </IfModule>
287 
288 #
289 # The following lines prevent .htaccess and .htpasswd files from being 
290 # viewed by Web clients. 
291 #
292 <Files ".ht*">
293     Require all denied
294 </Files>
295 
296 #
297 # ErrorLog: The location of the error log file.
298 # If you do not specify an ErrorLog directive within a <VirtualHost>
299 # container, error messages relating to that virtual host will be
300 # logged here.  If you *do* define an error logfile for a <VirtualHost>
301 # container, that host's errors will be logged there and not here.
302 #
303 ErrorLog "logs/error.log"
304 
305 #
306 # LogLevel: Control the number of messages logged to the error_log.
307 # Possible values include: debug, info, notice, warn, error, crit,
308 # alert, emerg.
309 #
310 LogLevel warn
311 
312 <IfModule log_config_module>
313     #
314     # The following directives define some format nicknames for use with
315     # a CustomLog directive (see below).
316     #
317     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
318     LogFormat "%h %l %u %t \"%r\" %>s %b" common
319 
320     <IfModule logio_module>
321       # You need to enable mod_logio.c to use %I and %O
322       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
323     </IfModule>
324 
325     #
326     # The location and format of the access logfile (Common Logfile Format).
327     # If you do not define any access logfiles within a <VirtualHost>
328     # container, they will be logged here.  Contrariwise, if you *do*
329     # define per-<VirtualHost> access logfiles, transactions will be
330     # logged therein and *not* in this file.
331     #
332     CustomLog "logs/access.log" common
333 
334     #
335     # If you prefer a logfile with access, agent, and referer information
336     # (Combined Logfile Format) you can use the following directive.
337     #
338     #CustomLog "logs/access.log" combined
339 </IfModule>
340 
341 <IfModule alias_module>
342     #
343     # Redirect: Allows you to tell clients about documents that used to 
344     # exist in your server's namespace, but do not anymore. The client 
345     # will make a new request for the document at its new location.
346     # Example:
347     # Redirect permanent /foo http://www.example.com/bar
348 
349     #
350     # Alias: Maps web paths into filesystem paths and is used to
351     # access content that does not live under the DocumentRoot.
352     # Example:
353     # Alias /webpath /full/filesystem/path
354     #
355     # If you include a trailing / on /webpath then the server will
356     # require it to be present in the URL.  You will also likely
357     # need to provide a <Directory> section to allow access to
358     # the filesystem path.
359 
360     #
361     # ScriptAlias: This controls which directories contain server scripts. 
362     # ScriptAliases are essentially the same as Aliases, except that
363     # documents in the target directory are treated as applications and
364     # run by the server when requested rather than as documents sent to the
365     # client.  The same rules about trailing "/" apply to ScriptAlias
366     # directives as to Alias.
367     #
368     ScriptAlias /cgi-bin/ "C:\Apache/cgi-bin/"
369 
370 </IfModule>
371 
372 <IfModule cgid_module>
373     #
374     # ScriptSock: On threaded servers, designate the path to the UNIX
375     # socket used to communicate with the CGI daemon of mod_cgid.
376     #
377     #Scriptsock cgisock
378 </IfModule>
379 
380 #
381 # "${SRVROOT}/cgi-bin" should be changed to whatever your ScriptAliased
382 # CGI directory exists, if you have that configured.
383 #
384 <Directory "C:\Apache/cgi-bin">
385     AllowOverride None
386     Options None
387     Require all granted
388 </Directory>
389 
390 <IfModule headers_module>
391     #
392     # Avoid passing HTTP_PROXY environment to CGI's on this or any proxied
393     # backend servers which have lingering "httpoxy" defects.
394     # 'Proxy' request header is undefined by the IETF, not listed by IANA
395     #
396     RequestHeader unset Proxy early
397 </IfModule>
398 
399 <IfModule mime_module>
400     #
401     # TypesConfig points to the file containing the list of mappings from
402     # filename extension to MIME-type.
403     #
404     TypesConfig conf/mime.types
405 
406     #
407     # AddType allows you to add to or override the MIME configuration
408     # file specified in TypesConfig for specific file types.
409     #
410     #AddType application/x-gzip .tgz
411     #
412     # AddEncoding allows you to have certain browsers uncompress
413     # information on the fly. Note: Not all browsers support this.
414     #
415     #AddEncoding x-compress .Z
416     #AddEncoding x-gzip .gz .tgz
417     #
418     # If the AddEncoding directives above are commented-out, then you
419     # probably should define those extensions to indicate media types:
420     #
421     AddType application/x-compress .Z
422     AddType application/x-gzip .gz .tgz
423 
424     #
425     # AddHandler allows you to map certain file extensions to "handlers":
426     # actions unrelated to filetype. These can be either built into the server
427     # or added with the Action directive (see below)
428     #
429     # To use CGI scripts outside of ScriptAliased directories:
430     # (You will also need to add "ExecCGI" to the "Options" directive.)
431     #
432     #AddHandler cgi-script .cgi
433 
434     # For type maps (negotiated resources):
435     #AddHandler type-map var
436 
437     #
438     # Filters allow you to process content before it is sent to the client.
439     #
440     # To parse .shtml files for server-side includes (SSI):
441     # (You will also need to add "Includes" to the "Options" directive.)
442     #
443     #AddType text/html .shtml
444     #AddOutputFilter INCLUDES .shtml
445 </IfModule>
446 
447 #
448 # The mod_mime_magic module allows the server to use various hints from the
449 # contents of the file itself to determine its type.  The MIMEMagicFile
450 # directive tells the module where the hint definitions are located.
451 #
452 #MIMEMagicFile conf/magic
453 
454 #
455 # Customizable error responses come in three flavors:
456 # 1) plain text 2) local redirects 3) external redirects
457 #
458 # Some examples:
459 #ErrorDocument 500 "The server made a boo boo."
460 #ErrorDocument 404 /missing.html
461 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
462 #ErrorDocument 402 http://www.example.com/subscription_info.html
463 #
464 
465 #
466 # MaxRanges: Maximum number of Ranges in a request before
467 # returning the entire resource, or one of the special
468 # values 'default', 'none' or 'unlimited'.
469 # Default setting is to accept 200 Ranges.
470 #MaxRanges unlimited
471 
472 #
473 # EnableMMAP and EnableSendfile: On systems that support it, 
474 # memory-mapping or the sendfile syscall may be used to deliver
475 # files.  This usually improves server performance, but must
476 # be turned off when serving from networked-mounted 
477 # filesystems or if support for these functions is otherwise
478 # broken on your system.
479 # Defaults: EnableMMAP On, EnableSendfile Off
480 #
481 #EnableMMAP off
482 #EnableSendfile on
483 
484 # Supplemental configuration
485 #
486 # The configuration files in the conf/extra/ directory can be 
487 # included to add extra features or to modify the default configuration of 
488 # the server, or you may simply copy their contents here and change as 
489 # necessary.
490 
491 # Server-pool management (MPM specific)
492 #Include conf/extra/httpd-mpm.conf
493 
494 # Multi-language error messages
495 #Include conf/extra/httpd-multilang-errordoc.conf
496 
497 # Fancy directory listings
498 #Include conf/extra/httpd-autoindex.conf
499 
500 # Language settings
501 #Include conf/extra/httpd-languages.conf
502 
503 # User home directories
504 #Include conf/extra/httpd-userdir.conf
505 
506 # Real-time info on requests and configuration
507 #Include conf/extra/httpd-info.conf
508 
509 # Virtual hosts
510 Include conf/extra/httpd-vhosts.conf
511 
512 # Local access to the Apache HTTP Server Manual
513 #Include conf/extra/httpd-manual.conf
514 
515 # Distributed authoring and versioning (WebDAV)
516 #Include conf/extra/httpd-dav.conf
517 
518 # Various default settings
519 #Include conf/extra/httpd-default.conf
520 
521 # Configure mod_proxy_html to understand HTML4/XHTML1
522 <IfModule proxy_html_module>
523 Include conf/extra/proxy-html.conf
524 </IfModule>
525 
526 # Secure (SSL/TLS) connections
527 #Include conf/extra/httpd-ssl.conf
528 #
529 # Note: The following must must be present to support
530 #       starting without SSL on platforms with no /dev/random equivalent
531 #       but a statically compiled-in mod_ssl.
532 #
533 <IfModule ssl_module>
534 SSLRandomSeed startup builtin
535 SSLRandomSeed connect builtin
536 </IfModule>
537 
538 #加載php
539 LoadModule php5_module C:\php-5.6.40-Win32-VC11-x86/php5apache2_4.dll 
540 <IfModule php5_module> 
541     PHPIniDir "C:/php-5.6.40-Win32-VC11-x86/" 
542     AddType application/x-httpd-php .php
543     AddType application/x-httpd-php-source .phps
544 </IfModule>
545 #加載django
546 LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll"
547 LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
548 WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"
549 
550 #指定website的wsgi.py配置文件路徑  
551 #WSGIScriptAlias / C:/myphp/Apache/mypro/mypro/wsgi.py
552 
553 #指定項目路徑  
554 #WSGIPythonPath  C:/myphp/Apache/mypro 
555 #設置wsgi路徑 
556 #<Directory C:/myphp/Apache/mypro/mypro>  
557 #<Files wsgi.py>  
558   #  Require all granted  
559 #</Files>  
560 #</Directory>
561 
562 
563 #設置靜態文件路徑
564 #Alias /static C:/myphp/Apache/mypro/static
565 #<Directory C:/myphp/Apache/mypro/static>  
566  #   AllowOverride None  
567  #   Options None  
568 #    Require all granted  
569 #</Directory> 
httpd.conf

apache的虛擬主機表中的文件httpd-vhosts.conf:

 1 # Virtual Hosts
 2 #
 3 # Required modules: mod_log_config
 4 
 5 # If you want to maintain multiple domains/hostnames on your
 6 # machine you can setup VirtualHost containers for them. Most configurations
 7 # use only name-based virtual hosts so the server doesn't need to worry about
 8 # IP addresses. This is indicated by the asterisks in the directives below.
 9 #
10 # Please see the documentation at 
11 # <URL:http://httpd.apache.org/docs/2.4/vhosts/>
12 # for further details before you try to setup virtual hosts.
13 #
14 # You may use the command line option '-S' to verify your virtual host
15 # configuration.
16 
17 #
18 # VirtualHost example:
19 # Almost any Apache directive may go into a VirtualHost container.
20 # The first VirtualHost section is used for all requests that do not
21 # match a ServerName or ServerAlias in any <VirtualHost> block.
22 #
23 <VirtualHost *:80>
24     ServerAdmin webmaster@dummy-host.example.com
25     DocumentRoot "C:\myphp\Apache\htdocs"
26     ServerName 17ai-trade.cn
27     DirectoryIndex index.html
28     ServerAlias www.17ai-trade.cn
29     ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log
30     CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common
31 </VirtualHost>
32 
33 <VirtualHost *:8080>
34     ServerAdmin webmaster@dummy-host2.example.com
35     ServerName 17ai-trade.cn
36     ServerAlias www.17ai-trade.cn
37     ErrorLog C:\phpStudy\PHPTutorial\Apache\logs\error_django.log
38     CustomLog C:\phpStudy\PHPTutorial\Apache\logs\access_django.log common
39     
40     
41 
42     WSGIScriptAlias / C:/myphp/Apache/mypro/mypro/wsgi.py
43     DocumentRoot "C:/myphp/Apache/mypro"
44     <Directory C:/myphp/Apache/mypro/mypro>  
45         <Files wsgi.py>  
46             Require all granted  
47         </Files>  
48     </Directory>
49 
50 
51     Alias /static C:/myphp/Apache/mypro/static
52     <Directory C:/myphp/Apache/mypro/static>  
53         AllowOverride None  
54         Options None  
55         Require all granted  
56     </Directory>
57     
58     
59     #<Directory "C:/myphp/Apache/mypro">  
60      #   Options Indexes FollowSymLinks
61     #AllowOverride None
62     #Require all granted
63     #</Directory>
64 
65 
66 </VirtualHost>
httpd-vhosts.conf

django中的wsgi.py文件

"""
WSGI config for mypro project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application
import sys

root = os.path.join(os.path.dirname(__file__), '..') # add parent path
sys.path.insert(0, root) # add to sys path

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mypro.settings")

application = get_wsgi_application()
wsgi.py

 

加載單個php項目:https://www.cnblogs.com/xiezhidong/p/6238379.htmlhttps://www.cnblogs.com/52fhy/p/6059685.html

加載單個django項目:https://blog.csdn.net/weixin_40754816/article/details/80955817

使用phpStudy加載django:https://blog.csdn.net/jklf5/article/details/79531379


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM