发布于 2016-01-04 03:23:57 | 508 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的精品教程,程序狗速度看过来!

Apache Web服务器

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件。


这是我首次尝试的经验,走了很多坑,借此记录一下,希望朋友们少走一些弯路;
我是通过下载源码安装的,所有的下载文件为*.tar.bz2压缩包(不同压缩方式,解压方式不同,我就下载同一种了);

一. 下载安装包

一次性把文件(包括关联文件——请原谅我不放链接,下次安装的时候补上)下载好,其中包括:

apr-1.5.2
apr-util-1.5.4
pcre-8.37(如果没记错的话,这个不要下载最新版;记错的话,以上三个有一个不要下载最新版——我好不负责)
httpd-2.4.18

二. 查看是否有编译器

如果没有的话,安装文件时会报错,可以根据提示安装相应文件;
我是通过yum install安装的gcc 、c++

[root@root]# yum install gcc -y
[root@root]# yum install gcc-c++ -y

三. 解压源码包

把第一步下载好的源码包解压:

tar -jxvf DirName.tar.bz2

当然,如果你没有解压工具,请通过:

yum search bzip2查找安装解压工具;

四. 安装关联文件

如果直接安装Apache的话(我就不直接安装),它有可能会报错(我都是一定会报错):

checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found.  Please read the documentation.
这时候第一步下载的文件就用的上了;
安装顺序apr -> apr-util ,当然pcre可以乱入(顺序不重要);
安装过程,配置 -> 编译 -> 安装 三部曲;

主要说配置:
进入解压后的apr文件包:
    [root@root]# ./configure --prefix=/usr/local/apr/(这里配置的是安装路径)
    # make
    # make intall
进入解压后的apr-util文件包:
     [root@root]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config(配置apr-util安装路径,并关联apr文件——确保路径正确)
    # make
    # make intall
进入解压后的pcre文件包:
    [root@root]# ./configure --prefix=/usr/local/pcre(配置安装路径)
    # make
    # make intall  

五. 配置、编译、安装

关联文件安装结束后就是主菜了:

进入解压后的httpd文件包:
[root@root]# ./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/(确保路径正确)
# make
# make intall  

六. 启动

进入Apache的目录/usr/local/apache/conf/

修改httpd.conf配置文件(Apache2.4与2.2配置不同)
Require all denied(禁止外部访问)
Require all granted(允许外部访问)

进入Apache的安装目录/usr/local/apache/(如果你没自定义的话):

./apachectl start  #启动服务
./apachectl stop   #关闭服务
./apachectl restart  #重启服务

我用的Centos7不会提醒服务已启动,所以,我一般一个命令运行两次,第二次它会报告服务已启动/已关闭;

七. 调试

启动就ok了?我曾经是这样认为的——可是,坑还在继续……

外网/局域网访问不了:

排查1:
    服务器/虚拟机自身网络是否正常,可以通过ping http://www.baidu.com度娘地址试试;
排查2:
    服务是否启动,占用80端口的是否为http服务:
    netstat -ntpl  #查看端口监听(我的是,所以,我就没有了关闭其它进程的经验)
    如果你不一定非要80端口的话,可以修改/usr/local/apache/conf/httpd.conf监听端口;
排查3:
    You don't have permission to access / on this server
    没有权限,解决方案:
    chmod o+x /usr/
    chmod o+x /usr/local/
    chmod o+x /usr/local/apache/
    chmod o+x /usr/local/apache/htdocs(每一级目录都要执行)
    
    以上问题可以通过curl http://127.0.0.1在服务器/虚拟机上检验本地是否可以访问;
排查4:
    防火墙设置——Centos7默认使用firewalld代替iptables(网上多数是iptables的设置解决方案)    
    systemctl start firewalld  #启动
    systemctl state firewalld  #查看状态
    systemctl disable firewalld  #停止
    systemctl stop firewalld  #禁用(我是直接禁用了,可以尝试改一下80端口权限)
    查看所有打开的端口:
    # firewall-cmd --zone=dmz --list-ports(firewall-cmd是一个合成词)
    加入一个端口到区域:
    # firewall-cmd --zone=dmz --add-port=8080/tcp
    永久生效再加上 --permanent 然后reload防火墙
    # firewall-cmd --complete-reload
    

由于我进行了很多步操作来解决外部访问的问题,所以,最终仅仅通过以上调试方法能否得到外部访问的结果,不敢保证;

如不行:
检查一下selinux设置(其它问题只能自行百度了)……

    
    


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务