原文地址:CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境

下载安装包
apr-1.4.6.tar.gz
apr-util-1.5.1.tar.gz
httpd-2.4.4.tar.gz
mysql-5.6.10.tar.gz
pcre-8.32.tar.gz
php-5.3.22.tar.gz
zlib-1.2.7.tar.gz

 

解压
tar -xzvf apr_1.4.6.tar.gz
。。。挨个儿解压

 

卸载默认低版本的环境
先看看有没有安装httpd软件包
# rpm -qa | grep httpd
如果装了就卸载
# rpm -e httpd-2.2.15-15.el6.centos.1.x86_64 --nodeps
说明:卸载软件包, --nodeps 如果有连带关系,也强制卸载
# cd /etc/httpd
# rm -rf *

# rpm -qa | grep mysql
# rpm -qa | grep php
一样如果装了就卸载

 

安装gcc gcc-c++编译器
# yum install gcc
# yum install -y gcc gcc-c++

 

# cd apr-1.4.6
# ./configure --prefix=/usr/local/apr
# make && make install

# cd apr-util-1.5.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
# make && make install

# cd zlib-1.2.7
# ./configure --prefix=/usr/local/zlib
# make && make install

# cd pcre-8.32
# ./configure --prefix=/usr/local/pcre
# make && make install
如果报you need c++ compiler.... 就:
# yum install -y gcc gcc-c++

 

安装apache
# cd httpd-2.4.4
# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-

zlib=/usr/local/zlib/ --with-pcre=/usr/local/pcre/ --enable-so --enable-rewrite
# make && make install

将apache安装为系统服务
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
然后 vi /etc/rc.d/init.d/httpd 添加(# !/bin/sh下面)
# chkconfig: 2345 50 90
# description: Activates/Deactivates Apache Web Server
保存退出
最后,运行chkconfig把Apache添加到系统的启动服务组里面:
# chkconfig --add httpd
# chkconfig httpd on
然后再service httpd start

如果报:httpd (pid 5658) already running 就说明已经启动了
如果重启不了也停不掉,解决办法:
# vi /etc/httpd/httpd.conf
找到# ServerName www.example.com:80 把#去掉,重启apache即可

启动Apache
# /usr/local/apache2/bin/apachectl start
关闭Apache
# /usr/local/apache2/bin/apachectl stop
查看80端口是否开启
# netstat -tnl|grep 80

 

安装mysql
先安装cmake
# yum install cmake
# cd mysql-5.6.10
# rm CMakeCache.txt
# yum -y install ncurses-devel
# yum install bison
直接cmake编译
# cmake .
# make && make install
很慢 等着吧

 

配置Mysql
先进入mysql安装目录
# cd /usr/local/mysql/
创建MySQL数据库服务器的配置文件
# cp support-files/my-default.cnf /etc/my.cnf
初始化用mysql用户创建授权表,创建成功后,会在/usr/local/mysql目录下生成一个data目录
# scripts/mysql_install_db --user=mysql &

将文件的所有属性改为root用户
# chown -R root /usr/local/mysql/
将数据目录的所有属性改为mysql用户
# chown -R mysql /usr/local/mysql/data
将组属性改为mysql组
# chgrp -R mysql /usr/local/mysql
也可以直接
# chown -R mysql:mysql /usr/local/mysql/

启动数据库
# bin/mysqld_safe --user=mysql &
查看3306端口是否开启
# netstat -tnl|grep 3306
简单的测试
# bin/mysqladmin version
查看所有mysql参数
# bin/mysqladmin variables

设置Mysql开机自启动
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
# chown root.root /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
# chkconfig --levels 245 mysqld off

# service mysqld start

测试一下:
# mysql -u root -p
然后输入密码,如果能够进入就说明安装好了

把mysql安装为系统启动项
# vi /etc/rc.d/init.d/mysqld 添加(# !/bin/sh下面)
# chkconfig: 2345 51 89
# description: Activates/Deactivates MySQL Server
保存退出
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld restart

 

删除非localhost的主机
 mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';
刷新授权表
 mysql> FLUSH PRIVILEGES;
为root用户添加密码
 mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('abc123');
再次进入Mysql客户端
 # /usr/local/mysql/bin/mysql -u root -h localhost -p
关闭MySQL数据库
 # /usr/local/mysql/bin/mysqladmin -u root -p shutdown

 

安装php
先安装libxml2
# yum install libxml2
# yum install libxml2-devel -y
# cd php-5.3.22
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-

zlib=/usr/local/zlib/ --enable-soap --enable-mbstring=all --enable-sockets
# make && make install

 

创建配置文件
# cp php.ini-development /usr/local/php/etc/php.ini
使用vi编辑apache配置文件
# vi /etc/httpd/httpd.conf
添加这一条代码
Addtype application/x-httpd-php .php .phtml
重启Apache
# /usr/local/apache2/bin/apachectl restart

 

测试一下php
# vi /usr/local/apache2/htdocs/info.php
<?php
phpinfo();
?>
通过浏览器访问http://localhost/info.php,获得php的详细配置信息