一步一步源碼編譯最新版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

經過瀏覽器就能夠正常訪問
相關文章
相關標籤/搜索