01-0005 關於實驗"拍賣系統"的配置與運行【Win10 系統下的Apache源碼的編譯與配置】【失敗】

0.Note

這篇文章最後沒有結果,可以選擇不看!!!

竟然因爲一個小小的問題,在這耗了一天,畢設碰都沒碰,我掙得是發現了個槓精🤕,一直到撞死才知道停下。並不像把問題留到明天,但是今天沒有解決,乾脆放棄得了,沒啥大不了的。
當然啦,如果有幸你知道怎麼解決,請,請務必在評論裏面留下解決方案!跪謝🙏!
#############底層知識真的很重要##############

1.相關說明

What

  • 實驗的代碼,可以在本地模擬網絡拍賣的大致流程,所有的物品屬性會在平臺進行展示,客戶可以拍出或拍入物品,大概就是這麼個功能。
  • 需要在Apache服務器的支持下,在VS上進行開發,用的是C++~

Why

  • 首先,這是學校暑期的一個大型實驗課,當時放棄了參加全國武術比賽的機會,而選擇了在學校裏面做實驗,我也真的是夠傻的!
  • 其次,如今找工作需要用到這個小項目,但時間久遠,運行時的一些操作給忘記了,所以有了這篇文章。

2.相關配置

2.1 資源下載

總目錄:http://mirror.bit.edu.cn/apache/
apache:https://archive.apache.org/dist/httpd/
httpd:https://archive.apache.org/dist/httpd/
apr:https://archive.apache.org/dist/apr/
apr-util:https://archive.apache.org/dist/apr/
openssl:https://ftp.openssl.org/source/old/1.0.2/
pcre:https://ftp.pcre.org/pub/pcre/
activestate:https://www.activestate.com/products/perl/
nasm:Index of /pub/nasm/releasebuilds
Gawk:http://sourceforge.net/projects/gnuwin32/files/gawk/

2.2 遇到的問題

2.2.1 “windows.h”: No such file or directory

ms\uplink.c(11): fatal error C1083: 無法打開包括文件: “windows.h”: No such file or directory

通過運行vcvars32.bat文件,將VS的環境變量加載進來,可以解決該問題。格式如下:

call "D:\Microsoft Visual Studio\Community2019\VC\Auxiliary\Build\vcvars64.bat"

2.2.2 模塊計算機類型“x86”與目標計算機類型“x64”衝突

tmp32dll\uplink.obj : fatal error LNK1112: 模塊計算機類型“x86”與目標計算機類型“x64”衝突

編輯ms/nt.mak (或者ms/ntdll.mak),修改輸入目錄:

# The output directory for everything intersting
OUT_D=out32
# The output directory for all the temporary muck
TMP_D=tmp32
# The output directory for the header files
INC_D=inc32
INCO_D=inc32/openssl

# The output directory for everything intersting
OUT_D=out64
# The output directory for all the temporary muck
TMP_D=tmp64
# The output directory for the header files
INC_D=inc64
INCO_D=inc64/openssl

備註:如果中途嘗試過這種方法,再次嘗試的時候記得刪掉已經有內容inc64等文件夾。


2.2.3 fatal error U1077

fatal error U1077: ““D:\Microsoft Visual Studio\Community2019\VC\Tools\MSVC\14.24.28314\bin\Hostx64\x64\cl.EXE””: 返回代碼“0x2”

備註:忘記了。似乎是跟vcvars32有關。


2.2.4 ‘perl’ 不是內部或外部命令,也不是可運行的程序

‘perl’ 不是內部或外部命令,也不是可運行的程序

這個需要是需要安裝一些程序的,我用的acticeState,下面鏈接可以下載:
Link:https://www.activestate.com/products/perl/


2.2.5 NMAKE : fatal error U1064

NMAKE : fatal error U1064: 未找到 MAKEFILE 並且未指定目標
apr-util NMAKE : fatal error U1064: 未找到 MAKEFILE 並且未指定目標

可能是上一步的apr編譯出錯,apr在build的時候需要選對文件夾,可能直接拷貝了別人的一段指令,沒有修改文件夾。


2.2.6 Could NOT find EXPAT

