美文网首页我爱编程
Linux下apache的安装

Linux下apache的安装

作者: 轴儿 | 来源:发表于2018-03-17 11:11 被阅读0次

1.获取软件:

http://httpd.apache.org/   httpd-2.4.25.tar.gz

并上传至服务器。

运行以上命令时,可能会出现“APR not found.”的错误。此时需要下载依赖包。

2.下载安装依赖包:

创建文件夹:

mkdir /usr/httpd-refer

cd /usr/httpd-refer/

下载依赖包:

wget http://p5osdejt4.bkt.clouddn.com/apr-1.5.2.tar.gz

wget http://p5osdejt4.bkt.clouddn.com/apr-util-1.5.4.tar.gz

wget http://p5osdejt4.bkt.clouddn.com/pcre-8.40.tar.gz

解压依赖包:

tar -xzvf apr-1.5.2.tar.gz

tar -xzvf apr-util-1.5.4.tar.gz

tar -xzvf pcre-8.40.tar.gz

安装依赖包:

cd apr-1.5.2

./configure --prefix=/usr/httpd-refer/apr

make && make install

cd apr-util-1.5.4

./configure --prefix=/usr/httpd-refer/apr-util --with-apr=/usr/httpd-refer/apr/bin/apr-1-config

make && make install

cd pcre-8.40

./configure --prefix=/usr/httpd-refer/pcre

make && make install

3.解压apache源文件:

tar zvxf httpd-2.4.25.tar.gz

cd httpd-2.4.25

./configure --prefix=/usr/local/apache --with-apr=/usr/httpd-refer/apr --with-apr-util=/usr/httpd-refer/apr-util/ --with-pcre=/usr/httpd-refer/pcre  --enable-s --enable-rewrite

make && make install

运行./configure 命令进行编译源代码,

--prefix=/usr/local/apach 是设置编译安装到的系统目录,

--enable-s  参数是使httpd服务能够动态加载模块功能,

--enable-rewrite  是使httpd服务具有网页地址重写功能。

4.启动apache:

/usr/local/apache/bin/apachectl start

将apache加入到系统服务,用service命令来控制apache的启动和停止

首先以apachectl脚本为模板生成Apache服务控制脚本:

grep -v "#" /usr/local/apache/bin/apachectl  > /etc/init.d/apache

用vi编辑Apache服务控制脚本/etc/init.d/apache:

vim /etc/init.d/apache

在文件最前面插入下面的行,使其支持chkconfig命令:

#!/bin/sh              

# chkconfig: 2345 85 15              

# description: Apache is a World Wide Web server.

保存后退出vi编辑器,执行下面的命令增加Apache服务控制脚本执行权限:

chmod +x /etc/init.d/apache

执行下面的命令将Apache服务加入到系统服务:    

chkconfig --add apache

执行下面的命令检查Apache服务是否已经生效:

chkconfig --list

命令输出类似下面的结果:  

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

表明apache服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制Apache的启动和停止。

启动Apache服务:service apache start

停止Apache服务:service apache stop

执行下面的命令开启开机自启动:chkconfig apache on

5.apache配置文件

开启虚拟服务器,使得不同域名访问不同目录及配置虚拟端口。

vim /usr/local/apache/conf/httpd.conf

编辑配置文件,去掉proxy的注释:

#LoadModule proxy_module modules/mod_proxy.so

#LoadModule proxy_connect_module modules/mod_proxy_connect.so

#LoadModule proxy_http_module modules/mod_proxy_http.so

去掉"Include conf/extra/httpd-vhosts.conf"的注释:

#Include conf/extra/httpd-vhosts.conf

编辑httpd-vhosts.conf文件:

多个域名访问不同的文件:

<VirtualHost *:80>

    DocumentRoot "/usr/local/apache/htdocs/test"

    ServerName www.test.com

< /VirtualHost  >

以上含义就是代表www.test.com这个域名访问的是/usr/local/apache/htdocs/test下的文件。

配置虚拟主机,按域名解析到不同端口:

<VirtualHost *:80>

    ServerName www.test.com

    ServerAlias www.test.com

    ProxyPreserveHost On

    ProxyRequests Off

    ProxyPass / http://192.21.00.00:8080/

    ProxyPassReverse / http://192.21.00.00:8080/

    ErrorLog "logs/test.com-error_log"

    CustomLog "logs/test.com-access_log" common

</VirtualHost >

以上含义就是www.test.com访问的是192.21.00.00这台主机下的8080端口。

相关文章

  • linux下安装Apache

    linux下安装Apache 1 - 下载Apache 2 - 安装Apache 执行./configure的时候...

  • Linux下安装Apache

    Linux下安装Apache# 20150418 目录## ......什么是httpd ......安装步骤 ....

  • linux下安装apache

    图片服务器上安装一个http服务 软件准备: apr-1.5.2.tar.gz httpd-2.4....

  • Linux系统下安装Apache服务器

    Linux系统下安装Apache服务器 1.第一步命令安装apache: yum install httpd ht...

  • Linux下apache的安装

    1.获取软件: http://httpd.apache.org/ httpd-2.4.25.tar.gz 并上传至...

  • Linux环境下 ab压力测试

    Linux下搭建ab环境 1.安装Apache 2.如果不想安装apache但是又想使用ab命令的话,我们可以直接...

  • LAMP安装教程

    Linux配置 安装wget 更新linux库 安装vim 安装zip和unzip 配置显示 安装Apache 安...

  • LAMP安装(1)

    LAMP,就是在linux环境下安装apache(httpd),mysql(mariadb),与php wget ...

  • Linux下安装Apache,PHP

    下载Apache和PHP的源码不用说。 Apache安装: 进入tar.gz解压出来的文件夹,如果直接./conf...

  • linux下安装apache环境

    具体安装步骤: 1 下载想要安装的版本源码包并且配置安装apache的基础环境2 解压,预编译,编译,安装3 启动...

网友评论

    本文标题:Linux下apache的安装

    本文链接:https://www.haomeiwen.com/subject/odqdqftx.html