1. 安装mysql

###############################

注意,刚开始安装出错,原因是二进制包下载错了,本机centos是32位的,却下载了个64位的二进制包

###############################

[root@chen src]# cd /usr/local/src/

[root@chen src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz   

#二进制包免编译,若是64位系统,则下载这个包,32位则下载下面排错时的包

[root@chen src]# tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz

[root@chen src]# mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/mysql

[root@chen ~]# useradd -s /sbin/nologin mysql

 [root@chen ~]# cd /usr/local/mysql

[root@chen mysql]# mkdir -p /data/mysql

[root@chen mysql]# chown -R mysql:mysql /data/mysql

[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

./scripts/mysql_install_db: line 249: ./bin/my_print_defaults: cannot execute binary file

Neither host 'chen' nor 'localhost' could be looked up with

./bin/resolveip

Please configure the 'hostname' command to return a correct

hostname.

If you want to solve this at a later stage, restart this script

with the --force option

########################

此时出现错误,经过搜集资料,发现是因为本机系统为32位,却下载了一个64位的二进制包

使用命令如下命令查看本机系统是32位,还是64位

[root@chen mysql]# getconf LONG_BIT

32


########################

#重新下下载一个对应包,再进行之前的操作,错误解决

[root@chen mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

Installing MySQL system tables...

OK

Filling help tables...

OK


To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

#出现两个OK则正确安装上了

[root@chen mysql]# cp support-files/my-large.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y       #由于系统自带此文件,需要将它覆盖掉

[root@chen mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@chen mysql]# chmod 755 /etc/init.d/mysqld

[root@chen mysql]# vim /etc/init.d/mysqld   #修改basedir和basedir,如下:


# overwritten by settings in the MySQL configuration files.


basedir=/usr/local/mysql

datadir=/data/mysql



[root@chen mysql]# chkconfig --add mysqld

[root@chen mysql]# chkconfig mysqld on

[root@chen mysql]# service mysqld start

Starting MySQL............. SUCCESS!

#成功安装并启动mysql

2. 安装apache

[root@chen src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz

[root@chen src]# tar zxvf httpd-2.2.31.tar.gz

[root@chen src]# cd httpd-2.2.31

[root@chen httpd-2.2.31]# ./configure --prefix=/usr/local/apache2 --with-included-apr  --with-pcre --enable-mods-shared=most

[root@chen httpd-2.2.31]# echo $?   #检查上一步是否出错,若为0则未出错,非0则有错

0

[root@chen httpd-2.2.31]# make && make install

[root@chen httpd-2.2.31]# echo $?

0

【如何指定使用worker/prefork】http://www.lishiming.net/thread-944-1-1.html
【apache两种工作模式】http://www.lishiming.net/thread-838-1-2.html

3.  安装php

[root@chen src]# wget http://cn2.php.net/distributions/php-5.3.28.tar.gz

[root@chen src]# tar zxf php-5.3.28.tar.gz

[root@chen src]# cd php-5.3.28

[root@chen php-5.3.28]# ./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

######################

执行上面命令的过程中会遇到一些依赖缺少的提示,下面列出我遇到的依赖问题:
错误:
configure: error: xml2-config not found. Please check your libxml2 installation.

解决:
yum  install -y  libxml2-devel

错误:
configure: error: jpeglib.h not found.

解决:
yum  install -y  libjpeg-devel

错误:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决:
yum  install  -y  libmcrypt-devel
由于版权原因,可能无法直接安装上面的包,在百度经验里找到了一个解决办法:
http://jingyan.baidu.com/article/54b6b9c0e94f1e2d583b4782.html

错误:
checking for recode support... yes
configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.

解决:
yum  install -y  librecode-devel


######################

重新编译执行如上操作,出现以下提示,则表明安装成功:

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

| 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.


[root@chen php-5.3.28]# echo $?

0

[root@chen php-5.3.28]# make && make install

[root@chen php-5.3.28]# echo $?

0

[root@chen php-5.3.28]#  cp php.ini-production /usr/local/php/etc/php.ini     #拷贝配置文件


4. 配置apache结合php

vim /usr/local/apache2/conf/httpd.conf找到:

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all

改为:

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all




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

AddType application/x-httpd-php .php
找到:

    DirectoryIndex index.html

将该行改为:

    DirectoryIndex index.html index.htm index.php

找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80


查看配置文件是否有问题:

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

如果显示Syntax OK,则没有问题了。然后启动服务:

/usr/local/apache2/bin/apachectl start

检查Apache是否正常启动:

[root@chen php-5.3.28]# ps aux |grep httpd

root      6733  0.0  1.0  28912  9952 ?        Ss   03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6734  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6735  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6736  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6737  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

daemon    6738  0.0  0.9  28912  8716 ?        S    03:58   0:00 /usr/local/apache2/bin/httpd -k start

root      6753  0.0  0.0   6052   788 pts/0    S+   04:01   0:00 grep httpd

5. 测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:

<?php
    echo "php解析正常";
?>
保存后,继续测试:

curl localhost/1.php