Could NOT find EXPAT (missing: EXPAT_LIBRARY EXPAT_INCLUDE_DIR)
CMake Error at CMakeLists.txt:65 (MESSAGE):
Expat is required, and it wasn’t found!

由於1.6之後的版本,expet庫不再使用apr-util鏈接,需要自己安裝expat。下載安裝都是比較容易的,但是二進制文件的編譯,我沒有搞得來,底層知識實在是太薄弱了!
Link:https://libexpat.github.io/
最後沒辦法,只能使用1.6版本之前的apr-util:
Link:Index of /dist/apr
具體有哪些變化可以參考下面的鏈接:
Link:Changes with APR-util 1.6.1


2.2.7 lua51.lib : warning LNK4272

D:\app\Lua5.1\lib\lua51.lib : warning LNK4272:庫計算機類型“x86”與目標計算機類型“x64”衝突

備註:解決不來!!!!


2.2.8 mod_lua.so : fatal error LNK1120: 62 個無法解析的外部命令

mod_lua.so : fatal error LNK1120: 62 個無法解析的外部命令
NMAKE : fatal error U1077: “D:\app\CMake\bin\cmake.exe”: 返回代碼“0xffffffff”
Stop.
NMAKE : fatal error U1077: ““D:\Microsoft Visual Studio\Community2019\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe””: 返回代碼“0x2”
Stop.
NMAKE : fatal error U1077: ““D:\Microsoft Visual Studio\Community2019\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64\nmake.exe””: 返回代碼“0x2”
Stop

備註:即使是使用了原文中的 httpd-2.4.12.tar.gz 也不能成功,在最後: Building C object CMakeFiles/mod_lua.dir/modules/lua/lua_request.c.obj的時候會出現問題,還會有D:\app\Lua5.1\lib\lua51.lib : warning LNK4272:庫計算機類型“x86”與目標計算機類型“x64”衝突 的錯誤。

說實在的,沒有找到解決的辦法,我放棄了。


2.2.9 NMAKE : fatal error U1077

NMAKE : fatal error U1077: return code “0xffffffff”

備註:Have no result!!!😢😢😭😭😭


綜述:大隻遇到的問題就這幾種,基本上如果能解決,或是理解,就不會有太大的難處!

2.3 編譯與安裝

參考鏈接:Topic: HOWTO: Building Apache 2.4.x for Windows x64 using CMake
2.3 部分的所有內容,基本上來自上述鏈接。

在努力使用Visual Studio 2013 IDE進行構建時,並且不想依賴Gregg提供的WIN32源代碼之後,我着手定義了一個使用庫存源代碼包且工作量很小的方法。

在WangMaster的努力下,請參見下面我現在使用的過程http://www.apachelounge.com/viewtopic.php?t=6421

2.3.1 軟件準備:

  • Visual Studio 2013 (I use the Community Edition)
  • ActivePerl for Windows (64-bit, currently using 5.20.1.2000)
  • CMake for Windows (currently using 3.1.3)
  • GNU Awk for Windows (currently using 3.1.6-1)
  • Netwide Assembler (NASM) (currently using 2.11.06)

2.3.2 軟件源碼包準備:

(I don’t use ZLIB for Apache or OpenSSL, or LUA/LIBXML2/EXPAT, therefore these are not included in the process)

  • httpd-2.4.12.tar.g
  • apr-1.5.1.tar.gz
  • apr-util.1.5.4.tar.gz
  • openssl-1.0.2a.tar.gz (yes it works with 1.0.2a!)
  • pcre-8.36.tar.gz

2.3.2 編譯安裝過程:

1、將所有軟件包解壓縮到首選源代碼樹中的單獨文件夾中 (e.g. C:\Development\Apache24\src)


2、在你的Apache路徑下爲 Apache, PCRE, APR and APR-Util 穿件文件夾 (e.g. C:\Development\Apache24\build)


3、文件夾結構如下:

C:\Development
   └ Apache24
      ├ src
      │   ├ apr-1.5.1
      │   ├ apr-util-1.5.4
      │   ├ httpd-2.4.12
      │   ├ openssl-1.0.2a
      │   └ pcre-8.36
      │
      └ build
         ├ apr
         ├ apr-util
         ├ httpd
         └ pcre

