Linux(centos6+)安装Apache2.4详细教程

本教程基于centos6.5 环境

版本:Apache2.43 +apr-1.6.3 + apr-util-1.6.1

一,所有资源官网

1 Apache下载  httpd.apache.org/download.cg…

2 apr和apr-util下载 apr.apache.org/

3 正则工具 pcre: http://www.pcre.org/

二,安装

2.1 装库

# yum install -y gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel

2.1安装apache依赖

2.1.1 APR

# wget apache.osuosl.org//apr/apr-1.…

# tar zxf apr-1.6.3.tar.gz# cd apr-1.6.3# ./configure --prefix=/usr/local/apr-1.6.3# make && make install

2.1.2 apr-util

# wget apache.osuosl.org//apr/apr-ut…

# tar zxf apr-util-1.6.1.tar.gz

# cd apr-util-1.6.1

# ./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.3 (!!版本号要对应啊啊!) # make && make install

2.1.3 pcre

# wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz

# tar zxf pcre-8.42.tar.gz

# cd pcre-8.42.tar.gz

# ./configure

# make && make install

2.2开装apache

#cd /usr/local/src

#wget mirrors.sonic.net/apache//htt…

# tar zxf httpd-2.4.33.tar.gz

# cd httpd-2.4.33

# mkdir -p /usr/local/apache2.433

#./configure --prefix=/usr/local/apache2.433 --with-apr=/usr/local/apr-1.6.3 --with-apr-util=/usr/local/apr-util-1.6.1 --with-ssl --enable-ssl --enable-module=so --enable-rewrite --enable-cgid --enable-cg

#make && make install

# cp /usr/local/apache2.433/conf/httpd.conf /usr/local/apache2.433/conf/httpd.conf.default(这句意思是把配置文件备份一下,留作日后抢救,可以不用)

2.3 配置Apache

2.3.1配置ServerName

# vi /usr/local/apache2.433/conf/httpd.conf

将#ServerName www.example.com:80 改为:ServerName localhost:80

2.3.2 配置DirectoryIndex

# vi /usr/local/apache2.433/conf/httpd.conf

找:DirectoryIndex index.html 改为:DirectoryIndex index.html index.php

2.3.3开启apache支持伪静态

# vi /usr/local/apache2.433/conf/httpd.conf

AllowOverride None 改:AllowOverride All

LoadModule rewrite_module modules/mod_rewrite.so 去掉# 支持伪静态

2.3.4 添加apache服务系统环境变量

#vi /etc/profile #添加apache服务系统环境变量

在最后添加下面这一行

export PATH=$PATH:/usr/local/apache2.433/bin

2.3.5 把apache加入到系统启动

# cp /usr/local/apache2.433/bin/apachectl /etc/rc.d/init.d/httpd

# vi /etc/init.d/httpd

在#!/bin/sh下面添加以下两行

#chkconfig:2345 10 90

#description:Activates/Deactivates Apache Web Server

2.3.6 设置开机启动

# chkconfig httpd on

现在可以用命令 service httpd start || stop || restart 控制httpd了

查看端口状态 # netstat -an | grep 80

2.3.7虚拟主机配置

# vi /usr/local/apache2.433/conf/httpd.conf

在倒数十行找VirtualHost字眼位置去掉 Include **** extra/virtual-host-httpd.conf

2.3.8设置你的项目目录

默认配置 在 httpd.conf

可以修改成 你自己的设定的目录 如

注意这里改了,虚拟主机配置文件里面的最好也要改

三,常见报错:

1.apache安装报错configure: WARNING: OpenSSL version is too old no

checking whether to enable mod_ssl…

configure: error: mod_ssl has been requested but can not be built due to prerequisite failures

解决办法:#yum install openssl-devel

#yum update openssl

2.网站访问403

You don't have permission to access / on this server. Server unable to read htaccess file, denying access to be safe

解决办法:chmod -R 755 /var/myproject (给你的项目根目录设置访问权限)

万一装成功。。。请手动赞。。

编译按装php请看下篇


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值