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"
- 修改项目目录具体参数
<Directory "/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
通过浏览器检测是否安装成功
相关推荐
liuhangtiant 2020-10-20
duckes 2020-05-17
byourb 2020-01-11
咻咻ing 2020-01-08
咻咻ing 2019-12-17
亦碎流年 2019-12-05
fengtaijun 2013-08-08
zhoujk00 2014-03-12
单调的低调 2015-01-16
Neptune 2019-11-11
泥淖 2019-11-09
hairetz 2015-09-07
RuoShangM 2019-10-23
xiaohanshasha 2011-06-01
eroshn 2019-10-27
artwebs 2011-02-17
TLROJE 2010-08-26