Linux(CentOS 7下httpd的安装)

时间:2024-04-29 21:54:36

Linux(CentOS 7下httpd的安装)

自己是个linux小白。最近几天在学linux,看到视频教程中安装源码包httpd所以自己想试一试,安装过程中有很多的错误,在网上找了很久也没找到,要么就是答非所问,安装了3个多小时才弄好,希望有像自己一样的小白能获得一点帮助。

步骤

下面的步骤是在安装过gcc的基础上。

1.源码包httpd下载

httpd下载链接

我是首先下载到了Window下。然后采用xShell将压缩包传到了linux虚拟机中。

点击选中的按钮会出现文件传输的页面。

Linux(CentOS 7下httpd的安装)

Linux(CentOS 7下httpd的安装)

双击即可上传。很方便。

注意:linux:一般源码包保存在 /usr/local/src/目录下

软件安装位置 /usr/local

看视频教程时,因为教程可能比较老,过程没有一点报错,结果自己安装时出现了错误。

软件配置与检查:./configure(这个步骤需要先进入解压好的httpd文件夹)

后面加上./configure --prefix=/usr/local/httpd指定安装的路径

结果报错如下:

configure: error: APR not found. Please read the documentation.

出现这种情况表示有依赖包还没装好。

需要安装:APR,APR-util


下载地址

http://apr.apache.org/download.cgi

Linux(CentOS 7下httpd的安装)

2.步骤同上:分别传输到linux的/usr/local/src/文件夹下,然后分别解压

tar -zxvf apr-1.7.0.tar

tar -zxvf apr-util-1.6.1.tar

3.将apr和apr-util复制到httpd-2.4.46/srclib目录下

cp -a -r apr-1.7.0/ ./httpd-2.4.416/srclib/apr

cp -a -r apr-util-1.6.1/ ./httpd-2.4.46/srclib/apr-util

4.再次进入解压好的httpd文件夹

执行命令

./configure --prefix=/usr/local/httpd/ --with-included-apr --with-included-apr --with-included-apr-util

此时又会出现新得错误

configure: error: pcre-config for libpcre not found. PCRE is required and available

说明缺少 pcre 包

下载链接

Linux(CentOS 7下httpd的安装)

这里需要注意以下:

pcre包 和pcre2包 不一样,我中午下载错了。然后虽然安装但是这个错误依然无法解决。

configure: error: pcre-config for libpcre not found. PCRE is required and available

所以一定注意要下载的是pcre包!!!!!!别下载错了!,不然会一直报那个错。

步骤同上 上传到linux

解压

进入解压好的pcre (这里可以按tab键 自动补全)

./configure --prefix=/usr/local/pcre --enable-utf8

可能会出现错误

configure: error: Invalid C++ compiler or C++ compiler flags

此时就需要安装gcc-c++

yum install -y gcc-c++

下载之后在进行

make && make install

5.再一次进入解压好的httpd-2.4.46/的目录

./configure --prefix=/usr/local/httpd/ --with-included-apr --with-included-apr --with-included-apr-util --with-pcre=/usr/local/pcre

make && make install

又出现错误:apahce./gen_test_char > test_char.h /bin/sh: ./gen_test_char: 没有那个文件或目录(省略10000字)好几个错误

yum -y install expat-devel(查了很久。。。。。太坑了,在这个过程还删除了apr,apr-util,pcre,httpd重新开始装了两次,最后才成功。。。。)

6..再再一次进入解压好的httpd-2.4.46/的目录

./configure --prefix=/usr/local/httpd/ --with-included-apr --with-included-apr --with-included-apr-util --with-pcre=/usr/local/pcre

make && make install

完美撒花.......

7.启动httpd的服务

启动命令(需要使用绝对路径):

/usr/local/httpd/bin/apachectl start

此时报错:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

说明端口被占用

vi /usr/local/httpd/conf/httpd.conf

修改配置文件 ,将ServerName后面的端口改成8080

因为内容较多,所以需要再文件中进行查找。

命令模式下输入: /ServerName

按回车 :

1.按n可以查看下一个出现要查询的字符的地方

2.找到之后 按i可以插入删掉80改为8080

3.修改之后按Esc推出插入模式,按:wq保存退出

此时重新启动httpd服务:

/usr/local/httpd/bin/apachectl start

就可以看到httpd(pid号)already running。。。

8.此时就可以再自己的电脑浏览浏览器输入虚拟机的ip地址就可以看到

Linux(CentOS 7下httpd的安装)

如果还不能访问,

再linux输入 systemctl stop firewalld 关闭防火墙。

完美撒花!!!

第一次发文章,而且是个对linux没有经验的小白,如果有错误欢迎指出。大家一块交流学习。!