一、准备工作:

1、全新安装redhat6.5系统,修改主机名,修改网络配置,设置可使用外网,设置用户账户密码;

2、iptables -F清除防火墙规则,sevices iptables save保存防火墙规则;

3、使用xshell 5进行ssh连接;

4、因无法使用红帽yum源使用winscp传送163yum源到/etc/yum.repo.d/目录下

5、编辑CentOS6-Base-163.repo文件,开户yum源开关,具体配置如下:

[root@redhat yum.repos.d]# vi /etc/yum.repos.d/CentOS6-Base-163.repo 

[base]

name=CentOS-$releasever - Base - 163.com

baseurl=http://mirrors.163.com/centos/6/os/x86_64/

enabled=1

gpgcheck=0

[updates]

name=CentOS-$releasever - Updates - 163.com

baseurl=http://mirrors.163.com/centos/6/updates/x86_64/

enabled=1

gpgcheck=0

[extras]

name=CentOS-$releasever - Extras - 163.com

baseurl=http://mirrors.163.com/centos/6/extras/x86_64/

enabled=1

gpgcheck=0

[centosplus]

name=CentOS-$releasever - Plus - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/

release=$releasever&arch=$basearch&repo=centosplus

gpgcheck=0

enabled=0

6、yum安装上传下载工具yum install -y lrzsz

二、开始安装mysql

1、下载mysql到/usr/local/src目录,我已经下载好mysql

cd /usr/local/src/

使用rz命令将mysql上传到src目录

2、解压:tar -zxvf mysql-5.1.72-linux-x86_64-glibc23.tar.gz

3、把解压完的数据移动到/usr/local/目录下并重全名为mysql

mv mysql-5.1.72-linux-x86_64-glibc23 /usr/local/mysql
4、建立mysql用户 useradd -s /sbin/nologin mysql
5、初始化mysql数据库 cd /usr/local/mysql  mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql  ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

6、卸载自带的mysql数据库 yum remove mysql 

7、拷贝配置文件

 cp support-files/my-large.cnf /etc/my.cnf

拷贝启动角本并修改属性 cp support-files/mysql.server /etc/init.d/mysqld 

chmod 755 /etc/init.d/mysqld 

8、修改启动角本 

 vim /etc/init.d/mysqld

修改basedir 和datadir目录 

basedir=/usr/local/mysql

datadir=/data/mysql

  1. 把启动脚本加入系统服务项,并设定开机启动,启动mysql

chkconfig --add mysqld
chkconfig mysqld on
service mysqld start

使用ps aux |grep mysqld查看mysql是否启动

#注释:

在此文件查看mysql编译参数

/usr/local/mysql/bin/mysqlbug|grep -i configure

手动启动mysql的命令

/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/my.cnf --user=mysql --datadir=/data/mysql

如果重启mysql时出现以下错误:Starting MySQL. ERROR! The server quit without updating PID file (/longxibendi/mysql/mysql.pid). 则可能是因为/usr/local/mysql/my.cnf和/etc/my.cnf冲突,删除/etc/my.cnf

三、安装apache

1、下载apache软件并上传到/usr/local/src

2、解压apache 

 tar zxvf httpd-2.2.16.tar.gz

3、配置编译参数 

cd httpd-2.2.16
./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre
#注释:
--prefix=/usr/local/apache2安装目录
--with-included-apr跨平台操作组件
--enable-deflate=shared
--enable-expires=shared
--enable-rewrite=shared这三个表示动态共享
--with-pcre正则相关的库
使用echo $?查看返回值是否为0为0是成功编译

4、编译 make 使用echo $?查看编译是否成功

5、安装 make install 使用echo $?查看是否安装成功

#注释:

6、使用-t参数查看apache配置文件是否正确

/usr/local/apache2/bin/apachectl -t   返回值ok配置正解

/usr/local/apache2/bin/apachectl -M 查看模块(包括动态和静态模块)

/usr/local/apache2/bin/apachectl -l 只列出静态模块

/usr/local/apache2/modules 动态模块所在目录

/usr/local/apache2/bin/httpd 静态模块已经编译在这个文件里 

/usr/local/apache2/bin/apachectl graceful重新加载配置文件

在此文件查看apache的编译参数

/usr/local/apache2/build/config.nice

7、启动apache /usr/local/apache2/bin/apachectl start

四、安装php 

1、下载php文件并上传到src目录

2、配置编译参数 

cd php-5.4.36

./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=/usr/local/php/etc  \
--with-mysql=/usr/local/mysql \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-bz2 \
--with-openssl \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6
#注释:
--with-apxs2=/usr/local/apache2/bin/apxs自动安装扩展模块的参数

3、因为缺少需要的库文件编译参数不成功提示: mcrypt.h not found. Please reinstall libmcrypt

安装扩展源然后使用yum install安装:

rpm -ivh "http://www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_64.noarch.rpm"
然后yum install -y  libmcrypt-devel

(也可以直接下载libmcrypt 的rpm安装包安装

rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm )

重新配置编译文件,当出现以下结果时说明配置成功:

Generating files

configure: creating ./config.status

creating main/internal_functions.c

creating main/internal_functions_cli.c

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+


Thank you for using PHP.


config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/cgi/php-cgi.1

config.status: creating ext/phar/phar.1

config.status: creating ext/phar/phar.phar.1

config.status: creating main/php_config.h

config.status: executing default commands

也可以使用echo $?查看是否成功

4、编译 make  编译完成会有如下提示,

Build complete.

Don't forget to run 'make test'.

5、安装 make install  使用echo $?查看返回值为0安装成功

注释:

/usr/local/php/bin/php -m查看模块(静态)

在此文件查看编译参数

/usr/local/php/bin/php -i |grep configure

使用ldd查看php或apache或Mysql或nginx依赖的库文件的位置

ldd /usr/local/php/bin/php


6、拷贝配置文件 cp php.ini-production /usr/local/php/etc/php.ini

7、编辑apache主配置文件使apache结合php

vim /usr/local/apache2/conf/httpd.conf

找到该行AddType application/x-gzip .gz .tgz下面添加一行

AddType application/x-httpd-php .php

找到该行<IfModule dir_module>

修改该行下面的字符为

 DirectoryIndex index.html index.htm index.php

找到

#ServerName www.example.com:80

修改为ServerName localhost:80

检测配置文件

/usr/local/apache2/bin/apachectl -t 


重新加载配置文件

/usr/local/apache2/bin/apachectl graceful

写个简单的php文件

vim info.php

<?php

phpinfo();

?>

在浏览器访问测试可以访问