Linux安装apache

  这里就不讲解apache是什么,有什么作用,直接上安装教程。这里是我自己本人在Linux机上安装apache的两种方式,发表出来给大家当作参考。

1.使用yum安装(推荐):

  1. 安装之前先确认机子是否曾经安装过apache,

    # rpm -qa |grep httpd

    # yum list installed |grep httpd

    # find / -name “*apachectl*”

    如果以上三条指令都没有内容,则说明此时机子上的apache已经卸载干净

     

  2.安装

    # yum -y install httpd

     

  3.启动

    # service httpd start

    如图,则启动成功

     

    在通过service httpd restart的时候,服服务器提示:

    Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down

是说80端口已经在使用了。

    解决:

      $ sudo fuser -k -n tcp 80 
      $ sudo /etc/init.d/httpd -k start

      把运行80端口的进程kill掉

  4.测试

    安装成功后,需要先找出apache的httpd.conf文件

    # find / -name “httpd.conf”

     

    # vi /etc/http/conf/httpd.conf

    添加一行ServerName localhost:80,然后在外部用浏览器测试,

     

    如图,则安装成功

 

2.官网下载tar包用make编译安装(不推荐):

  1. 先下载apache所需要的文件,这里以安装apache-2.4为例

   

    需要下载以上4个文件,版本要对应!

  2.安装时需要按照顺序安装,即如下顺序:

    apr-1.5.1.tar.gz

    apr-util-1.5.4.tar.gz

    pcre-8.35.tar.gz

    httpd-2.4.12.tar.gz

  3.解压

    # tar -zxcf apr-1.5.1.tar.gz

    # tar -zxcf apr-util-1.5.4.tar.gz

    # tar -zxcf pcre-8.35.tar.gz

    # tar -zxcf httpd-2.4.12.tar.gz

  如图:

   

  4.安装apr-1.5.1,

    # cd apr-1.5.1

    # ./configure --prefix=/var/opt/httpd/apr-1.5.1

   

出现如下错误:

   

    则需要先安装gcc与gcc-c++,即

    # yum -y install gcc

    # yum -y install gcc-c++

   

   

    此时安装完gcc与gcc-c++之后,则继续安装apr-1.5.1,

    # ./configure --prefix=/var/opt/httpd/apr-1.5.1 //此步骤为编译,如编译通过则执行安装

    # make

    # make install

  5.apr安装好了之后则依次安装apr-util、pcre、httpd

    命令与安装apr差别不大,如下

    编译安装apr-util-1.5.4:

    # cd apr-util-1.5.4

    # ./configure --prefix=/var/opt/httpd/apr-util-1.5.4 --with-apr=/var/opt/httpd/apr-1.5.1/bin/apr-1-config

    # make

    # make install

---------------------------------------------------------------------------------------------------------------------------

    编译安装pcre-8.35/:

    # cd pcre-8.35/

    # ./configure --prefix=/var/opt/httpd/pcre-8.35

    # make

    # make install

---------------------------------------------------------------------------------------------------------------------------

    编译安装apache-2.4.12

    # cd httpd-2.4.12/

    # ./configure --prefix=/var/opt/httpd/apache-2.4.12 --with-apr=/var/opt/httpd/apr-1.5.1/bin/apr-1-config --with-apr-util=/var/opt/httpd/apr-util-1.5.4/bin/apu-1-config --with-pcre=/var/opt/httpd/pcre-8.35/bin/pcre-config

    # make

    # make install

    注意:如果在编译过程中因为操作不当导致安装报错,如编译一半又中断,再编译这种情况,建议可以用make clean清除先前产生的执行文件及配置文件

  6.安装完成之后,测试

    # cd /var/opt/httpd/apache-2.4.12/conf/

    # vi httpd.conf

    添加一行ServerName localhost:80,然后在外部用浏览器测试,

   

  如图,则安装成功

 

原文地址:https://www.cnblogs.com/wicfhwffg/p/5410307.html