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

吐槽几句:这些问题不难,但是整理好好长时间,自觉这是一件没有太大意义的事情,希望今后不会再出现类似的情况😡!

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