(一)安装Apache
1、下载安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
yum install zlib-devel -y
wget http: //mirror .bit.edu.cn /apache/httpd/httpd-2 .2.31. tar .gz
tar 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 -rewrite
make make install
ln -s /application/apache2 .2.31/ /application/apache
ls -l /application/
|
2、启动服务,检查
1
2
|
/application/apache/bin/apachectl start
netstat -lntup| grep httpd
|
3、配置基于域名的虚拟主机
1
2
3
4
5
6
7
8
9
|
cd /application/apache/conf/
vim httpd.conf 修改98行 ServerName 127.0.0.1:80 修改132 <Directory "/application/apache2.2.31/html" >
修改378 Include conf /extra/httpd-mpm .conf
修改396 Include conf /extra/httpd-vhosts .conf
|
==============================
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
[root@web02 conf] # cd extra/
[root@web02 extra] # vim httpd-vhosts.conf
<VirtualHost *:80> 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
< /VirtualHost >
<VirtualHost *:80> 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
< /VirtualHost >
<VirtualHost *:80> 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
< /VirtualHost >
|
创建站点目录及测试文件
1
2
3
4
5
6
7
|
mkdir -p /application/apache2 .2.31 /html/ {www,bbs,blog}
echo www.etiantian.org > /application/apache2 .2.31 /html/www/index .html
echo bbs.etiantian.org > /application/apache2 .2.31 /html/bbs/index .html
echo blog.etiantian.org > /application/apache2 .2.31 /html/blog/index .html
mkdir /app/logs -p
/application/apache/bin/apachectl -t
/application/apache/bin/apachectl graceful
|
4、配置客户端host解析到如下域名商,检查
1
2
3
|
curl www.etiantian.org curl bbs.etiantian.org curl blog.etiantian.org |
apache基于域名的虚拟主机配置成功。
==============================================
(二)搭建PHP,本地不装MYSQL
1、安装依赖包并检查
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
wget -O /etc/yum .repos.d /epel .repo http: //mirrors .aliyun.com /repo/epel-6 .repo
yum 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
rpm -qa zlib-devel libxml2-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash mhash-devel mcrypt openssl-devel mkdir -p /home/oldboy/tools
cd /home/oldboy/tools
wget http: //ftp .gnu.org /pub/gnu/libiconv/libiconv-1 .14. tar .gz
tar zxf libiconv-1.14. tar .gz
cd libiconv-1.14
. /configure --prefix= /usr/local/libiconv
make make install
cd ..
|
2、安装php(无需安装MySQL)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
cd /home/oldboy/tools
tar xf php-5.5.26. tar .gz
cd 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 - ftp
make make install
ln -s /application/php5 .5.26/ /application/php
|
检查结果:
1
2
3
4
5
6
7
|
[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.conf
LoadModule php5_module modules /libphp5 .so
[root@web02 php-5.5.26] # cp php.ini-production /application/php/lib/php.ini
|
3、配置httpd.conf
1
2
3
4
5
6
7
8
|
311行下增加: AddType application /x-httpd-php .php .phtml
AddType application /x-httpd-php-source .phps
168行下增加: DirectoryIndex index.php index.html 67行下增加 User www Group www |
建立用户:
1
2
3
4
5
|
useradd -u 513 -s /sbin/nologin www
id www
/application/apache/bin/apachectl -t
/application/apache/bin/apachectl graceful
|
检查PHP:
1
2
3
|
<?php phpinfo(); ?> |
检查MySQL:
1
2
3
4
5
6
7
8
9
|
<?php $link_id=mysql_connect( 'db01.etiantian.org' , 'wordpress' , '123456' ) or mysql_error();
if ($link_id){
echo "mysql successful by oldboy training!" ;
}
else {
echo mysql_error();
}
?> |
LAMP搭建完成。
搭建博客产品略,见图: