在生產環境中,Apache、MySQL、PHP通常都分別工作在不同的主機上,而且使用的是高可用叢集,以分擔單個伺服器的壓力,同時避免單點故障,所以,我今天向大家介紹的就是位於不同主機上的LAMP架構,使我們的操作更貼近生產環境

1、搭建前規劃

作業系統Centos6.4 x86_64位

Apache ——> 172.16.251.77 (static IP)
MySQL ——-> 172.16.251.78 (static IP)
PHP ———> 172.16.251.79 (static IP)

2、環境準備
(1)配置yum網路源;
# cd /etc/yum.repos.d/
# mkdir bak
# mv *.repo bak
# cd
# vim /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
[base]
name=CentOS-$releasever – Base
baseurl=http://172.16.0.1/cobbler/ks_mirror/centos-6.5-x86_64/
enable=1
gpgcheck=1
gpgkey=http://172.16.0.1/cobbler/ks_mirror/centos-6.5-x86_64/RPM-GPG-KEY-CentOS-6
cost=1000
[fedora-epel]
name=Fedora EPEL
baseurl=http://172.16.0.1/fedora-epel/6/x86_64/
enable=1
gpgcheck=0
cost=2000

(2)系統時間同步:最好的做法是新增定時任務,每隔一定時間同步一次
# crontab -e
*/5 * * * * /sbin/hwclock -s &>/dev/null
# crontab -l
*/5 * * * * /sbin/hwclock -s &>/dev/null
# hwclock -s

(3)關閉防火牆(iptables和selinux)
清除鏈規則:iptables -F
關閉selinux:setenforce 0
檢視selinux的狀態:getenforce

3、Apache端
(1)下載Apache相關原始碼包
[root@station123 ~]# mkdir tools  #建立一個目錄,用於存放原始碼包,方便管理
[root@station123 ~]# cd tools/
[root@station123 tools]# ls
apr-1.5.0.tar.bz2  apr-util-1.5.3.tar.bz2  httpd-2.4.9.tar.bz2
[root@station123 ~]# lftp 172.16.0.1/pub
lftp 172.16.0.1:/pub> cd Sources/sources/httpd/
lftp 172.16.0.1:/pub/Sources/sources/httpd> mget apr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2 httpd-2.4.9.tar.bz2
lftp 172.16.0.1:/> exit
(2)解除安裝系統自帶的lamp軟體包
rpm -e `rpm -q mysql` –nodeps &>/dev/null
rpm -e `rpm -q httpd` –nodeps  &>/dev/null

rpm -e `rpm -q php` –nodeps  &>/dev/null

(3)安裝編譯所需依賴包:
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel  krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libtermcap  libtermcap-devel  gcc gcc-c++
(4)編譯安裝apr(1.5.0版本)和apr-util(1.5.3版本)
[root@station123 tools]# tar xf apr-1.5.0.tar.bz2
[root@station123 tools]# cd apr-1.5.0
[root@station123 apr-1.5.0]# ./configure –prefix=/usr/local/apr
[root@station123 apr-1.5.0]# make && make install
[root@station123 apr-1.5.0]# cd ..
[root@station123 tools]# tar xf apr-util-1.5.3.tar.bz2
[root@station123 tools]# cd apr-util-1.5.3
[root@station123 apr-util-1.5.3]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/
[root@station123 apr-util-1.5.3]# make && make install
[root@station123 apr-util-1.5.3]# cd ..

(5)編譯安裝Apache(httpd 2.4.9版本)
[root@station123 tools]# tar xf httpd-2.4.9.tar.bz2
[root@station123 tools]# cd httpd-2.4.9
[root@station123 httpd-2.4.9]# ./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-pcre –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util/ –enable-modules=most –enable-mpms-shared=all –with-mpm=event
[root@station123 httpd-2.4.9]# make && make install

(6)修改httpd的主配置檔案,設定其Pid檔案的路徑
編輯/etc/httpd/httpd.conf,新增如下行即可:
PidFile  “/var/run/httpd.pid”

(7)將httpd新增為系統服務,可使用service啟動,並可使用chkconfig載入服務列表
[root@station123 ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@station123 ~]# vim /etc/init.d/httpd #新增如下兩行(在第3行新增即可)
# chkconfig: – 85 15
# description: Apache is a World Wide Web server.
[root@station123 ~]# chkconfig –add httpd
[root@station123 ~]# chkconfig –list httpd
httpd              0:off    1:off    2:off    3:off    4:off    5:off    6:off
[root@station123 ~]# chkconfig –level 35 httpd on
[root@station123 ~]# service httpd start
[root@station123 ~]# ss -tnl|grep “:80”
LISTEN     0      128                      :::80                      :::*
(8)匯出標頭檔案,庫檔案和apache man 幫助資訊
輸出apache的標頭檔案至系統標頭檔案路徑/usr/include:
這可以通過簡單的建立連結實現:
[root@station123 httpd-2.4.9]# ln -sv /usr/local/apache/include /usr/include/apache
`/usr/include/apache` -> `/usr/local/apache/include`

