零起步7-CentOS6.3关于LAMP的配置apache-2.4.3、php-5.4.7、phpMyAdmin3.5

全新以最小化包安装了64位的CentOS6.3系统,作为本地的Web服务器使用,现记录全过程
第七步,LAMP配置,版本为httpd-2.4.3、php-5.4.7、phpMyAdmin3.4

准备工作,下载相应安装包
[root@localhost ~]# yum install wget -y
[root@localhost ~]# wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.3.tar.gz
[root@localhost ~]# wget http://mirrors.axint.net/apache/apr/apr-1.4.6.tar.gz
[root@localhost ~]# wget http://mirrors.axint.net/apache/apr/apr-util-1.5.1.tar.gz
[root@localhost ~]# wget http://cn2.php.net/distributions/php-5.4.7.tar.gz
[root@localhost ~]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
[root@localhost ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz


安装apache,版本为httpd-2.4.3,之前apache2.2的编译安装方法对apache2.4有些不适应
以上源码包全部用tar zxvf xxx.tar.gz解压缩,apache2.4官网文档地址为

安装apache依赖包pcre
[root@localhost ~]# cd /usr/software/pcre-8.31
[root@localhost ~]# ./configure --prefix=/usr/local/pcre
[root@localhost ~]# make && make install

更新openssl库,否则编译时会报openssl太旧
[root@localhost ~]# yum install openssl-devel
[root@localhost ~]# yum update openssl

将apr、apr-util移动到apache的srclib目录
[root@localhost ~]# mv /usr/software/apr-1.4.6 /usr/software/httpd-2.4.3/srclib/apr
[root@localhost ~]# mv /usr/software/apr-util-1.5.1 /usr/software/httpd-2.4.3/srclib/apr-util

编译安装,对编译参数不熟悉的,可以用./configure --help查看
[root@localhost ~]# cd /usr/software/httpd-2.4.3
[root@localhost ~]# ./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-included-apr --with-mpm=prefork --enable-cache --enable-file-cache --with-pcre=/usr/local/pcre
[root@localhost ~]# make && make install

配置开机自启动
[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@localhost ~]# vim /etc/init.d/httpd
在#!/bin/sh 下面加上这两行,wq保存退出
# chkconfig: 345 90 90
# description: Apache
[root@localhost ~]# chkconfig --add /etc/init.d/httpd
[root@localhost ~]# service httpd start

打开防火墙80、443端口
[root@localhost ~]# vim /etc/sysconfig/iptables
加上以下现行,wq保存退出
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
[root@localhost ~]# service iptables restart

修改httpd.conf文件,避免“AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using centos.huoba. Set the 'ServerName' directive globally to suppress this message”错误提示
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
找到“#ServerName www.example.com:80”,在下面加上这一行
ServerName localhost:80

Apache至此已经完成安装,另附相关命令,以后会常用
查看apache版本
[root@localhost ~]# /usr/local/apache/bin/httpd -v
查看apache已编译安装的模块
[root@localhost ~]# /usr/local/apache/bin/httpd -M

接下去还有文章会提到安装postfix+cyrus-sasl+mysql+extmail+maildrop时还会提到suexec模块的编译配置


安装php,版本为php-5.4.7

安装php依赖包libmcrypt
[root@localhost ~]# cd /usr/software/libmcrypt-2.5.8
[root@localhost ~]# ./configure
[root@localhost ~]# make && make install

安装相关资源及图片依赖包
[root@localhost ~]# yum install bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel -y
以下错误都是跟上述包没安装有关
Configure: error: Please reinstall the libcurl distribution -easy.h should be in /include/curl/
yum install bzip2 bzip2-devel

Configure: error: Please reinstall the BZip2 distribution
yum install curl curl-devel

configure: error: jpeglib.h not found.
yum install libjpeg libjpeg-devel

configure: error: png.h not found.
yum install libpng libpng-devel

configure: error: freetype.h not found.
yum install freetype-devel

更多的常见编译错误,可以参考这篇文章: http://hi.baidu.com/susuper_/item/27c588dd7d57affc3dc2cb07

编译安装php,该编译方法默认添加的mysql支持,无需再配置
[root@localhost ~]# cd /usr/software/php-5.4.7
[root@localhost ~]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/include/libxml2  --with-config-file-path=/usr/local/apache/conf --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --enable-gd-native-ttf --with-zlib --with-mcrypt --with-pdo-mysql=/usr/local/mysql --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --with-xmlrpc --enable-fpm --enable-mbstring --with-zlib-dir --with-bz2 --with-curl --enable-exif --enable-ftp --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-freetype-dir=/usr/lib/
[root@localhost ~]# make && make install

php配置,编译安装时我的php.ini文件目录指向/usr/local/apache/conf
[root@localhost ~]# cp /usr/software/php-5.4.7/php.ini-production /usr/local/apache/conf/php.ini 

apache配置文件httpd.conf相关修改
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
1. 添加php支持,在末尾处加下如下代码
    # php_module Configuration
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps
    PHPIniDir "conf"
2. 添加默认索引页面index.php,再找到“DirectoryIndex”,在index.html后面加上“ index.php”
    DirectoryIndex index.html index.php index.jsp
3. 找到“#ServerName www.example.com:80”,在下面加上这一行
    ServerName localhost:80
4. 不显示目录结构,找到“Options Indexes FollowSymLinks”,修改为
    Options FollowSymLinks
5. 开启Apache支持伪静态,找到“AllowOverride None”,修改为
    AllowOverride All

保存httpd.conf配置,然后再执行以下两行命令
[root@localhost ~]# chown -R nobody. /usr/local/apache/htdocs/
[root@localhost ~]# chmod -R 777 /usr/local/apache/htdocs/


PHP至此已经完成安装,另在mongodb篇会详细讲解mongodb的 的php驱动安装,其中有 phpize使用介绍,以后会常用
phpize主要用来加载php扩展,使用phpize不用重新编译整个php,以加载mongodb的php驱动为例介绍一下phpize使用


phpMyAdmin配置使用,版本为phpMyAdmin-3.5.3-all-languages

将phpMyAdmin解压后移到/usr/local/apache/htdocs/目录下,并将目录名改为phpMyAdmin
1. phpMyAdmin配置文件加载顺序说明
    phpmyadmin3中默认首先加载libraries/config.default.php配置文件的内容,如果有/config.inc.php,就会在config.inc.php配置文件中找到相同的变量并覆盖
2. phpMyAdmin配置文件说明
    config.inc.php配置示例请参考/config.sample.inc.php
3. 修改config.default.php配置
[root@localhost ~]#  vim /usr/local/apache/htdocs/phpMyAdmin/libraries/config.default.php
    $cfg['Servers'][$i]['host'] = 'localhost';              //mysql服务器IP地址,本机为localhost
    $cfg['Servers'][$i]['port'] = '';                           //mysql连接端口,默认3306时可以留空
    $cfg['Servers'][$i]['extension'] = 'mysqli';          //mysql的连接扩展应该为mysqli
    $cfg['Servers'][$i]['user'] = 'root';                     //mysql数据库用户名为root
    $cfg['Servers'][$i]['password'] = '';                   //在此处填写mysql密码
    $cfg['LoginCookieValidity'] = 14400;                //phpMyAdmin的cookie会话时长,默认为1440(即24分钟),修改为14400
4. 至此配置已全部结束,使用以下地址访问phpMyAdmin
     http://192.168.0.21/phpMyAdmin/                  //其中192.168.0.21即为你服务器的IP地址


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值