linux 安装Apache

时间:2019-03-21
本文章向大家介绍linux 安装Apache,主要包括linux 安装Apache使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

安装Apache参考网址
https://www.cnblogs.com/xdouby/p/6406873.html
第一步下载
网址
例如:
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.37.tar.bz2
错误提示
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
yum -y install expat-devel
版本不兼容
https://blog.csdn.net/gouhexiong1989/article/details/78694037?tdsourcetag=s_pctim_aiomsg
见以网址错误提示
结论删除1.6版本的apr 和apr-util,重新下载1.5版本重新编译和安装。
重新下载
http://archive.apache.org/dist/apr/
http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz

删除旧版本的apr和apr-util
rm –rf /usr/local/apr
rm –rf /usr/local/apr-util

开始安装
首先安装编译环境
yum install -y gcc gcc-c++
把压缩包放到root下
第一步:安装apr
tar –xvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
会出现错误要下载gcc
yum -y install gcc(Ubuntu是apt-get,-y是一直yes不用自己选)
make –j
make install
第二步:安装apr-util
tar –xvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
make –j
make install

第三步:安装pcre
tar –xvf pcre-8.42.tar.gz
./configure --prefix=/usr/local/pcre
在之前会报错,没有c++,则需要装apt-get(centos用yum) install gcc-c++
make –j
make install

第四步:安装openssl
tar –xvf openssl-1.0.2q.tar.gz
cd openssl-1.0.2q
./config --prefix=/usr/local/openssl
make –j
make install
cd /usr/local
ln -s openssl ssl
在/etc/ld.so.conf文件的最后面,添加如下内容:
/usr/local/openssl/lib
执行 ldconfig
添加OPESSL的环境变量,在/etc/profile的最后一行,添加:
export OPENSSL=/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
执行source /etc/profile

第五步:安装httpd
tar –xvf httpd-2.4.37.tar.gz
cd httpd-2.4.37
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr- 
util=/usr/local/apr-util --with-pcre=/usr/local/pcre
如果上述错误,则执行第四步,否则不必要
make –j
make install
第六步(不必要):启动服务
添加防火墙配置
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
firewall-cmd –reload
netstat –apnt|grep 80
注:ubuntu:ufw disable

管理apache服务
apache默认占用80端口,所以如果有应用占用80这个端口,就要注意会存在端口冲突问题。
•启动Apache:/usr/local/apache2/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

解决网址https://blog.csdn.net/zhaomininternational/article/details/42293511

即执行vim /usr/local/apache2/conf/httpd.conf 
搜索/ServerName
#ServerName www.example.com:80 更改为ServerName localhost:80
ps -aux |grep 进程号
netstat -anpt |grep 80查看端口
wget是Linux上网的命令,直接输入wget查看是否可用,不可用则用yum install wget安装
然后输入wget localhost在本地下载一个文件为index.txt

防火墙配置网址
https://www.cnblogs.com/moxiaoan/p/5683743.html

1、firewalld的基本使用
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld 
开机禁用  : systemctl disable firewalld
开机启用  : systemctl enable firewalld

•停止Apache:/usr/local/apache2/bin/apachectl stop
•重启Apache:/usr/local/apache2/bin/apachectl restart

在浏览器中通过http://192.168.0.208:80,如果看到页面中显示“It works!”字样,则代表Apache验证 
通过。