在生产环境中,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\np\n3\n\n+20G\nt\n3\n8e\n\w\n" |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:\Windows\System32\drivers\etc
添加如下行
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
免责声明:
1. 本站所有资源来自网络搜集或用户上传,仅作为参考不担保其准确性!
2. 本站内容仅供学习和交流使用,版权归原作者所有!© 查看更多
3. 如有内容侵害到您,请联系我们尽快删除,邮箱:kf@codeae.com