centos6.5源碼安裝php5.6.9

來源:互聯網
上載者:User

centos6.5源碼安裝php5.6.9

  • 下載php5.6.9包並解壓

[root@localhost ~]# wgethttp://cn2.php.net/distributions/php-5.6.9.tar.bz2

[root@localhost ~]# tar xf php-5.6.9.tar.bz2

  • 編譯安裝

我的編譯選項如下

--prefix=/usr/local/php:定義安裝的路徑

--with-mysql=/usr/local/mysql :指定mysql安裝目錄

--with-mysqli=/usr/local/mysql/bin/mysql_config

--with-openssl:Include OpenSSL support (requires OpenSSL >= 0.9.6)

--enable-mbstring :允許多位元組的字串支援,這樣可支援中文等字型

--with-freetype-dir: Set the path to FreeType 2 install prefix

--with-jpeg-dir :GD: Set the path to libjpeg install prefix

--with-png-dir :GD: Set the path to libpng install prefix

--with-zlib :--with-zlib=DIR Include ZLIB support (requires zlib >= 1.0.9)

--with-libxml-dir=/usr :得先安裝libxml2

--enable-xml :支援擴充標記語言

--enable-sockets :支援sockets

--with-apxs2=/usr/local/apache/bin/apxs :構建動態模組2.0支援支援,這裡意味著在你的/etc/httpd/httpd.conf中.,如果希望使用fastcgi那麼請替換為enable-fpm

--with-mcrypt :提供加密支援

--with-config-file-path=/etc :在/etc目錄下組建組態檔案/etc/php.ini

--with-config-file-scan-dir=/etc/php.d :在/etc/php.d目錄下有分設定檔

--with-bz2 :支援bz2壓縮

--enable-maintainer-zts:支援線程的模組,如果使用prefork請不要加入該選項,可通過命令httpd V顯示當前載入的模組

[root@localhost php-5.6.9]#./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

由於軟體太多,所以先編譯一下試試

  • 謝天謝地,只報了一個錯誤,有的錯誤可以參閱http://www.jb51.net/article/37487.htm這位大哥寫的文章

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

下載libmcrypt,yum初始源裡面並沒有,所以去別處下載

下載這四個包並安裝,如果不想下載,請自己更新163或其他源,親測http://jingyan.baidu.com/article/d2b1d1027b76c75c7e37d4d0.html可以,更新挺久的,2h左右,最後我的可以yum找到這幾個包了,如果不想更新源,請按照下面步驟

[root@localhost ~]# wget {ftp://rpmfind.net/linux/epel/6/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm,ftp://rpmfind.net/linux/epel/6/x86_64/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm}

[root@localhost ~]# wget {ftp://rpmfind.net/linux/epel/6/x86_64/mhash-devel-0.9.9.9-3.el6.x86_64.rpm,ftp://rpmfind.net/linux/epel/6/x86_64/mhash-0.9.9.9-3.el6.x86_64.rpm}

中間可能會有說NOKEY,被我忽略了

再重新編譯下試試,如果最後幾行是create….就是成功了

[root@localhost php-5.6.9]# make&&make install

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

  • 解決與httpd的聯絡,如果啟動不了,請把自己的防火牆和selinux關掉哦

    a)在指定行添加 AddType application/x-httpd-php .php .phtml

    b)在指定行修改 DirectoryIndex index.html index.php

  • 測試php是否正常運行

    修改網頁首頁為Index.php,把之前的index.html備份或者刪除

    [root@localhost htdocs]# cat index.php

    <html>

    <body>

    <h1>it works!</h1>

    </body>

    </html>

    <?php

    phpinfo();

    ?>

    具體我不了,很多之前編譯載入的模組被enabled,可以使用

  • 測試與mysql的串連

    [root@localhost htdocs]# cat index.php

    if ($conn)

    echo "success!";

    else

    echo "failure!";

    ?>

  • 安裝php的xcache3.0(負責加速解析php代碼)擴充

    下載安裝包,編譯安裝

    下面這部分,針對php5.4可用

    [root@localhost ~]# wgethttp://xcache.lighttpd.net/pub/Releases/3.0.1/xcache-3.0.1.tar.gz

    [root@localhost ~]# tar xf xcache-3.0.1.tar.gz

    [root@localhost ~]# cd xcache-3.0.1

    [root@localhost xcache-3.0.1]# /usr/local/php/bin/phpize #phpize是準備一個php擴充準備編譯,第一層次的檢查

    Configuring for:

    PHP Api Version: 20131106

    Zend Module Api No: 20131226

    Zend Extension Api No: 220131226

    編譯指定哪個擴充(xcache),php-config是負責解析這個擴充並編譯的,相當於檢閱吧

    [root@localhost xcache-3.0.1]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

    [root@localhost xcache-3.0.1]# make&&make install

    /root/xcache-3.0.1/xcache.c: In function 'zif_xcache_get_special_value':

    /root/xcache-3.0.1/xcache.c:324: error: 'IS_CONSTANT_ARRAY' undeclared (first use in this function)

    /root/xcache-3.0.1/xcache.c:324: error: (Each undeclared identifier is reported only once

    /root/xcache-3.0.1/xcache.c:324: error: for each function it appears in.)

    make: *** [xcache.lo] Error 1

    上面的內容會報錯,原因是php5.6 xcache3.0並不支援,所以官網下載最新版,所以還是多去官網或權威網站比較好

    [root@localhost ~]# wgethttp://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz

[root@localhost~]# tar xzf xcache-3.2.0.tar.gz

[root@localhost~]# cd xcache-3.2.0

[root@localhostxcache-3.2.0]# /usr/local/php/bin/phpize

Configuringfor:

PHPApi Version: 20131106

ZendModule Api No: 20131226

ZendExtension Api No: 220131226

[root@localhostxcache-3.2.0]# ./configure --enable-xcache--with-php-config=/usr/local/php/bin/php-config

[root@localhostxcache-3.2.0]#make&&make install

Installingshared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20131226/

終於安裝好了,看來編譯環境和軟體版本等都需要考慮

把主設定檔放到php的片段配置小分隊

[root@localhostxcache-3.2.0]# mkdir /etc/php.d

[root@localhostxcache-3.2.0]# cp xcache.ini /etc/php.d/

修改/etc/php.d/xcache.ini檔案中的指定地方

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

重啟服務

[root@localhostxcache-3.2.0]# service httpd restart

Stoppinghttpd:[ OK ]

Startinghttpd:[OK ]

再次開啟網頁發現有了這個模組支援

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.