一、源码安装LAMP
网上有一堆关于介绍lamp的在这里我就不罗嗦了,直接上配置过程
 
1.apr包的安装
apr简介:
The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations.
The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.
下载地址:
wget http://labs.mop.com/apache-mirror//apr/apr-1.4.6.tar.gz
wget http://labs.mop.com/apache-mirror//apr/apr-util-1.4.1.tar.gz
tar xvf apr-1.4.6.tar.gz
tar xvf apr-util-1.4.1.tar.gz
cd apr-1.4.6
./configure 
make 
make install
 
在编译时有可能会出现以下问题
cannot remove `libtoolT': No such file or directory
解决方法:
vim configure
把RM='$RM'改为RM='$RM  -f',在configure里面 RM='$RM  -f'   这里的$RM后面一定有一个空格。 如果后面没有空格,直接连接减号,就依然会报错。
 
cd apr-util-1.4.1
./configure --with-apr=/usr/local/apr
make 
make install
 
如果使用的是apt-get 安装apr
apt-get install libaprutil1-dev libapr1-dev
在编译安装apache是会报错:
rotatelogs.c:(.text+0x603): undefined reference to `apr_file_link'
collect2: ld returned 1 exit status
make[2]: *** [rotatelogs] Error 1
make[2]: Leaving directory `/root/lamp/httpd-2.4.2/support'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/root/lamp/httpd-2.4.2/support'
make: *** [install-recursive] Error 1
原因是apr的版本太低,解决办法:源码安装apr较新包
 
 
2.apache包的安装
下载地址:
wget http://mirror.bjtu.edu.cn/apache//httpd/httpd-2.4.3.tar.bz2
 
tar xvf httpd-2.4.3.tar.bz2
cd httpd-2.4.3
 
 
./configure --prefix=/usr/local/apache2 --enable-modules=shared --enable-so --enable-deflate --enable-expires --enable-headers --enable-rewrite --with-included-apr=/usr/local/apr --with-included-apr-util
make 
make install
 
编译过程中可能遇到
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决方法:apt-get install libpcre3-dev
 
checking for zlib location... not found
checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
解决方法:apt-get install zlib1g-dev
 
启动、重启和停止
/usr/local/apache2/bin/apachectl -k start
/usr/local/apache2/bin/apachectl -k restart
/usr/local/apache2/bin/apachectl -k stop
 
 
每次启动都输入那么长的命令是不是很烦,解决方法:
a.软连接的PATH路径,
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
ln -sv /usr/local/apache2/bin/* /usr/sbin  (或者/usr/bin、/usr/local/bin等)
然后就可以直接在终端用:
apachectl -k start
apachectl -k restart
apachectl -k stop
 
b.把/usr/local/apache2/bin/加入PATH路径
vim /etc/profile
#增加
PATH="$PATH:/usr/local/apache2/bin"
source /etc/profile
 
apache配置文件的修改:
vim /usr/local/apache2/conf/httpd.conf
找到:
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    在后面添加:
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    
找到:
    <IfModule dir_module>
    DirectoryIndex index.html
    </IfModule>
    添加:
    <IfModule dir_module>
    DirectoryIndex index.html index.php
    </IfModule>    
 
 找到:
    #ServerName www.example.com:80
    修改为:
    ServerName yourhostip:80
 
重启apache:  apachectl -k restart
 
通过浏览器访问:http://yourhostip
应该显示:It works!
 
3.mysql的安装
请参考:
 
初始化mysql数据库时可能会遇到:
./bin/mysqld: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
解决方法:apt-get install libstdc++5
 
4.php的安装
下载地址:
wget http://cn.php.net/get/php-5.4.6.tar.bz2/from/this/mirror
tar xvf php-5.4.6.tar.bz2
cd php-5.4.6
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-curl --with-mcrypt --enable-mbstring --enable-pdo --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --with-imap-ssl --with-gd --with-jpeg-dir=/usr/lib/ --with-png-dir=/usr/lib/ --enable-exif --enable-zip --enable-dba=shared --with-mysql=/usr/local/mysql
这一步可能会遇到:
/usr/bin/ld: cannot find -liconv
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解决办法:
apt-get install libglobus-libtool-dev
 
checking libxml2 install dir... no
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法:apt-get install libxml2-dev
 
configure: error: Cannot find OpenSSL's <evp.h>
解决方法:apt-get install libssl-dev
 
checking if we should use cURL for url streams... no
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
解决方法:apt-get install libcurl4-openssl-dev
 
configure: error: jpeglib.h not found.
解决方法:apt-get install libjpeg62-dev
 
configure: error: png.h not found.
解决方法:apt-get install libpng-dev
 
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:apt-get install libmcrypt-dev
 
 
php 5.4.6 make 时在apprentice.c -o ext/fileinfo/libmagic/apprentice.lo 没反应了
在网上查了查是内存不足,这一步要编译过去至少要有1G内存,我只有300M的内存。
把该虚拟机内存调到1.2G,这一步就ok了
 
以上编译过程中产生的编译错误,当然如果你搭建过n边LAMP环境就可以直接以下操作,是不是省事很多
apt-get install -y curl libxml2 libxml2-dev libssl-dev sendmail libcurl4-openssl-dev libjpeg-dev libpng-dev libmcrypt-dev
不知道大家发现规律没有,一般在ubuntu下编译通过不了,根椐报错找到XXXX-dev的包安装即可。如果你人品差,apt-get 安装的包版本太低
那就需要下载更新的软件包编译安装了。
make
make test
make install
 
cp php.ini-production /usr/local/php/lib/php.ini
vim /etc/profile
PATH=$PATH:/usr/local/php/bin/
source /etc/profile
 
验证一下php是否正确安装:
apachectl -k restart
cd /usr/local/apache2/htdocs
vim index.php
<?php
phpinfo();
?>
通过浏览器访问:http://yourhostip/index.php
如果能正确访问说明php安装ok了
 
测试php与mysql的链接性
设置mysql的权限:允许通过本机或同一网段的主机链接mysql server,同一网段(192.168.12.0)如:192.168.12.%
mysql -uroot -predhat
mysql>grant all privileges on *.* to 'root'@'yourhostip_in_network';
 
测试链接脚本:
vim /usr/local/apache2/htdocs/index.php
<?php
$link=mysql_connect('yourhostip','root','redhat');
if(!$link)
echo "connect mysql failing...";
else
echo "connect mysql successful...";
mysql_close();
?>
 
通过浏览器访问:http://yourhostip/index.php
提示:500错误,这样也看不出具体哪出错了
 
在终端下直接用php执行index.php
php index.php
 
提示:PHP Fatal error:  Call to undefined function mysql_connect()
google 了一下大部分说在php.ini中把,extension=msql.so 的注释去掉,改了之后还是不行而且还会有新的错误,有两种方法可以解决:
 
a.是在configure 时没有关联mysql导致的,在configure 后加 --with-mysql=/usr/local/mysql,重新编译安装php就行了
 
b.msql.so文件不存在,生成.so文件
 cd php-5.4.6/ext/mysql

安装autoconf,因为phpize命令执行生成configure文件需要
apt-get install autoconf

执行命令
phpize
在当前目录下会生成configure文件

./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr/local/mysql
make
make install
在/usr/local/php/lib/php/extensions/no-debug-zts-20100525/目录下自动生成mysql.so文件
修改配置文件:vim /usr/local/php/lib/php.ini 
去掉注释并修改extension=mysql.so

为什么会出现上述的问题?原因很简单你在编译时没有让php包含进mysql的一些库函数,那样在php脚本中就不能用mysql的函数去操作数据库。要么我们重新编译,要么不重新编译生成扩展文件xxx.so.
 
ok,到此LAMP的环境就搭建好了,下面我们基于LAMP环境搭建wordpress博客平台
 
二、安装wordpress
下载wordpress:wget http://cn.wordpress.org/wordpress-3.4.1-zh_CN.zip
apt-get install unzip
 
unzip wordpress-3.4.1-zh_CN.zip
mv wordpress /usr/local/apache2/htdocs/
 
数据库的设置:
mysql -uroot -predhat
mysql>create database wordpress;
mysql>grant all privileges on wordpress.* to 'wpuser'@'10.48.255.%' identified by "redhat";
mysql>flush privileges;
 
修改wordpress的配置文件:
cp /usr/local/apache2/htdocs/wordpress/wp-config-sample.php /usr/local/apache2/htdocs/wordpress/wp-config.php 
vim /usr/local/apache2/htdocs/wordpress/wp-config.php
#修改一下几行
define('DB_NAME', 'wordpress');
 
/** MySQL 数据库用户名 */
define('DB_USER', 'wpuser');
 
/** MySQL 数据库密码 */
define('DB_PASSWORD', 'redhat');
 
/** MySQL 主机 */
define('DB_HOST', '10.48.255.244');
 
通过浏览器:http://yourhostip/wordpress/
完成剩余的配置
 
通过admin登入,在设置常规中开启,任何人都可以注册,然后访问wordpress就可以看到注册按钮了
 
实现用户注册,需邮件激活:
注册一个用户,发现他是把激活信息发到邮箱,打开邮箱但是没有邮件;手动找回密码,显示可能原因:您的主机禁用了 mail() 函数...
google是因为少了发邮件的插件:WP Mail SMTP,插件的下载:
wget http://downloads.wordpress.org/plugin/wp-mail-smtp.0.9.1.zip
unzip wp-mail-smtp.0.9.1.zip
 
wordpress插件的安装同cacti差不多,把插件copy到相应的目录下即可
mv wp-mail-smtp  /usr/local/apache2/htdocs/wordpress/wp-content/plugins
 
以管理员的身份登入:插件--》启动WP-Mail——SMTP--》Settings
From Email  example@126.com
From Name   nsfocus
Mailer   Send all WordPress emails via SMTP
Return Path  勾上
 
smtp host smtp.126.com
Authentication  Yes
 
username example@126.com
password xxxxxxxxx
 
保存,再试,ok email 发过来了,但是点击激活信息时提示:抱歉,该 key 似乎无效
解决方法:
找到wordpress根目录下的的wp-login.php文件:找到下面的字符串:
$message .= ‘<' . network_site_url(“wp-login.php?action=rp&key=$key&login=” . rawurlencode($user_login), ‘login’) . “>\r\n”;
改成
$message .= network_site_url(“wp-login.php?action=rp&key=$key&login=”. rawurlencode($user_login), ‘login’) . “\r\n”;
也就是把 左边的  '<'.  和最后的   >   删掉就解决了