CentOS7 搭建Apache服务器,centos7搭建apache


CentOS7 搭建Apache服务器


更新:


直接使用yum安装,下面使用源码安装的方式过于复杂,yum安装简单且不容易出错:

注:yum install httpd如果执行较慢,请替换源:替换方法替换源

yum install httpd //安装Apache(http://blog.csdn.net/u011402032/article/details/53910275)
/sbin/chkconfig httpd on //设置Apache服务开机自启动(可选,不过设置自启动方便)
/sbin/service httpd start //启动Apache服务
/sbin/service httpd restart  //重启
/sbin/service httpd stop  //停止

主配置文件位置:/etc/httpd/conf/httpd.conf

测试:
打开浏览器输入:localhost:80得到下面页面则成功:


下面是使用源码的方式安装,较为复杂,推荐使用上面的方式安装

一.准备:

  • 装有centos7系统的pc或者虚拟机
  • 需下载的包:
    - httpd-2.4.25.tar.gz(Apache安装包,下载地址:http://httpd.apache.org/)
    - apr-1.5.2.tar.gz(下载地址:http://apr.apache.org/download.cgi)
    - apr-util-1.5.4.tar.gz(下载地址:http://apr.apache.org/download.cgi)
    - pcre-8.38.tar.gz(注:不要下载pcre2-开头的包,在后面make时会报错。下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/)

二.搭建过程:
1.为了方便管理这里首先新建一个目录,用来装Apache所需要用到的上面四个安装包:

cd /usr
mkdir forApache

将准备阶段下载好的四个包放在forApache目录下。

2.先装apr-1.5.2.tar.gz:

cd /usr/forApache
tar -zxf apr-1.5.2.tar.gz //也可以在图形界面右键解压,就跟我们熟悉的Windows一样
cd apr-1.5.2
./configure --prefix=/usr/local/apr-1.5.2   //装在/usr/local/apr-1.5.2目录下
make
make install

3.再装apr-util-1.5.4.tar.gz

cd /usr/forApache
tar -zxf apr-util-1.5.4.tar.gz//也可以在图形界面右键解压,就跟我们熟悉的Windows一样
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2
make
make install

4.再装pcre-8.38.tar.gz
这里要注意下载的时候不要下载pcre2开头的包,否在在下部安装httpd-2.4.25时会报错error: Did not find pcre-config script at /usr/local/pcre

cd /usr/forApache
tar -zxf pcre-8.38.tar.gz //也可以在图形界面右键解压,就跟我们熟悉的Windows一样
cd pcre-8.38
./configure --prefix=/usr/local/pcre
make 
make install

5.最后再装httpd-2.4.25

cd /usr/forApache
tar -zxf httpd-2.4.25.tar.gz //也可以在图形界面右键解压,就跟我们熟悉的Windows一样
cd httpd-2.4.25 
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make
make install

6.修改配置文件,查看是否配置成功。(此步为了简便,直接在图形化界面操作):

建议修改我们刚才安装的Apache服务器的监听端口,因为centos7 自带了有Apache,默认的就是80端口。这样两个Apache运行的话会造成冲突,解决这种冲突有3种方法:

这里采用的是第3种办法,Apache的配置文件位置:/usr/local/apache/conf,打开该目录下的httpd.conf ,修改以下两处:

Listen 8080  //Apache服务器的监听端口,默认80
ServerName loaclhost:8080  //你的服务器地址

启动Apache服务:

cd /usr/local/apache
bin/apachectl start//启动Apache
bin/apachectl stop//停止Apache
bin/apachectl restart//重启Apache

三.测试:
打开浏览器,在地址栏输入localhost:8080 ,显示It works! 表明搭建成功。

相关内容

    暂无相关文章