輸出apache的庫檔案給系統庫查詢路徑:(我沒看到),可先忽略它

[root@station123 ~]# ldconfig
匯出apache的man幫助資訊
[root@station123 ~]# vim /etc/man.config
MANPATH /usr/local/apache/man

測試httpd服務能否成功執行:
[root@station123 ~]# cd /usr/local/apache/htdocs #預設站點
[root@station123 htdocs]# ls
index.html
在瀏覽器輸入http://172.16.251.77/看是否會出現”It Works”字樣
我的在這裡是ok的,參考截圖httpd1-ok

至此,apache的配置告一段落

3、MySQL端:

(1)下載MySQL原始碼包

[root@station25 ~]# mkdir tools
[root@station25 ~]# cd tools/
[root@station25 tools]# lftp 172.16.0.1/pub/Sources
lftp 172.16.0.1:/pub> cd Sources/
lftp 172.16.0.1:/pub/Sources> cd 6.x86_64/
lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> get  mysql-5.5.33-linux2.6-x86_64.tar.gz
186839926 bytes transferred in 37 seconds (4.79M/s)                                       lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> exit

(2)建立執行mysql資料庫的系統使用者和系統組mysql
[root@station25 ~]# groupadd -r mysql
[root@station25 ~]# useradd -g mysql -r -s /sbin/nologin mysql

(3)編譯安裝mysql-5.5.33

[root@station25 tools]# tar xfz mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/src
[root@station25 tools]# cd /usr/src/
[root@station25 src]# mv mysql-5.5.33-linux2.6-x86_64/ /usr/local/
[root@station25 src]# cd $_
[root@station25 local]# ln -sv mysql-5.5.33 mysql
`mysql` -> `mysql-5.5.33`
[root@station25 local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  mysql-5.5.33  sbin  share  src

(4)為資料庫建立專門的資料存放目錄和儲存裝置

[root@station25 ~]# mkdir /data #建立資料存放目錄

[root@station25 ~]# fdisk /dev/sda  #建立磁碟分割槽
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7859-15665, default 7859):
Using default value 7859
Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +20G

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.

echo -n -e “n
p
3

+20G
t
3
8e
w
” |fdisk /de/sda

執行操作1和操作2,以便新增磁碟分割槽可以系統快速識別

[root@station25 ~]# kpartx -af /dev/sda 操作1

device-mapper: reload ioctl on sda1 failed: Invalid argument
create/reload failed on sda1
device-mapper: reload ioctl on sda2 failed: Invalid argument
create/reload failed on sda2
device-mapper: reload ioctl on sda3 failed: Invalid argument
create/reload failed on sda3
[root@station25 ~]# partx -a /dev/sda 操作2

BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2

檢視新增的磁碟分割槽是否被系統識別

[root@station25 ~]# cat /proc/partitions
major minor  #blocks  name

  8        0  125829120 sda
  8        1     204800 sda1
  8        2   62914560 sda2
  8        3   20979891 sda3  #sda3是我們剛才劃分的,說明該分割槽此時已被系統識別
253        0   20971520 dm-0
253        1    2097152 dm-1
253        2   10485760 dm-2
253        3   20971520 dm-3

建立lvm卷,以應對資料庫的快速增長

[root@station25 ~]# pvcreate /dev/sda3
 Physical volume “/dev/sda3” successfully created
[root@station25 ~]# vgcreate myvg /dev/sda3
 Volume group “myvg” successfully created
[root@station25 ~]# lvcreate -L 10G -n mydata myvg
Logical volume “mydata” created
檢視系統當前的具有所有的lvs屬性的邏輯卷
[root@station25 ~]# lvs
 LV     VG   Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
 mydata myvg -wi-a—- 10.00g                                            
 root   vg0  -wi-ao— 20.00g                                            
 swap   vg0  -wi-ao—  2.00g                                            
 usr    vg0  -wi-ao— 10.00g                                            
 var    vg0  -wi-ao— 20.00g  

格式化邏輯卷
[root@station25 ~]# mke2fs -t ext4 /dev/myvg/mydata

