編譯安裝PHP5.4.41

 

一、部署LAMP環境,安裝順序

二、編譯、安裝php

三、安裝xcache,爲php(opcode)加速

四、其他

 

一、部署LAMP環境,安裝順序

 

編譯安裝部署LAMP環境,安裝順序

1、編譯安裝apache,http://64314491.blog.51cto.com/2784219/1652948

2、編譯安裝mysql,http://64314491.blog.51cto.com/2784219/1652999

3、編譯安裝php

 

二、編譯、安裝php

 

1、下載php並解壓

[root@localhost downloads]# wget http://cn2.php.net/distributions/php-5.4.41.tar.bz2
[root@localhost downloads]# tar xf php-5.4.41.tar.bz2

 

2、編譯前準備工作

(1)、編譯選項

./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

 

(2)、直接編譯,會有如下提醒,所以需提前準備

1、configure: error: xml2-config not found. Please check your libxml2 installation.
2、configure: error: Please reinstall the BZip2 distribution
3、configure: error: mcrypt.h not found. Please reinstall libmcrypt.
4、configure: error: Cannot find MySQL header files under /usr/local/mysql.    #這個問題就需要先安裝mysql後,再來編譯php了,所以最好按照步驟apache-->mysql-->php

所以編譯前需要安裝依賴環境

1、# yum -y  install libxml2 libxml2-devel
2、# yum -y  install bzip2-devel

下載libmcrypt libmcrypt-devel,並安裝
# wget http://mirrors.sohu.com/fedora-epel/6Server/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm
# wget http://mirrors.sohu.com/fedora-epel/6Server/x86_64/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
3、# rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpm 
   # rpm -ivh libmcrypt-devel-2.5.8-9.el6.x86_64.rpm

 

3、編譯、安裝php

# ./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
# make && make install

注:--enable-maintainer-zts    編譯模塊worker、event時,需要使用該選項

 

4、編輯/etc/httpd/httpd.conf

(1)、在AddType application/x-gzip .gz .tgz後添加以下信息,使httpd識別php格式的頁面

ADDType application/x-httpd-php .php
ADDType application/x-httpd-php-source .phps

 

(2)、添加默認起始頁文件名

DirectoryIndex index.php

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

完成配置後,重載配置

[root@localhost ~]# service httpd graceful

 

(3)、爲php提供配置文件,在我們解壓出的源碼目錄中,有兩個配置文件樣例

[root@localhost ~]# cd /root/downloads/php-5.4.41
[root@localhost php-5.4.41]# ls |grep php.ini
php.ini-development    #適用於開發環境
php.ini-production    #適用於生產環境

編譯安裝時,我們指定了php的配置文件目錄/etc,這裏我們把適用於生產環境的配置文件複製過去

[root@localhost php-5.4.41]# cp php.ini-production /etc/php.ini

 

(4)、測試

之前編譯安裝的apache,配置文件中,默認網站根目錄是DocumentRoot "/usr/local/apache/htdocs"  
在該路徑新建一個測試頁面index.php,內容如下

<h1>host1</h1>
<?php
        phpinfo();
?>

在瀏覽器輸入主機地址測試,出現下圖所示,說明安裝、配置成功

image

 

(5)、測試連接mysql

 /usr/local/apache/htdocs在該路徑新建一個測試頁面pcmysql.php,內容如下

<h1>host1</h1>
<?php
        $link=mysql_connect(localhost,root,'password');    #注意之前給mysql的root用戶改過密碼執行函數返回值mysql_connect(localhost,"root",)存儲在變量$link中
        if ($link)
                echo "Sueccess.";
        else
                echo "Failure.";
?>

然後用瀏覽器訪問這個頁面,顯示如下信息則說明php成功連接mysql

wKioL1VYwB7z3y6TAAASSTnwtyo345.jpg


三、安裝xcache,爲php(opcode)加速

1、下載xcache

wget http://xcache.lighttpd.net/pub/Releases/3.1.2/xcache-3.1.2.tar.gz

 

2、爲php添加xcache

[root@localhost downloads]# tar xf xcache-3.1.2.tar.gz 
[root@localhost downloads]# cd xcache-3.1.2
[root@localhost xcache-3.1.2]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525

 

3、編譯安裝xcache

[root@localhost xcache-3.1.2]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[root@localhost xcache-3.1.2]# make && make install

安裝完成,提示模塊安裝的位置

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

 

4、將xcache配置文件複製到php配置文件目錄

[root@localhost xcache-3.1.2]# mkdir /etc/php.d
[root@localhost xcache-3.1.2]# cp xcache.ini /etc/php.d
[root@localhost xcache-3.1.2]# vim /etc/php.d/xcache.ini
[root@localhost xcache-3.1.2]# service httpd graceful    #重載配置

新建測試頁面,在瀏覽器中訪問測試頁面,顯示如下畫面,說明模塊正常加載

vim /usr/local/apache/htdocs/test.php
編輯如下內容
<?php
        phpinfo();
?>

 

image

image    #配置文件已經載入

 

如果xcache沒有正常工作,試試編輯xcache.ini,編輯extension = xcache.so,修改爲全路徑

extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

 

 

四、其他

 

配置文件/etc/php.ini,/etc/php.d/目錄下的*.ini

php.ini官方文檔:

配置參數:http://www.php.net/manual/zh/ini.list.php  
核心配置參數詳解:http://www.php.net/manual/zh/ini.core.php

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章