(一)安装apache

1、安装apache依赖包

 yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel

2、下载并安装apache2.2.31

wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gztar xf httpd-2.2.31.tar.gz cd httpd-2.2.31./configure \--prefix=/application/apache2.2.31 \--enable-deflate \--enable-expires \--enable-headers \--enable-modules=most \--enable-so \--with-mpm=worker \--enable-rewritemakemake installln -s /application/apache2.2.31/ /application/apachels -l /application/总用量 4lrwxrwxrwx  1 root root   26 6月  27 22:37 apache -> /application/apache2.2.31/drwxr-xr-x 15 root root 4096 6月  27 22:35 apache2.2.31

3、编写apache启动脚本

#!/bin/bash# chkconfig: 2345 85 15. /etc/rc.d/init.d/functionsif [ -f /etc/sysconfig/httpd ]; then        . /etc/sysconfig/httpdfiINITLOG_ARGS=""apachectl=/application/apache/bin/apachectl     (修改)httpd=/application/apache/bin/httpd             (修改)pid=$httpd/logs/httpd.pidprog=httpdRETVAL=0start() {        echo -n $"Starting $prog: "        daemon $httpd $OPTIONS        RETVAL=$?        echo        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd        return $RETVAL}stop() {        echo -n $"Stopping $prog: "        killproc $httpd        RETVAL=$?        echo        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid}reload() {        echo -n $"Reloading $prog: "        killproc $httpd -HUP        RETVAL=$?        echo}case "$1" in  start)        start        ;;  stop)        stop        ;;  status)        status $httpd        RETVAL=$?        ;;  restart)        stop        start        ;;  condrestart)        if [ -f $pid ] ; then                stop                start        fi        ;;  reload)        reload        ;;  graceful|help|configtest|fullstatus)        $apachectl $@        RETVAL=$?        ;;  *)        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status"        echo $"|fullstatus|graceful|help|configtest}"        exit 1esacexit $RETVAL

4、设置apache开机启动

chkconfig  --add httpdchkconfig  --list  httpdchmod +x  /etc/init.d/httpd/etc/init.d/httpd restart

5、配置基于域名的虚拟主机

cd /application/apache/conf/vim httpd.conf 修改98行ServerName 127.0.0.1:80修改132 
修改378 Include conf/extra/httpd-mpm.conf修改396 Include conf/extra/httpd-vhosts.conf

==============================

[root@web02 conf]# cd extra/[root@web02 extra]# vim httpd-vhosts.conf 
    ServerAdmin oldboy@oldboyedu.com    DocumentRoot "/application/apache2.2.31/html/www"    ServerName www.etiantian.org    ServerAlias etiantian.org    ErrorLog "/app/logs/www-error_log"    CustomLog "/app/logs/www-access_log" common
    ServerAdmin oldboy@oldboyedu.com    DocumentRoot "/application/apache2.2.31/html/bbs"    ServerName bbs.etiantian.org    ErrorLog "/app/logs/bbs-error_log"    CustomLog "/app/logs/bbs-access_log" common
    ServerAdmin oldboy@oldboyedu.com    DocumentRoot "/application/apache2.2.31/html/blog"    ServerName blog.etiantian.org    ErrorLog "/app/logs/blog-error_log"    CustomLog "/app/logs/blog-access_log" common

6、创建站点目录及测试文件

mkdir -p /application/apache2.2.31/html/{www,bbs,blog}echo www.etiantian.org >/application/apache2.2.31/html/www/index.htmlecho bbs.etiantian.org >/application/apache2.2.31/html/bbs/index.htmlecho blog.etiantian.org >/application/apache2.2.31/html/blog/index.htmlmkdir /app/logs -p/etc/init.d/httpd graceful    (优雅重启)

7、配置客户端host解析到如下域名商,检查

curl www.etiantian.org                  curl bbs.etiantian.orgcurl blog.etiantian.org

apache基于域名的虚拟主机配置成功。

(二) 安装mysql(这里用二进制包)

1、安装mysql依赖包

yum -y install libaio*

2、下载mysql二进制安装包

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz

3、创建mysql用户

useradd mysql -s /sbin/nologin -M

4、解压并安装mysql

tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz   mv mysql-5.5.49-linux2.6-x86_64   /application/mysql-5.5.49ln -s /application/mysql-5.5.49/ /application/mysql /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql  (初始化mysql)chown -R mysql.mysql /application/mysql/cp /application/mysql/support-files/my-small.cnf  /etc/my.cnfcp /application/mysql-5.5.49/support-files/mysql.server  /etc/init.d/mysqldchkconfig --add mysqld  sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe  /etc/init.d/mysqld   (修改mysql启动脚本)/etc/init.d/mysqld start

5、配置环境变量

echo "PATH="/application/mysql/bin:$PATH"" >> /etc/profilesource /etc/profile

6、创建mysql密码

mysqladmin -uroot password '123456' mysqladmin -uroot -p'旧密码' password '新密码'   (修改)

7、启动mysql

/etc/init.d/mysqld start

(三) 安装PHP

1、安装php依赖包

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repoyum install zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel libmcrypt-devel mhash mhash-devel mcrypt openssl-devel -y mkdir -p /home/oldboy/toolscd /home/oldboy/tools wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gztar zxf libiconv-1.14.tar.gzcd libiconv-1.14./configure --prefix=/usr/local/libiconvmakemake installcd ..

2、安装php

wget http://mirrors.sohu.com/php/php-5.5.26.tar.gzcd /home/oldboy/toolstar xf php-5.5.26.tar.gzcd php-5.5.26./configure \--prefix=/application/php5.5.26 \--with-apxs2=/application/apache/bin/apxs \--with-mysql=mysqlnd \--with-iconv-dir=/usr/local/libiconv \--with-freetype-dir \--with-jpeg-dir \--with-png-dir \--with-zlib \--with-libxml-dir=/usr \--enable-xml \--disable-rpath \--enable-safe-mode \--enable-bcmath \--enable-shmop \--enable-sysvsem \--enable-inline-optimization \--with-curl \--with-curlwrappers \--enable-mbregex \--enable-mbstring \--with-mcrypt \--with-gd \--enable-gd-native-ttf \--with-openssl \--with-mhash \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-zip \--enable-soap \--enable-short-tags \--enable-zend-multibyte \--enable-static \--with-xsl \--enable-ftpmakemake installln -s /application/php5.5.26/ /application/php

3、检查结果

[root@web02 php-5.5.26]# ll /application/apache/modules/总用量 30568-rw-r--r-- 1 root root     9194 11月 10 20:37 httpd.exp-rwxr-xr-x 1 root root 31285631 11月 10 23:51 libphp5.so[root@web02 php-5.5.26]# grep libphp5.so /application/apache/conf/httpd.confLoadModule php5_module        modules/libphp5.so[root@web02 php-5.5.26]# cp php.ini-production /application/php/lib/php.ini

4、配置apache整合php(配置httpd.conf)

311行下增加:AddType application/x-httpd-php .php .phtmlAddType application/x-httpd-php-source .phps168行下增加:DirectoryIndex index.php index.html67行下增加User wwwGroup www

5、建立用户

useradd www -s /sbin/nologinid www /application/apache/bin/apachectl -tSyntax OK/application/apache/bin/apachectl graceful

6、检查php

7、检查mysql

LAMP搭建完成

(四)搭建wordpress

1、下载wordpress

wget  https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gztar xf wordpress-4.5.3-zh_CN.tar.gzmv wordpress/* /application/apache/html/blog/chown -R www.www /application/apache/html/blog/

2、创建wordpress数据库

mysql> create database wordpress; mysql> grant all on wordpress.* to wordpress@'172.16.1.%' identified by 'wordpress123'mysql> flush privileges;

3、修改hosts记录 

vi /etc/hosts                   (修改hosts记录将mysql指向本机)172.16.1.31 MysqlServer.com

4、访问并配置博客  

5、配置wordpress伪静态

(1)在WordPress后台-设置-固定链接-自定义结构,输入下面的代码,最后保存更改即可。        

/archives/%post_id%.html

(2)在虚拟主机增加权限控制(只需要允许blog站点被访问就可以了,不需要写rewrite)

[root@Oldboy extra]# tail -15 httpd-vhosts.conf 
    ServerAdmin oldboy@oldboyedu.com    DocumentRoot "/application/apache2.2.31/html/blog"    ServerName blog.etiantian.org    ErrorLog "/app/logs/blog-error_log"    CustomLog "/app/logs/blog-access_log" common        # 增加以下内容    
       Options Includes ExecCGI FollowSymLinks       AllowOverride All       Order allow,deny       Allow from all    

(3)查看效果