設定開機自動掛載
[root@station25 ~]# vim /etc/fstab
/dev/myvg/mydata        /data                   ext4    defaults,noatime 0 0

掛載/etc/fstab檔案中所有支援自動掛載的檔案系統/磁碟分割槽

[root@station25 ~]# mount -a
驗證lvm裝置是否掛載成功
[root@station25 ~]# mount|grep “/data”
/dev/mapper/myvg-mydata on /data type ext4 (rw,noatime)
[root@station25 ~]# cd /data/
[root@station25 data]# mkdir mydata
[root@station25 data]# chown -R mysql.mysql mydata/
[root@station25 data]# ll
total 20
drwx—— 2 root  root  16384 Mar 22 15:51 lost+found
drwxr-xr-x 2 mysql mysql  4096 Mar 22 15:55 mydata

初始化mysql
[root@station25 data]# cd /usr/local/mysql
[root@station25 mysql]# chown -R root.mysql ./*
[root@station25 local]# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql
[root@station25 local]# cd mysql
[root@station25 mysql]# scripts/mysql_install_db –datadir=/data/mydata/ –user=mysql

[root@station25 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@station25 mysql]# chkconfig –add mysqld
[root@station25 mysql]# chkconfig –list mysqld
mysqld             0:off    1:off    2:on    3:on    4:on    5:on    6:off

[root@station25 mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf`? y
[root@station25 mysql]# vim /etc/my.cnf
在[mysqld]自段下面新增
datadir = /data/mydata
並將thread_concurrency修改為CPU個數的2倍
thread_concurrency = 4

[root@station25 mysql]# service mysqld start
Starting MySQL…….                                      [  OK  ]
[root@station25 mysql]# ls /tmp/
ks-script-n4bQu7  ks-script-n4bQu7.log  mysql.sock  yum.log

將mysql命令新增至系統PATH變數
[root@station25 mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@station25 mysql]# . $_

[root@station25 mysql]# mysql
mysql> select user,host,password from mysql.user;
+——+————————-+———-+
| user | host                    | password |
+——+————————-+———-+
| root | localhost               |          |
| root | station25.magelinux.com |          |
| root | 127.0.0.1               |          |
| root | ::1                     |          |
|      | localhost               |          |
|      | station25.magelinux.com |          |
+——+————————-+———-+
6 rows in set (0.01 sec)

mysql> use mysql
Database changed
mysql> update user set password=PASSWORD(`123456`) where user=`root`;
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> drop user “@`localhost`;
Query OK, 0 rows affected (0.00 sec)
mysql> drop user “@`station25.magelinux.com`;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye

[root@station25 ~]# vim .my.cnf
[mysql]
user = root
host = localhost
password = 123456

匯出標頭檔案,且/usr/include/mysql不能寫成/usr/include/mysql/這樣的形式
[root@station25 ~]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql` -> `/usr/local/mysql/include/`

[root@station25 ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@station25 ~]# ldconfig -p|grep mysql
   libtcmalloc_minimal.so.0 (libc6,x86-64) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0
   libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r.so.16
   libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
   libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.16
   libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so

4、PHP端:
[root@station79 ~]# yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel  krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libtermcap  libtermcap-devel  gcc gcc-c++
[root@station79 ~]# mkdir tools
[root@station79 ~]# cd tools/
[root@station79 tools]# lftp 172.16.0.1/pub/Sources/sources
cd ok, cwd=/pub                            
lftp 172.16.0.1:/pub/Sources/sources> cd php/
lftp 172.16.0.1:/pub/Sources/sources/php> mget php-5.4.26.tar.bz2 phpMyAdmin-4.0.5-all-languages.zip  xcache-3.0.3.tar.bz2
lftp 172.16.0.1:/pub/Sources/sources/php> exit

[root@station79 tools]# tar xf php-5.4.26.tar.bz2
[root@station79 tools]# cd php-5.4.26
[root@station79 php-5.4.26]# ./configure –prefix=/usr/local/php  –with-openssl  –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml  –enable-sockets  –with-mcrypt  –with-config-file-path=/etc  –with-config-file-scan-dir=/etc/php.d –with-bz2  –enable-maintainer-zts –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –enable-fpm
[root@station79 php-5.4.26]# make && make install

[root@station79 php-5.4.26]# cp php.ini-production /etc/php.ini
[root@station79 php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@station79 php-5.4.26]# chmod +x /etc/init.d/php-fpm
[root@station79 php-5.4.26]# chkconfig –add php-fpm
[root@station79 php-5.4.26]# chkconfig php-fpm on
[root@station79 php-5.4.26]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
編輯php-fpm的配置檔案:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相關選項為你所需要的值,並啟用pid檔案(如下最後一行):
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid

說明:pid這裡原本是一個相對路徑,而且和我們編譯安裝的位置不一樣,所以需要修改,但是,若你在編譯php的時候,若沒有指定pid檔案的存放路徑,那你怎麼知道pid檔案在哪呢?
方法:grep pid /etc/init.d/php-fpm
php_fpm_PID=${prefix}/var/run/php-fpm.pid
其他無效資訊已省略…
${prefix}指的是php編譯安裝的路徑,即為/usr/local/php

啟動php-fpm
[root@station79 php-5.4.26]# service php-fpm start
Starting php-fpm  done

使用如下命令來驗正(如果此命令輸出有中幾個php-fpm程式就說明啟動成功了):
[root@station79 php-5.4.26]# ps aux|grep “php-fpm”|grep -v “grep”
root      4278  0.0  0.4  69468  4604 ?        Ss   17:13   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)                                                                    
nobody    4279  0.0  0.3  69468  3932 ?        S    17:13   0:00 php-fpm: pool www                                                                                                            
nobody    4280  0.0  0.3  69468  3936 ?        S    17:13   0:00 php-fpm: pool www                                                                                                            
nobody    4281  0.0  0.3  69468  3936 ?        S    17:13   0:00 php-fpm: pool www                                                                                                            
nobody    4282  0.0  0.3  69468  3936 ?        S    17:13   0:00 php-fpm: pool www                                                                                                            
nobody    4283  0.0  0.3  69468  3936 ?        S    17:13   0:00 php-fpm: pool www  

