三、编译安装php-5.4.22
1、安装PHP所依赖的软件包
<1> RPM安装mcrypt
$ cd /usr/src/lamp
$ sudo wget ftp://ftp.muug.mb.ca/mirror/Fedora/epel/beta/6/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm
$ sudo wget http://www.gymglish.com/opensource/rpms/CentOS6-rpms/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
$ sudo rpm -ivh lib*
<2> Yum安装libxml和bzip2的devel包
$ sudo yum install libxml2-devel.x86_64
$ sudo yum install bzip2-devel.x86_64
2、编译安装php-5.4.22
$ cd /usr/src/lamp
$ sudo wget http://au1.php.net/distributions/php-5.4.22.tar.bz2
$ sudo tar xf php-5.4.22.tar.bz2
$ cd php-5.4.22
$ sudo ./configure --prefix=/usr/local/php --with-MySQL=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc/ --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
$ sudo make
$ sudo make install
为php提供配置文件:
$ sudo cp php.ini-production /etc/php.ini
3、编辑httpd配置文件,使其支持php及默认主页
$ sudo vim /etc/httpd/httpd.conf
# 添加以下内容:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# 修改以下内容:
DirectoryIndex index.php index.html
4、编辑httpd配置文件,新建虚拟主机
$ sudo vim /etc/httpd/httpd.conf
Include /etc/httpd/extra/vhosts.conf
1234567891011 $ sudo vim /etc/httpd/extra/vhosts.conf
<VirtualHost *:80>
DocumentRoot "/mydata/web"
ServerName cominggo.com
ServerAlias www.cominggo.com
<Directory "/mydata/web">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
5、重启httpd服务并测试
$ sudo servcie httpd configtest
$ sudo service httpd restart
四、安装PHP加速器XCache(可选)
1、编译安装xcache-3.0.4
$ cd /usr/src/lamp
$ sudo wget http://xcache.lighttpd.net/pub/Releases/3.0.4/xcache-3.0.4.tar.gz
$ sudo tar xf xcache-3.0.4.tar.gz
$ cd xcache-3.0.4
$ /usr/local/php/bin/phpize
$ sudo /usr/local/php/bin/phpize
$ sudo ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
$ sudo make
$ sudo make install
# 安装结果如下:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑xcache配置文件,整合PHP和XCache
$ sudo mkdir /etc/php.d
$ sudo cp xcache.ini /etc/php.d/
$ sudo vim /etc/php.d/xcache.ini
# 修改以下内容:
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注:xcache自3.0版本开始不再支持使用zend_extension加载xcache
3、重启httpd服务并测试
$ sudo service httpd restart
