准备工作
为了不影响实验效果,提前可以把selinux 和iptables 关闭
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# chkconfig ip6tables off
[root@localhost ~]# /etc/init.d/iptables stop
[root@localhost ~]# /etc/init.d/ip6tables stop
[root@localhost ~]# sed -i "s/LINUX=.*/LINUX=disabled/g" /etc/selinux/config
更改完selinux后要想生效需要重启一下服务器,reboot或者shutdown -r now
apache对php的支持是通过apache的mod_php5模块来支持的,这点与nginx不同。nginx是通过第三方的fastcgi处理器才可以对php进行解析.
因为我在安装的时候需要依赖包这里你可以自行安装一下:
yum install -y gcc gcc-c++ pcre-devel pcre zlib zlib-devel
第一步安装mysql 5.5
参考(mysql-5.5)
第二步:安装apache
首先下载httpd-2.4.7.tar.gz源码包
进入安装目录,依次执行下面命令:
# cd /usr/local/src/
解压源码包
# tar zxvf httpd-2.4.7
进入安装目录
# cd httpd-2.4.7
配置apache安装信息, 配置安装后目录,模块动态配置,允许重写重配置
# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
需要下载apr和apr-utils并解压到 ./srclib/ 目录下, 再进行编译。2.4版本要求apr1.4以上版本
# tar zxvf apr-util-1.4.1.tar.gz
# tar zxvf apr-1.4.6.tar.gz
# cp -r apr-1.4.6 httpd-2.4.7/srclib/apr
# cp -r apr-util-1.4.1 httpd-2.4.7/srclib/apr-util
# cd httpd-2.4.7
# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
报错:
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.4.7/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
解决方法:需要安装gcc
# yum install -y gcc
[root@pxe httpd-2.4.20]# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
报错:
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决方法:需要安装pcre
# yum search pcre
# yum install -y pcre-devel pcre
[root@pxe httpd-2.4.20]# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
报错:
checking for zlib location... not found
checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
解决方法:需要安装zlib
# yum search zlib
# yum install -y zlib zlib-devel
# ./configure --prefix=/usr/local/apache2/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared
# make
# make install && echo $?
第二步:配置apache
修改httpd.conf文件
# vim /usr/local/apache2/conf/httpd.conf
//ServerName 修改主机名称,若无dns,则用IP替代
ServerName 192.168.244.144:80
//DocumentRoot 修改文档路径,就是要放置目标网页的地方
DocumentRoot "/usr/local/apache2//htdocs"
//DirectoryIndex 修改默认的首页名称
DirectoryIndex index.html index.php
开启apache服务
# /usr/local/apache2/bin/apachectl start
# vi /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/apache2/bin/
[root@pxe httpd-2.4.20]# . /etc/profile.d/path.sh
[root@pxe httpd-2.4.20]# apachectl stop
[root@pxe httpd-2.4.20]# apachectl start
[root@pxe src]# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.local
开机启动
测试一下网页
更改一下网页的内容
ok 这里apache就按照完毕了
第三步 安装php
参考( php 安装 )
网页测试
Apache主配置文件为:/usr/local/apache2/conf/httpd.conf
更改3个地方
第一 添加 AddType application/x-httpd-php .php
第二 添加 index.php
第三 注销掉# AllowOverride none,把Require all denied 改成 Require all granted
# vim /usr/local/apache2/conf/httpd.conf
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php (定义apache解析PHP)
#
#
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
#
<Directory />
# AllowOverride none
Require all granted
</Directory>