4、進行以下文件更改,以便構建ApacheMonitor (without the Manifest error)
C:\Development\Apache24\src\httpd-2.4.12\CMakeLists.txt
取消註釋該部分以構建ApacheMonitor實用程序 (lines 769-775)

# getting duplicate manifest error with ApacheMonitor
ADD_EXECUTABLE(ApacheMonitor support/win32/ApacheMonitor.c support/win32/ApacheMonitor.rc)
SET(install_targets ${install_targets} ApacheMonitor)
SET(install_bin_pdb ${install_bin_pdb} ${PROJECT_BINARY_DIR}/ApacheMonitor.pdb)
SET_TARGET_PROPERTIES(ApacheMonitor PROPERTIES WIN32_EXECUTABLE TRUE)
SET_TARGET_PROPERTIES(ApacheMonitor PROPERTIES COMPILE_FLAGS "-DAPP_FILE -DLONG_NAME=ApacheMonitor -DBIN_NAME=ApacheMonitor.exe / ${EXTRA_COMPILE_FLAGS}")
TARGET_LINK_LIBRARIES(ApacheMonitor ${EXTRA_LIBS} ${HTTPD_SYSTEM_LIBS} comctl32 wtsapi32)

C:\Development\Apache24\src\httpd-2.4.12\support\win32\ApacheMonitor.rc
註釋掉包含ApacheMonitor.manifest 的行(line 29)

//CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST  "ApacheMonitor.manifest"

5、從“開始”菜單中,啓動在Visual Studio 2013-> Visual Studio工具下找到的VS2013 x64本機工具命令提示符。或者從Windows命令提示符處運行以下命令:

call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64

6、導航到PCRE的構建子文件夾,運行CMAKE生成合適的Makefile,然後編譯並安裝

cd /D C:\Development\Apache24\build\pcre
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=C:\Apache24 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=ON -DPCRE_BUILD_TESTS=OFF -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_SUPPORT_PCREGREP_JIT=OFF -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON -DPCRE_NEWLINE=CRLF -DINSTALL_MSVC_PDB=OFF ..\..\src\pcre-8.36
nmake
nmake install

備註:在cmke裏的路徑是要修改一下的!
備註:這裏顯示的是4條指令,確認之後是會有內容出來的,等待它正確完成後才能進行下一條指令。


7、導航到OpenSSL的源子文件夾,配置構建環境以使用NASM進行編譯,然後進行編譯和安裝

cd /D C:\Development\Apache24\src\openssl-1.0.2a
perl Configure VC-WIN64A --prefix=C:\Apache24 --openssldir=C:\Apache24\conf enable-camellia no-idea no-mdc2 no-ssl2 no-ssl3 no-zlib
ms\do_win64a.bat
nmake /f ms\ntdll.mak
nmake /f ms\ntdll.mak install

備註:注意路徑修改。


8、導航到APR的構建子文件夾,運行CMAKE生成合適的Makefile,然後編譯並安裝

cd /D C:\Development\Apache24\build\apr
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=C:\Apache24 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DMIN_WINDOWS_VER=0x0600 -DAPR_HAVE_IPV6=ON -DAPR_INSTALL_PRIVATE_H=ON -DAPR_BUILD_TESTAPR=OFF -DINSTALL_PDB=OFF ..\..\src\apr-1.5.1
nmake
nmake install

9、導航到APR-Util的構建子文件夾,運行CMAKE生成合適的Makefile,然後編譯並安裝

cd /D C:\Development\Apache24\build\apr-util
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=C:\Apache24 -DOPENSSL_ROOT_DIR=C:\Apache24 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DAPU_HAVE_CRYPTO=ON -DAPR_BUILD_TESTAPR=OFF -DINSTALL_PDB=OFF ..\..\src\apr-util-1.5.4
nmake
nmake install

10、導航到Apache的build子文件夾,運行CMAKE生成合適的Makefile,然後編譯並安裝

cd /D C:\Development\Apache24\build\httpd
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=C:\Apache24 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_MODULES=i -DINSTALL_PDB=OFF ..\..\src\httpd-2.4.12
nmake
nmake install

