安装完mysql,下面编译安装php-5.4.41
因为在编译php的时候需要用到--with-mcrypt的选项,该选项支持加密功能,然而此选项需要依赖以下几个rpm包生成的库文件,所以需要先安装如下包。
yum localinstall libmcrypt-2.5.7-5.el5.x86_64.rpm libmcrypt-devel-2.5.7-5.el5.x86_64.rpm mhash-0.9.2-6.el5.x86_64.rpm mhash-devel-0.9.2-6.el5.x86_64.rpm --nogpgcheck
接下来安装php
# tar xf php-5.4.41.tar.gz # cd php-5.4.41 # ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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 选项理解 --with-mysqli=/usr/local/mysql/bin/mysql_config 此选项表示通过另外的mysql接口和mysql通 信 --with-zlib 支持zlib压缩 --with-apxs2=/usr/local/apache/bin/apxs 此选项很重要,如果需要将php编译成httpd的模块的 话,此选项必加,如果要编译成fastcgi的话则需要添加--enable-fpm,两者不能同时添加 --enable-maintainer-zts 这里为了支持apache的worker或event这两个MPM,编译时使用了 --enable-maintainer-zts选项,如果是prefork则不需要此选项 make make install
为php提供配置文件:
# cp php.ini-production /etc/php.ini
编辑apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
让httpd能够识别php类型的文件
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
重新启动httpd
安装xcache,为php加速:xcache-3.2.0.tar.gz
# tar xf xcache-3.2.0.tar.gz # cd xcache-3.2.0 # /usr/local/php/bin/phpize 准备编译扩展 # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config # make && make install
编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
测试php
cd /usr/local/apache/htdocs/ mv index.html index.php vim index.php 添加 <?php phpinfo(); ?> 重启httpd,打开浏览器 测试php连接mysql vim index.php 添加内容 <?php $conn=mysql_connect(‘localhost‘,‘root‘,‘‘); if($conn) echo "success..."; else echo "failure..."; ?> 如果一切正常,浏览器应该显示success... 为httpd添加虚拟主机 vim /etc/httpd/httpd.conf 注释掉DocumentRoot 解注释 Include /etc/httpd/extra/httpd-vhosts.conf 编辑虚拟机文件 vim /etc/httpd/extra/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/www/a.org" <Directory "/www/a.org"> Options none AllowOverride none Require all granted #此选项要添加,否则目录不可访问 </Directory> ServerName www.a.org ErrorLog "/var/log/httpd/a.org-error_log" CustomLog "/var/log/httpd/a.org-access_log" combined </VirtualHost> <VirtualHost *:80> DocumentRoot "/www/b.net" <Directory "/www/b.net"> Options none AllowOverride none Require all granted </Directory> ServerName www.b.net ErrorLog "/var/log/httpd/b.net-error_log" CustomLog "/var/log/httpd/b.net-access_log" common </VirtualHost> 编辑宿主机hosts文件 添加解析 192.168.195.129 www.a.org 192.168.195.129 为2个虚拟机添加网页文件 echo "www.a.org" > /www/a.org/index.html echo "www.b.net" > /www/b.net/index.html 通过浏览器就可以正常访问