預設情況下,fpm監聽在127.0.0.1的9000埠,也可以使用如下命令驗正其是否已經監聽在相應的套接字
[root@station79 php-5.4.26]# ss -tnl|grep “:9000”
LISTEN     0      128               127.0.0.1:9000                     *:*    

######################Starting##############################
Apache 77
建立站點目錄及測試頁
# mkdir -p /web/{a.com,b.org}/htdocs
[root@station123 ~]# cd /etc/httpd/extra/
[root@station123 extra]# vim httpd-vhosts.conf
[root@station123 extra]# service httpd graceful
[root@station123 extra]# ss -tnl|grep “:80” |grep -v “grep”
LISTEN     0      128                      :::80                      :::*    
[root@station123 extra]# /etc/init.d/httpd -M  #檢視已被編譯安裝的模組
Loaded Modules:  #主要是為了看proxy_module (shared),proxy_fcgi_module (shared)是否編譯進去
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
proxy_module (shared)    
proxy_fcgi_module (shared)
mpm_event_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)

[root@station123 extra]# cd ..
[root@station123 httpd]# ls
conf.d  extra  httpd.conf  magic  mime.types  original

主配置檔案相關的操作:
[root@station123 httpd]# vim httpd.conf
# 在httpd主配置檔案中將中心主機用”#”註釋掉,操作如下行:
#DocumentRoot “/usr/local/apache/htdocs”

# 在預設首頁位置新增index.php,這樣,伺服器被訪問的時候,就會先找到index.php,若該檔案存在,就停止查詢;若該檔案不存在,就會繼續向右查詢,以此類推
<IfModule dir_module>
   DirectoryIndex  index.php  index.html
</IfModule>

# 因為在後面我要在/etc/httpd/extra/httpd-vhosts.conf中,即在擴充套件配置檔案中定義虛擬主機,所以
需要開啟Virtual hosts的功能,操作如下2行:
# Virtual hosts 此行是註釋不用理會
Include /etc/httpd/extra/httpd-vhosts.conf  #此行預設是被註釋掉的,要啟用它,需將行首的#去掉

新增如下兩行:
AddType application/x-httpd-php  .php
AddType application/x-httpd-php-source  .phps
作用:

#若proxy_module和proxy_fcgi_module模組已成功編譯進httpd,那麼在主配置檔案中就會有下面這樣兩行,
#不過,這兩行預設都未被啟用,若想啟用,將這兩行行首的註釋去掉
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

擴充套件配置檔案相關的操作:
[root@station123 httpd]# cd extra
[root@station123 extra]# vim httpd-vhosts.conf
<VirtualHost *:80>
   ServerAdmin webadmin@a.com
   DocumentRoot “/web/a.com/htdocs”
   ServerName www.a.com
   ServerAlias a.com
   ErrorLog “logs/a.com-error_log”
   CustomLog “logs/a.com-access_log” combined
       <Directory “/web/a.com/htdocs”>
               Options None
               Require all granted
       </Directory>
   ProxyRequests Off
   ProxyPassMatch ^/(.*.php)$ fcgi://172.16.251.79:9000/web/a.com/htdocs/$1
