示意流程图:

 

CentOS源使用的范围很广泛。用CentOS源安装LAMP。为了方便大家的理解,我们使用了很简单的安装方法。希望大家可以很好的理解。昨天又换了VPS,来自DiaHosting。这次最主要的目的是用作Web服务器。为了习惯,还是决定先用Apache。

首先做一些准备工作,准备好CentOS源安装包: 

cd /usr/local/src 
wget http://lnmp-v4.googlecode.com/files/mysql-5.1.44.tar.gz 
wget http://archive.apache.org/dist/httpd/httpd-2.2.13.tar.gz 
wget http://autosetup1.googlecode.com/files/php-5.2.13.tar.gz 
wget 

接着CentOS源安装编译器,运行库等需要的东西: 

yum install make 
yum install gcc gcc-c++ 
yum install libxml2 libxml2-devel 
yum install libmcrypt libmcrypt-devel 
yum install libtool-ltdl 
yum install apr apr-* 
yum install ncurses ncurses-*

CentOS源安装sendmail: 

yum install sendmail sendmail-* 
service sendmail start

接下来开始CentOS源安装配置MySQL: 

cd /usr/local/src 
tar zxvf mysql-5.1.44.tar.gz 
cd mysql-5.1.44 
./configure --prefix=/usr/local/mysql 
make 
make install 
cp support-files/my-medium.cnf /etc/my.cnf 
cd /usr/local/mysql 
groupadd mysql 
useradd -g mysql -d /usr/local/mysql/var mysql 
chown -R mysql . 
chgrp -R mysql . 
bin/mysql_install_db --user=mysql 
chown -R mysql var

将MySQL注册为服务,开机自启动: 

cp /usr/local/src/mysql-5.1.44/support-files/mysql.server \ 
/etc/rc.d/init.d/mysql 
chmod +x /etc/rc.d/init.d/mysql 
chkconfig --add mysql 
service mysql start

MySQL启动之后,设置root密码: 

/usr/local/mysql/bin/mysqladmin -u root \ 
-p password newpassword

下一步安装Apache: 

cd /usr/local/src 
tar zxvf httpd-2.2.13.tar.gz 
cd httpd-2.2.13 
./configure --prefix=/usr/local/apache \ 
--with-mysql=/usr/local/mysql \ 
--enable-rewrite=shared \ 
--enable-module=so \ 
--enable-shared=max 
make 
make install

最后CentOS源安装PHP:

cd /usr/local/src 

tar zxvf php-5.2.13.tar.gz 
cd php-5.2.13 
./configure --prefix=/usr/local/php \ 
--with-mysql=/usr/local/mysql \ 
--with-apxs2=/usr/local/apache/bin/apxs \ 
--with-mcrypt =/usr/local/libmcrytp\ 
--enable-mbstring

make 

make install 
cp php.ini-dist /usr/local/php/lib/php.ini

安装php的时候可能遇到下面这些问题

①编译的时候报错libxml2错误

安装:libxml2-2.72.tar.gz就可以了

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

解决办法:

下载

wget 

安装:  

# tar -zxvf libmcrypt-2.5.7.tar.gz  
# cd libmcrypt-2.5.7  
# mkdir -p /usr/local/libmcrytp  
# ./configure prefix=/usr/local/libmcrytp/  
# make 
# make install

配置httpd.conf: 

vi /usr/local/apache/conf/httpd.conf 
找到“AddType application/x-gzip .tgz”这一行,在下面添加: 
AddType application/x-httpd-php .php 
AddType application/x-httpd-php-source .phps 
找到“DirectoryIndex index.html”,改为: 
DirectoryIndex index.php index.html 
找到“#ServerName”,去掉注释的#号。

将所有“AllowOverride None”,改为: 

AllowOverride All

注册服务,并启动Apache: 

cp /usr/local/apache/bin/apachectl \ 
/etc/rc.d/init.d/httpd 
vi /etc/rc.d/init.d/httpd

找到“#!/bin/sh”,另起一行,增加: 

# chkconfig: 35 70 30 
# description: Apache 
继续: 
chkconfig --add httpd 
service httpd start

LAMP安装完成,新建一个测试页面: 

vi /usr/local/apache/htdocs/index.php 
写入: 
打开浏览器,http://localhost/index.php。

下面根据需要,CentOS源安装phpMyAdmin: 

cd /usr/local/src 
tar zxvf phpMyAdmin-3.2.5-all-languages.tar.gz 
mv phpMyAdmin-3.2.5-all-languages /usr/local/apache/htdocs/phpmyadmin 
配置phpMyAdmin: 
cd /usr/local/apache/htdocs/phpmyadmin 
cp config.sample.inc.php config.inc.php 
vi config.inc.php 
找到“blowfish_secret”,在后面的单引号之间添加任意字符串。 
访问 

来源:PHP淮北@杭州泛泛:伟大是熬出来的!