linux源码安装apache2,CentOS7编译安装Apache2

在LAMP环境下对于服务的安装是必不可少的,在linux环境下安装软件也有两种不同的方式,一种是yum安装当然了不同的linux发行版本使用略有不同,另一种是通过编译安装,编译安装要比yum安装要可控此,但是要比yum安装略微麻烦些我们下面这种方式就是通过编译安装的方式安装Apache2服务器软件,如果你觉得麻烦可以使用类似的yum方式哦!

安装软件运行基础

apr

下载地址

[root@localhost soft]# wget -i http://www-eu.apache.org/dist//apr/apr-1.6.3.tar.gz

解压编译安装

解压

[root@localhost soft]# tar -zxf apr-1.6.3.tar.gz && apr-1.6.3

编译

[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr

安装

[root@localhost apr-1.6.3]# make && make install

apr-util

下载地址

[root@localhost soft]# wget -i http://www-eu.apache.org/dist//apr/apr-util-1.6.1.tar.gz

解压编译安装

解压

[root@localhost soft]# tar -zxf apr-util-1.6.1.tar.gz && cd apr-util-1.6.1

编译

[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

安装

[root@localhost apr-util-1.6.1]# make && make install

pcre

下载地址

[root@localhost soft]# wget -i https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz

解压编译安装

解压

[root@localhost soft]# tar -zxf pcre-8.41.tar.gz && cd pcre-8.41

编译

[root@localhost pcre-8.41]# ./configure --prefix=/usr/local/pcre

安装

[root@localhost pcre-8.41]# make && make install

安装Apache2

下载地址

[root@localhost soft]# wget -i http://www-us.apache.org/dist//httpd/httpd-2.4.29.tar.bz2

解压编译安装

解压

[root@localhost soft]# tar -jxf httpd-2.4.29.tar.bz2 && cd httpd-2.4.29

编译

[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre

安装

[root@localhost httpd-2.4.29]# make && make install

配置Apache2

修改配置文件

[root@localhost soft]# vim /usr/local/apache2/conf/httpd.conf

修改监听端口号

Listen 8088

修改 ServerName

ServerName www.apache-host.dev:8088

修改项目目录

DocumentRoot "/www/apache-host"

修改项目目录具体参数

设置Apache2为Linux服务并实现开机自启动

添加Apache2配置文件 apachectl 到linux服务

拷贝文件并重命名

[root@localhost soft]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

将系统配置目录下的 httpd 添加到 系统服务

[root@localhost soft]# chkconfig --add httpd

设置系统服务 httpd 为开机启动

[root@localhost soft]# chkconfig httpd on

检测系统服务 httpd 是否启动成功

查看系统服务状态

[root@localhost soft]# chkconfig --list | grep httpd

系统服务状态详情

Note: This output shows SysV services only and does not include native

systemd services. SysV configuration data might be overridden by native

systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.

To see services enabled on particular target use

'systemctl list-dependencies [target]'.

httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

可见服务已经在 第2 到 第5 运行等级打开, 说明系统服务 httpd 已正常开启开机启动

禁用系统服务 httpd

禁用系统服务

[root@localhost soft]# chkconfig httpd off

禁用系统服务状态

Note: This output shows SysV services only and does not include native

systemd services. SysV configuration data might be overridden by native

systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.

To see services enabled on particular target use

'systemctl list-dependencies [target]'.

httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

可见服务已经在 第1 到 第6 运行等级关闭, 说明系统服务 httpd 已正常关闭开机启动功能

开启系统服务Apache2

[root@localhost soft]# systemctl start httpd.service

查看系统服务运行状态

[root@localhost soft]# systemctl status httpd.service

验证是否成功安装Apache2

通过curl命令行检测是否安装成功

检测

[root@localhost soft]# curl -I "http://127.0.0.1:8088"

结果

HTTP/1.1 200 OK

Date: Sun, 31 Dec 2017 18:23:24 GMT

Server: Apache/2.4.29 (Unix)

Content-Type: text/html;charset=ISO-8859-1

1460000012657097?w=1425&h=553

通过浏览器检测是否安装成功

1460000012657098?w=1439&h=752

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值