</VirtualHost>

<VirtualHost *:80>
   ServerAdmin webadmin@b.org
   DocumentRoot “/web/b.org/htdocs”
   ServerName www.b.org
   ServerAlias b.org
   ErrorLog “logs/b.org-error_log”
   CustomLog “logs/b.org-access_log” combined
       <Directory “/web/b.org/htdocs”>
               Options None
               Require all granted
       </Directory>
   ProxyRequests Off
   ProxyPassMatch ^/(.*.php)$ fcgi://172.16.251.79:9000/web/b.org/htdocs/$1
</VirtualHost>

向Apache端/etc/hosts檔案中新增域名解析
172.16.251.77 www.a.com a.com  www.b.org b.org

因為我們待會要通過宿主機的瀏覽器,使用域名來訪問我們的站點,所以我們也需要修改宿主機的hosts檔案,以便支援域名解析功能,(若有DNS就更好了)
路徑:C:WindowsSystem32driversetc
新增如下行
172.16.251.77 www.a.com www.b.org www.c.com www.d.org
有時候,宿主機上的防火牆可能會阻止我們修改此檔案,暫時關閉宿主機上的防火牆即可

78 MySQL端,此時不用進行其他的配置
79 PHP端,配置如下:
[root@station79 ~]# vim /usr/local/php/etc/php-fpm.conf
# 修改監聽的地址為PHP所在伺服器IP,埠不變,預設是監聽127.0.0.1:9000
listen = 172.16.251.79:9000

啟動php-fpm服務
[root@station79 php-5.4.26]# service php-fpm restart
Gracefully shutting down php-fpm warning, no pid file found – php-fpm is not running ?
Starting php-fpm  done

檢視監聽的地址是否為本機IP(172.16.251.79),且埠為9000
[root@station79 php-5.4.26]# ss -tnl|grep “:9000”
LISTEN     0      128           172.16.251.79:9000              

建立站點目錄
[root@station79 php-5.4.26]# mkdir -p /web/{a.com,b.org}/htdocs
[root@station79 php-5.4.26]# cd
[root@station79 ~]# vim /web/a.com/htdocs/index.php
Wecome to www.a.com
<?php
   phpinfo();
?>

[root@station79 ~]# vim /web/b.org/htdocs/index.php
Wecome to www.b.org
<?php
   phpinfo();
?>

新增完測試頁後,其實不需要重啟php-fpm服務的

檢視php-fpm指令碼都支援哪些選項
[root@station79 htdocs]# service php-fpm
Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status}

啟動php-fpm服務
[root@station79 php-5.4.26]# service php-fpm reload

至此,所有配置工作已完成

現在,我們可通過宿主機的瀏覽器來訪問剛剛我們新建的站點了
www.a.com/ 或 a.com
www.b.org 或 b.org
都可訪問相應的站點
結果我已儲存成網頁,可供大家檢視

   到目前為止,位於不同主機上的LAMP架構已搭建完畢,不過由於時間有限,我只能先介紹到這裡,稍後,我會在此文的基礎上繼續為大家演示如何使用php加速外掛,提高訪問速度,以及LAMP架構的優化,使我們的站點逐漸健壯起來。

   歉意:此文,尚未仔細排版,有些粗糙,還請各位博友多多包涵,稍後我會對此文重新排版釋出的….

下面我將為php程式安裝一個加速外掛,並使之生效

[root@station79 ~]# cd tools/
[root@station79 tools]# tar xf xcache-3.0.3.tar.bz2

[root@station79 tools]# cd xcache-3.0.3

[root@station79 xcache-3.0.3]#  /usr/local/php/bin/phpize

[root@station79 xcache-3.0.3]# ./configure –enable-xcache –with-php-config=/usr/local/php/bin/php-config

[root@station79 xcache-3.0.3]# make && make install

安裝結束時,會出現類似如下行:
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

編輯php.ini,整合php和xcache:
首先將xcache提供的樣例配置匯入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
說明:xcache.ini檔案在xcache的原始碼目錄中。

接下來編輯/etc/php.d/xcache.ini

早期的xcache版本,找到zend_extension開頭的行,修改為如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

xcache 3.0.3版本,操作如下:

[xcache-common]
;; non-Windows example:
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
;; Windows example:
; extension = php_xcache.dll

注意:如果php.ini檔案中有多條zend_extension(早期版本)或extension(新版本)指令行,要確保此新增的行排在第一位。

儲存退出,並重啟service php-fpm restart

訪問測試已ok