搭建LAMP架构— 1、手工编译安装Apache

LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。

本次,让我们先来完成Apache网站服务器的搭建,作为LAMP架构的前端,Apache是一款功能强大、稳定性好的Web服务器程序,该服务器直接面向用户提供网络访问,发送网页,图片等文件内容。

本次安装需要用到的编译安装包:百度网盘密码:2r7m

  • 首先,我们可以把安装包挂载到opt目录下新建的lamp目录中并把http、apr(支持Apache上层应用跨平台,提供底层接口库)、apr-util三个压缩包解压到opt目录中:
  • mount.cifs //192.168.x.x/LAMP /opt/lamp
    tar xzvf http-2.4.2.tar.gz -C /opt
    tar xzvf apr-1.4.6.tar.gz -C /opt
    tar xzvf apr-util-1.4.1.tar.gz -C /opt
  • 移动到opt目录中,并把apr、apr-util递归复制httpd中srclib目录中,并分别为他们新建目录方便识别:
  • cp -R apr-1.4.6/ /opt/httpd-2.4.2/srclib/apr
    cp -R apr-util-1.4.1/ /opt/httpd-2.4.2/srclib/apr-util
  • 使用yum仓库安装 gcc 、 gcc-c++ 、 make 、 pcre、pcre-devel 四个软件包
    (pcre : 一个Perl库,支持正则表达式):
  • yum install gcc gcc-c++ make pcre pcre-devel -y
  • 移动到httpd主目录,并用configure进行配置:
cd /opt/httpd-2.4.2

./configure \
--prefix=/usr/local/apache \
--enable-so \
--enable-rewrite \
--enable-mods-shared=most \
--with-mpm=worker \
--disable-cgid \
--disable-cgi
  • 目录不变,执行命令make make install编译安装:
  • make && make install
  • 过滤掉脚本文件中的注释行(#)并重定向到etc目录中,编辑文件,并在文件最前面插入下面的行用以执行:
  • grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd

vim /etc/init.d/httpd

#在文件开头插入下面的行
#!/bin/sh

chkconfig:2345 85 15

# description:Apache is a World Wide Web server.
  • 此时,我们可以设置httpd服务在init3、init5中开机启动,并建立软连接便于管理:
chkconfig --level 35 httpd on

ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
  • 编辑httpd.conf文件,并修改配置:
vim /etc/httpd.conf

Listen:IPV4    #这里我们可以监听本机地址
ServerName:    #分别为主机名.域名

现在我们就可以开启服务了!

-

Redhat6.5中服务开启关闭命令
service httpd start
service httpd stop

如在Redhat7.0以上版本,即为以下命令
systemctl start httpd.service
systemctl stop httpd.service

netstat -tnl   //查看监听端口

主页存放路径为  /usr/local/apache/htdocs/index.html

我们可以在局域网中用同一网段的另一台机器去访问主页,但要注意先关闭服务器的防火墙。

service iptables stop
setenforce 0

使用另一台主机访问主页:

搭建LAMP架构—  1、手工编译安装Apache

猜你喜欢

转载自blog.51cto.com/13625676/2117427