php安裝gd庫與phpize的用法

來源:互聯網
上載者:User
  1. [root@jbxue achievo]# php -v
  2. PHP 5.3.6 (cli) (built: Aug 19 2011 19:35:20)
  3. Copyright (c) 1997-2011 The PHP Group
  4. Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
複製代碼

二,phpize1,什麼是phpizephpize用來擴充php擴充模組,通過phpize可以建立php的外掛模組。

在安裝php時,需要用到phpize:

  1. './configure' '--prefix=/usr/local/php' '--with-mysql=/usr/local/mysql' '--with-zlib-dir' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-gd' '--enable-ftp' '--with-iconv' '--with-gettext' '--with-curl' '--enable-fastcgi' '--with-openssl'
複製代碼

後面的參數是需要的模組,有時需要再添加一些模組,又不想重新編譯php,此時即可用phpize來協助外掛模組。

2,如何使用phpize? 當php編譯完成後,php的bin目錄下會有phpize這個指令檔 。在編譯要添加的擴充模組之前,執行以下phpize就可以了;

  1. # 如果在編譯的時候忘記添加某些模組,可以使用這種辦法來重新編譯添加!
  2. # 首先,進入PHP目錄(未編譯)的擴充目錄
  3. cd /home/soft/php-5.2.14/ext/ftp/
  4. # 調用phpize程式產生編譯設定檔
  5. # find / -name phpize
  6. /usr/local/php/bin/phpize
  7. Configuring for:
  8. PHP Api Version: 20041225
  9. Zend Module Api No: 20060613
  10. Zend Extension Api No: 220060519
  11. # 編譯擴充庫
  12. /configure –with-php-config=/usr/local/php/bin/php-config
  13. make
  14. # make成功執行後,產生的擴充庫檔案在目前的目錄的 modules 子目錄下
  15. # 編輯php.ini文檔,找到extension_dir的目錄,將編譯好的擴充檔案複製到extension下面
  16. vim /usr/local/php/etc/php.ini
  17. # 第491行
  18. # extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
  19. cp ftp.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
  20. # 在php.ini的添加擴充庫位置,設定要添加的擴充庫。
  21. # 在612處添加 extension=ftp.so
  22. # 重啟webservice
複製代碼

------------------------------------------------------ 181的php源碼位置在 /root/software/php-5.3.6

嘗試在以上平台安裝個Xenforo論壇,安裝開始時提示以下資訊: The following errors occurred while verifying that your server can run XenForo: * The required PHP extension MySQLi could not be found. Please ask your host to install this extension. * The required PHP extension GD could not be found. Please ask your host to install this extension.

由於PHP是源碼編譯安裝的,所以以上兩個擴充都沒安裝,下面是為PHP添加這兩個擴充的過程:

一、安裝GD擴充 1.下載安裝GD庫擴充所需源碼包(可點擊源碼包直接下載) gd-2.0.35.tar.gz http://www.libgd.org/releases/ jpegsrc.v8b.tar.gz http://www.ijg.org/ libpng-1.5.0.tar.gz http://sourceforge.net/projects/libpng/ freetype-2.4.4.tar.gz http://sourceforge.net/projects/freetype/ zlib-1.2.3.tar.gz

2.分別編譯安裝各個源碼包 1)、安裝zlib

  1. tar zxvf zlib-1.2.3.tar.gz
  2. cd zlib-1.2.3
  3. ./configure
  4. make
  5. make install
複製代碼

2)、安裝libpng

  1. tar zxvf libpng-1.5.0.tar.tar
  2. cd libpng-1.5.0
  3. cd scripts
  4. mv makefile.linux ../makefile
  5. cd ..
  6. make
  7. make install
複製代碼

3)、安裝freetype

  1. tar zxvf freetype-2.4.4.tar.gz
  2. cd freetype-2.4.4
  3. ./configure
  4. make
  5. make install
複製代碼

4)、安裝Jpeg

  1. tar zxvf jpegsrc.v8b.tar.gz
  2. cd jpeg-8b
  3. ./configure –enable-shared
  4. make
  5. make test
  6. make install
複製代碼

注意,這裡configure一定要帶–enable-shared參數,不然,不會產生共用庫。

5)、安裝GD庫

  1. tar zxvf gd-2.0.33.tar.gz
  2. cd gd-2.0.33
  3. ./configure –with-png –with-freetype –with-jpeg
  4. make install
複製代碼

3,重新編譯安裝PHP(即是在以前編譯PHP的參數後面再加上以上安裝的相關參數) cd php-5.3.4 (進入以前的PHP源碼目錄)

  1. ./configure –prefix=/opt/php –with-mysql=/opt/mysql –with-apxs2=/opt/apache/bin/apxs –enable-track-vars –enable-force-cgi-redirect –with-config-file-path=/opt/php/etc –with-gd –enable-gd-native-ttf –with-zlib –with-png –with-jpeg –with-freetype –enable-sockets
複製代碼

綠色字型部份是以前安裝PHP時所加的參數:

  1. make
  2. make install
複製代碼

這樣GD庫擴充便安裝完畢,重啟Apache,查看PHP資訊測試頁便可看到gd項;

二、安裝MySQLi擴充 在這裡要用到phpize,phpize 命令是用來準備 PHP 擴充庫編譯環境,一般在安裝好PHP後,會在安裝PHP的bin目錄下找到這個命令。 如果在執行phpize命令後出現找不到autoconf之類的提示,請安裝好autoconf後再次執行。 以下指令的目錄路徑,請網友們根據自己系統的實際情況作相應修改。 PHP源碼包檔案夾下的EXT檔案夾就是放置著目前版本的可用擴充,CD進去看看哪些需要?應該看到mysqli檔案夾了。

  1. cd /opt/software/php-5.3.4/ext/mysqli
複製代碼

在目前的目錄下執行phpize

  1. [root@jbxue mysqli]#/opt/php/bin/phpize
  2. Configuring for:
  3. PHP Api Version: 20090626
  4. Zend Modeule Api No: 20090626
  5. Zend Extension Api No: 220090626
  6. [root@jbxue mysqli]#./configure –prefix=/opt/mysqli –with-php-config=/opt/php/bin/php-config –with-mysqli=/opt/mysql/bin/mysql_config
  7. [root@jbxue mysqli]#make
  8. [root@jbxue mysqli]#make install
複製代碼

安裝完成後,會有提示擴充所在目錄路徑,例如: /opt/php/lib/php/extensions/no-debug-zts-20090626 所需的mysqli.so便會在此目錄下。

接下來修改/opt/php/etc/下的php.ini檔案,加入mysqli擴充:

  1. extension=/opt/php/lib/php/extensions/no-debug-zts-20090626/mysqli.so
複製代碼

重啟Apache服務,再次開啟PHP資訊頁,即可看到MySQLi項。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.