一步一步源码编译最新版LAMP平台(三)

安装完mysql,下面编译安装php-5.4.41php

由于在编译php的时候须要用到--with-mcrypt的选项,该选项支持加密功能,然而此选项须要依赖如下几个rpm包生成的库文件,因此须要先安装以下包。html

wKioL1VqZSCili7ZAADs1PYj7QM228.jpg

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 --nogpgcheckmysql


接下来安装phpsql

# 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.iniapache


编辑apache配置文件httpd.conf,以apache支持phpvim

 # vim /etc/httpd/httpd.conf
 一、添加以下二行
   AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps浏览器

  让httpd可以识别php类型的文件

 二、定位至DirectoryIndex index.html
   修改成:
    DirectoryIndex  index.php  index.htmlbash

从新启动httpdapp


安装xcache,为php加速:xcache-3.2.0.tar.gzsocket

# 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

经过浏览器就能够正常访问
相关文章
相关标签/搜索