Linux CentOS Apache

系统版本:CentOS6.8

查看是否自带安装了Apache

[root@node ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-53.el6.centos.x86_64
httpd-2.2.15-53.el6.centos.x86_64

卸载已安装版本:

[root@node ~]# rpm -e --nodeps httpd-tools
[root@node ~]# rpm -e --nodeps httpd
[root@node ~]# rpm -qa | grep httpd
[root@node ~]#


源码安装 httpd-2.4.43.tar.gz

下载地址:http://httpd.apache.org/download.cgi

官方安装教程:http://httpd.apache.org/docs/2.4/install.html

[root@node ~]# ll http*
-rw-r--r--. 1 root root 9348230 May 17 12:26 httpd-2.4.43.tar.gz

解压:

[root@node ~]# tar -zxf httpd-2.4.43.tar.gz

配置:

http://httpd.apache.org/docs/2.4/programs/configure.html#page-header

[root@node httpd-2.4.43]# pwd
/root/httpd-2.4.43
[root@node httpd-2.4.43]# ./configure --prefix=/usr/local/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... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.

设置安装目录 /usr/local/apache,默认安装位置 /usr/local/apache2。

但是提示发现错误,没有APR依赖。安装:

http://apr.apache.org/download.cgi

apr-1.7.0.tar.gz
apr-util-1.6.1.tar.gz

查看并卸载旧版本:

[root@node ~]# rpm -qa | grep apr
apr-util-ldap-1.3.9-3.el6_0.1.x86_64
apr-util-1.3.9-3.el6_0.1.x86_64
apr-1.3.9-5.el6_2.x86_64
[root@node ~]# rpm -e --nodeps apr-util-ldap
[root@node ~]# rpm -e --nodeps apr-util
[root@node ~]# rpm -e --nodeps apr
[root@node ~]# rpm -qa | grep apr
[root@node ~]#

安装 apr:

[root@node ~]# tar -zxf apr-1.7.0.tar.gz 
[root@node apr-1.7.0]# pwd
/root/apr-1.7.0
[root@node apr-1.7.0]# ./configure -prefix=/usr/local/apr
[root@node apr-1.7.0]# make
[root@node apr-1.7.0]# make install

安装apr-util:

[root@node ~]# tar -zxf apr-util-1.6.1.tar.gz 
[root@node apr-util-1.6.1]# pwd
/root/apr-util-1.6.1
[root@node apr-util-1.6.1]# ./configure -prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

此时出现错误:xml/apr_xml.c:35:19: error: expat.h: No such file or directory

是因为:https://blog.csdn.net/hanzheng260561728/article/details/79655043
解决:

[root@node apr-util-1.6.1]# yum install expat-devel

继续安装 apr-util:

[root@node apr-util-1.6.1]# make
[root@node apr-util-1.6.1]# make install

再次进入Apache源码目录,重新配置、编译、安装httpd:

[root@node httpd-2.4.43]# ./configure -prefix=/usr/local/apache --with-apr-util=/usr/local/apr-util/
[root@node httpd-2.4.43]# make
[root@node httpd-2.4.43]# make install

安装成功后,编辑配置文件 http.conf

[root@node conf]# pwd
/usr/local/apache/conf
[root@node conf]# vim httpd.conf

设置端口为 9090

启动apache:(start | stop | restart)

[root@node bin]# ./apachectl -k start


另:修改防火墙设置,增加9090访问端口

[root@node bin]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT
[root@node bin]# service iptables restart


起初作者将apache安装在某用户主目录/home/xxx下,访问出现错误"You don't have permission to access this resource"。

查看日志发现是用户主目录权限问题,需要给其他用户增加可执行权限才可正常访问(chmon o+x /home/xxx),所以更改了安装目录。



转载请指明出处!http://www.miselehe.com/article/view/69