准备两台服务器,一台安装Apache,一台安装mysql

 

安装Apache

1、下载安装

yum install zlib-devel -ywgethttp://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gztar xf httpd-2.2.31.tar.gzcd 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/

2、启动服务

/application/apache/bin/apachectl startnetstat -lntup|grep httpd

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

cd /application/apache/conf/vim httpd.conf 修改98,132,378,396行98 ServerName 127.0.0.1:80132 
378 Include conf/extra/httpd-mpm.conf396 Include conf/extra/httpd-vhosts.conf  cd /application/apache/conf/extraextra/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  cd /application/apache/conf/extramkdir -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

检查语法

/application/apache/bin/apachectl -tSyntax OK/application/apache/bin/apachectl graceful

 

验证之前在/etc/hosts要有解析

验证:

curl www.etiantian.org                 

www.etiantian.org

curl bbs.etiantian.org

bbs.etiantian.org

curl blog.etiantian.org

blog.etiantian.org

本机不安装mysqlmysql服务器独立存在 

安装php 

1)安装依赖包

wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repoyum install zlib-devel libxml2-devellibjpeg-devel libiconv-devel -yyum install freetype-devel libpng-develgd-devel curl-devel libxslt-devel -y rpm -qa freetype-devellibjpeg-turbo-devel  libcurl-devel  libpng-devel gd-devel libxslt-devel 查看结果:freetype-devel-2.3.11-15.el6_6.1.x86_64gd-devel-2.0.35-11.el6.x86_64libpng-devel-1.2.49-1.el6_2.x86_64libcurl-devel-7.19.7-46.el6.x86_64libxslt-devel-1.1.26-2.el6_3.1.x86_64libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64

源码包里没有下面的包:

libiconv-devel

安装libiconv-devel

mkdir -p /home/oldboy/toolscd /home/oldboy/toolswget 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/libiconvmake    make installcd ../

安装libmcrypt

yum install libmcrypt-devel -yrpm -qa libmcrypt-devel             libmcrypt-devel-2.5.8-9.el6.x86_64

安装mhash

yum -y install mhash mhash-develrpm -qa mhash mhash-develmhash-0.9.9.9-3.el6.x86_64mhash-devel-0.9.9.9-3.el6.x86_64

安装mcrypt加密扩展库

yum -y install mcrypt mcrypt-develrpm -qa mcrypt mcrypt-2.6.8-10.el6.x86_64

正式安装php

rz -y上传软件包

tar zxf php-5.3.27.tar.gzcd php-5.3.27./configure \--prefix=/application/php5.3.27 \--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-ftp makemake installln -s /application/php5.3.27//application/php

 

cd /application/apache/conf/

配置:

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

建立用户:

useradd -s /sbin/nologin www

id www

/application/apache/bin/apachectl -tSyntax OK/application/apache/bin/apachectl graceful

 

站点目录

cd /application/apache/html/blog

建立两个测试文件

vim test1.php

第二个测试文件要等mysql安装好了,才能出结果

vim test2.php

vim /etc/hosts

172.16.1.51 db01.etiantian.org

检测:

ping db01.etiantian.org

检查语法

/application/apache/bin/apachectl -t

启动服务

/application/apache/bin/apachectl start

重新加载

/application/apache/bin/apachectl graceful

 

 

二、安装MySQL数据库

 

使用mysql-5.5.32二进制包安装

1、添加用户

useradd mysql -s /sbin/nologin -M

2、解包处理

tar xf mysql-5.5.32-linux2.6-x86_64.tar.gzmv mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32

创建软链接

ln -s /application/mysql-5.5.32/ /application/mysql

3、初始化数据库

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

初始化的结果是生成文件

ll /application/mysql/data/total 12drwx------ 2 mysql root  4096 Nov 11 02:59 mysqldrwx------ 2 mysql mysql 4096 Nov 11 02:59performance_schemadrwxr-xr-x 2 mysql root  4096 Nov 11 02:53 test

初始化后要授权:

chown -R mysql.mysql /application/mysql/

4、启动数据库 

\cp /application/mysql/support-files/my-small.cnf  /etc/my.cnfsed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe\cp /application/mysql/support-files/mysql.server /etc/init.d/mysqldsed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld

启动mysql服务

/etc/init.d/mysqld  startStarting MySQL SUCCESS!

MySQL的路径

PATH路径

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

进入MySQL

mysql

 

5.管理数据库

设置新密码

mysqladmin -uroot passwordNew password:   此处输入密码Confirm new password: 重复上面的密码

登录数据库

mysql -uroot -pEnter password:创建数据库mysql> create database wordpress;Query OK, 1 row affected (0.07 sec)授权mysql> grant all on wordpress.* to wordpress@'localhost'identified by '123456';Query OK, 0 rows affected (0.07 sec)刷新mysql> flush privileges;Query OK, 0 rows affected (0.05 sec) mysql> show grants for wordpress@'localhost';      +------------------------------------------------------------------------------------------------------------------+| Grants for wordpress@localhost                                                                                  |+------------------------------------------------------------------------------------------------------------------+| GRANT USAGE ON *.* TO 'wordpress'@'localhost'IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' || GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'localhost'                                                |+------------------------------------------------------------------------------------------------------------------+2 rows in set (0.06 sec) mysql> select user,host from mysql.user whereuser='wordpress';+-----------+-----------+| user      |host      |+-----------+-----------+| wordpress | localhost |+-----------+-----------+1 row in set (0.00 sec)  mysql> select user,host from mysql.user;+-----------+-----------+| user      | host     |+-----------+-----------+| root      |127.0.0.1 || root      |localhost || wordpress | localhost || root      |web01     |+-----------+-----------+4 rows in set (0.00 sec)

切换到站点目录:

cd /application/apache/html/blog/rz -ytar xf wordpress-4.2.2-zh_CN.tar.gzmv blog/* .cd ../chown -R www.www blog/

在本机hosts做解析后,浏览器访问以下地址,按要求下一步。

blog.etiantian.org/wp-admin/setup-config.php