11、最後,確認一切正常

cd /D C:\Apache24\bin
openssl version
httpd -V

I hope that others who have struggled find this useful. Please feel free to suggest any improvements to the process.
我希望其他苦苦掙扎的人覺得這很有用。請隨時提出對流程的任何改進建議。

2.4 配置已經編譯好的

參考鏈接:Apache服務器最新版下載、安裝及配置(windows版)

備註:最開始就應該使用這個方法,而不是自己進行編譯,,上面是主要的參考鏈接,基本上的流程都比較一致。


面針對其中遇到的一些問題進行說明:

備註:但凡是修改了文件,都要卸載進行重新安裝,用到的指令在Answer 6中。

Error 1:httpd.conf 80端口

(OS 10013)以一種訪問權限不允許的方式做了一個訪問套接字的嘗試。 : AH00072: make_sock: could not bind to address [::]:80
(OS 10013)以一種訪問權限不允許的方式做了一個訪問套接字的嘗試。  : AH00072: make_sock: could not bind to address 0.0.0.0:80
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs

原因:是因爲端口被佔用。
方案:需要修改 httpd.conf 文件中的 Listen 、ServerName 修改端口號,這裏把 80 設置爲 8080。修改爲目前沒有被佔用的端口號即可,根據自己的需要進行設置。

# 將原來的80改爲8080
Listen 8080					#line:67附近
ServerName localhost:8080	#line:232附近

Error 2:httpd-ssl.conf 443端口

(OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次。  : AH00072: make_sock: could not bind to address [::]:443
(OS 10048)通常每個套接字地址(協議/網絡地址/端口)只允許使用一次。  : AH00072: make_sock: could not bind to address 0.0.0.0:443
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs

原因:監聽端口被佔用。
方案:需要修改 Apache24\conf\extra 下的 httpd-ahssl.conf 、httpd-ssl.conf 在這裏把 443 修改爲 442 。

下面所有的443修改爲1444,或者445或者442等,只要是不被佔用就好

Listen 443 https #line18附近


#line:142-186,大概是這一段區間
<VirtualHost _default_:443>
  SSLEngine on
  ServerName localhost:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
  DocumentRoot "${SRVROOT}/htdocs"
# DocumentRoot access handled globally in httpd.conf
	CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
	<Directory "${SRVROOT}/htdocs">
		Options Indexes Includes FollowSymLinks
		AllowOverride AuthConfig Limit FileInfo
    Require all granted
	</Directory>
</virtualhost>

<VirtualHost *:443>
  SSLEngine on
  ServerName serverone.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
  DocumentRoot "${SRVROOT}/htdocs"
  CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  <Directory "${SRVROOT}/htdocs">
    Options Indexes Includes FollowSymLinks
    AllowOverride AuthConfig Limit FileInfo
    Require all granted
  </Directory>
</virtualhost>

<VirtualHost *:443>
  SSLEngine on
  ServerName servertwo.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
  DocumentRoot "${SRVROOT}/htdocs"
  CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
  <Directory "${SRVROOT}/htdocs">
    Options Indexes Includes FollowSymLinks
    AllowOverride AuthConfig Limit FileInfo
    Require all granted
  </Directory>
</virtualhost> 

備註:這裏有三個虛擬主機的設置,都是需要改變的!


Error 3:serverone.crt

SSLCertificateFile: file 'D:/0001/C_Downloads/Apache24/conf/ssl/serverone.crt' does not exist or is empty
# or
SSLCertificateFile: file 'D:/0001/C_Downloads/Apache24/conf/ssl/servertwo.crt' does not exist or is empty

原因:沒有對應的文件。
方案:手動添加該文件,可以複製已經存在.crt和.key文件,然後重命名爲上面代碼中三個虛擬主機要求的文件。
形如:

Apache24/conf/ssl:
    server.crt
    server.key

修改爲:

Apache24/conf/ssl:
	server.crt
    server.key
    serverone.crt
    serverone.key
    servertwo.crt
    servertwo.key

Question 4:Errors reported here must be corrected before the service can be started.

如果遇到如下文字:

Errors reported here must be corrected before the service can be started.

備註:這個並不是錯誤,是因爲apache的服務沒有打開,有兩個辦法:

  • 在任務管理器的服務中手動打開apache服務。
  • D:\Apache24\bin\ApacheMonitor.exe 運行之後,在這個GUI界面裏面打開。
    注意:運行之後不會直接打開界面,在右下角隱藏的圖標裏面雙擊的打開界面,開了之後一看便知。

Question 5:怎麼在瀏覽器中打開

怎麼在瀏覽器裏面打開?

如果沒有修改端口,默認80:

如果修改了端口,爲8080:

下面展示了幾種常見的輸入

apache中:
默認:https://localhost
修改:https://localhost:8080

wempapache:
http://127.0.0.1/

Answer 6:文中用到的一些指令

// 運行exe文件時:
D:\0001\C_Downloads\Apache24\bin\ApacheMonitor.exe
D:\0001\C_Downloads\Apache24\bin\httpd.exe
//安裝以及卸載
D:\0001\C_Downloads\Apache24\bin\httpd.exe -k install -n apache
D:\0001\C_Downloads\Apache24\bin\httpd.exe -k nuinstall -n apache
//輸出文件目錄:
tree //只顯示文件夾
tree/f //可以顯示文件
tree/f > info.txt //寫入到文件
dir //顯示詳細信息的

2.5 Apache & Vs 運行配置

主要是針對拍賣系統的實驗進行的一些配置,其他的配置都在上面的過程之中。

2.5.1 Apache 路徑

修改C:/auction/Apache/conf/httod.conf文件中的內容:

DocumentRoot "C:/auction/Apache/htdocs"	//302
<Directory "C:/auction/Apache/htdocs">	//327
UserDir "C:/auction/Apache/users/"		//361

備註:基本上這裏需要用到了路徑,都是需要修改的!

2.5.2 Vs 命令參數

項目->屬性:修改命令參數爲4000
在這裏插入圖片描述


對NO_PARENT參數進行初始化:

文件:Categories.h
static const int NO_PARENT=0;

3.運行過程

  1. 打開Apache文件夾中的Apache.exe文件
  2. 運行Visual Studio 2019中的工程
  3. 瀏覽器輸入:https://localhost

在這裏插入圖片描述

4.源代碼

鏈接:01-0005 實驗源碼 + Apache

備註:工程是可以直接運行的,我的Vs版本是2019,如果因爲版本不同而導致運行出了問題,可以新建工程自己進行導入。
另外,Apache是已經編譯好的,可以直接使用,不需要太多的配置!

5.相關鏈接

Apache-LICENSE-1.1
activestate
Index of /dist/httpd
nmake下一些錯誤的解決辦法
windows下nmake一些錯誤的解決辦法
【Windows 8.1, Intel-x64】編譯報錯:no rule for ssl\ at util\mk1mf.pl line 1048.
openSSL在Win7下的編譯與安裝
expat 2.0.1-7.2ubuntu1.4 source package in Ubuntu
離線安裝expat-2.0.1 ——安裝apr-util 遇到 expat.h: No such file or directory 的解決
Building UDUNITS2 with CMAKE: missing EXPAT_INCLUDE_DIR
在Windows上將EXPAT編譯爲靜態鏈接的.a
vs2015編譯apr-util
vs2015編譯expat
cmake在Windows上的使用
APR-util 1.6.1的更改
Visual Studio安裝多個工具鏈後CMake生成Nmake文件時報錯問題分析
build-all.bash - CMake fails when generating NMake files for protobuf
NMake configuration on Windows fails
將Visual Studio編譯器默認爲X64
如何查看程序佔用的端口
Apache服務器最新版下載、安裝及配置(windows版)
win10下安裝並測試apache服務器
如何解除80端口被佔用
apache 安裝遇到的問題
windows cmd 查看文件目錄樹
Windows通過cmd命令獲取文件列表 例子
SSLCertificateFile: file ‘/private/etc/apache2/server.crt’ does not exist or is empty
獲取tcp/udp端口對應的進程pid

吐槽幾句:這些問題不難,但是整理好好長時間,自覺這是一件沒有太大意義的事情,希望今後不會再出現類似的情況😡!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章