編譯安裝PHP

1.去php官網下載源碼 http://www.php.net/downloads.php ,我下載使用的版本是(php-5.4.8.tar.gz)

2.解壓到/usr/src目錄,執行命令:sudo tar -zxvf php-5.4.8.tar.gz -C /usr/src

3.執行./configure --prefix=/usr/local/php --enable-fpm  --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf  --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetype

4.編譯遇到問題:error: xml2-config not found.解決辦法:

 (1)去官網http://xmlsoft.org/sources/ 下載源碼。我用的版本是libxml2-2.9.0.tar.gz, 解壓到/usr/src,執行命令:sudo tar -zxvf libxml2-2.9.0.tar.gz  -C /usr/src

 (2)進入目錄/usr/src/libxml2-2.9.0,在root下執行或者用sudo命令執行: sudo ./configure --prefix=/usr/local/libxml2/ ; make; make install

   (3) 進入php目錄中編譯時加上--with-libxml-dir=/usr/local/libxml2

5.再次編譯,遇到問題:checking if the location of ZLIB install directory is defined... no ; configure: error: Cannot find libz. 解決辦法:

  (1)去網址 http://www.zlib.net/ 下載zlib源碼。我下的是版本zlib-1.2.7.tar.gz,解壓到/usr/src,執行命令:sudo tar -zxvf zlib-1.2.7.tar.gz  -C /usr/src

  (2)進入目錄/usr/src/zlib-1.2.7/,執行命令:sudo ./configure --prefix=/usr/local/zlib;make;make install

  (3)進入php目錄中重新編譯,增加新參數 --with-zlib-dir=/usr/local/zlib

6.再次編譯,遇到問題:error: Please reinstall the BZip2 distribution. 解決辦法:

  (1)去網站 http://www.bzip.org/downloads.html 下載源碼。我用的版本是bzip2-1.0.6.tar.gz,執行命令:sudo tar -zxvf bzip2-1.0.6.tar.gz -C /usr/src

  (2)進入目錄/usr/src/bzip2-1.0.6/,sudo方式執行:make;make install(下的源碼中並沒有configure)

  (3)重新編譯,不用增加新參數

7.再次編譯,遇到問題:

checking if we should use cURL for url streams... no checking for cURL in default path... not found

configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/

解決辦法是重裝libcurl

  (1)去網站 http://curl.haxx.se/download/ 下載libcurl源碼。我用的版本是curl-7.28.0.tar.gz,執行命令:sudo tar -zxvf curl-7.28.0.tar.gz -C /usr/src

  (2)進入/usr/src/curl-7.28.0目錄,用sudo執行命令:./configure --prefix=/usr/local/curl;make;make install

  (3)重新編譯php,增加參數--with-curl=/usr/local/curl

8.再次編譯,遇到問題:configure: error: jpeglib.h not found. 解決辦法:

  (1)去網站 http://www.ijg.org/ 下載源碼。我用的版本是jpegsrc.v8d.tar.gz,執行命令:sudo tar -zxvf jpegsrc.v8d.tar.gz -C /usr/src

  (2)進入/usr/src/jpegsrc.v8d目錄,sudo方式執行命令:sudo ./configure --prefix=/usr/local/jpeg;make;make install;

  (3)重新編譯php,增加參數--with-jpeg-dir=/usr/local/jpeg

9.再次編譯,遇到問題:configure: error: png.h not found.

  (1)去網站http://www.libpng.org/pub/png/libpng.html 下載源碼,我用的版本是libpng-1.5.13.tar.gz,執行命令:sudo tar -zxvf libpng-1.5.13.tar.gz -C /usr/src

  (2)進入/usr/src/libpng-1.5.13目錄,sudo方式執行命令:sudo ./configure --prefix=/usr/local/png;make;make install;

  (3)這時出現了configure: error: zlib not installed的錯誤,明明之前已經裝過的,但是這裏還是報錯。在網上查瞭解決辦法如下:

          3.1)進入zlib的源文件目錄(這裏我的是/usr/src/zlib-1.2.7/),執行命令 make clean,清除zlib;

    3.2)重新配置 ./configure,後面不要接--prefix參數;

    3.3)make && make install;

    3.4)進入libpng目錄(我的是/usr/src/libpng-1.5.13/),執行命令 ./configure --prefix=/usr/local/png;

    3.5)make && make install;

  (4)重新編譯php,這時增加參數--with-png-dir=/usr/local/png。

10.再次編譯,遇到問題:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

 (1)去網站http://mcrypt.hellug.gr/lib/index.html 的下載源碼,我下的版本是libmcrypt-2.5.7.tar.gz;執行命令:sudo tar -zxvf libmcrypt-2.5.7.tar.gz -C /usr/src

 (2)進入/usr/src/libmcrypt-2.5.7目錄,sudo方式執行命令:./configure prefix=/usr/local/libmcrypt/;make ;make install

 (3)重新編譯php,這時增加參數--with-mcrypt=/usr/local/libmcrypt

11.再次編譯,就沒有遇到問題了,雖然顯示了configure: WARNING: unrecognized options: --enable-freetype,但結果依然是Thank you for using PHP. 此時的編譯php的參數如下:

 (1)sudo ./configure --prefix=/usr/local/php --enable-fpm  --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --enable-gd-native-ttf  --enable-pdo --with-pdo-mysql --with-gettext --with-curl --with-pdo-mysql --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-freetype --with-libxml-dir=/usr/local/libxml2 --with-zlib-dir=/usr/local/zlib --with-curl=/usr/local/curl --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-mcrypt=/usr/local/libmcrypt --with-apxs2=/usr/local/apache2/bin/apxs

(備註:一定要加這個 apxs - APache eXtenSion tool 用來製作apache的擴展模塊DSO,要使用這個工具,安裝apache的時候就必須添加enable-so以支持DSO. 如果沒有這個的話apache是隻會解析靜態頁面的,第一次編譯時沒加,怎麼配置都不行,第二次加了該選項重新編譯以後就都OK了。)

(2)sudo make

(3)sudo make install

12.爲了在命令行可以直接使用php命令,編輯 sudo vim /etc/environment,將php的bin目錄路徑添加進去,我的是/usr/local/php/bin,然後reboot機器

13.爲了使Apache支持PHP,解決辦法:

  (1)進入apache配置目錄,執行命令:cd /usr/local/apache2/conf。 編輯文件:sudo vim httpd.conf

 (2)查找字符串AddType,並增加

        AddType application/x-httpd-php .php .php3 .htm .phtml .php4

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

        然後重啓apache使配置生效

  (3)查找字符串DirectoryIndex,並修改爲 DirectoryIndex index.html index.php3 index.php default.php

14. 修改php配置.

  (1)進入php源碼目錄,選擇php.ini-development複製一份到/usr/local/lib,並改名爲php.ini使用vim打開,查找extension_dir,修改爲extension_dir = "D:/php/php5/ext",讀      者根據自己的目錄結構配置,目的是找到和php.ini同目錄下的ext文件夾中的擴展庫。

(2)查找extension=php_,去掉extension=php_curl.dll,extension=php_gd2.dll,extension=php_mbstring.dll,extension=php_mysql.dll,extension=php_mysqli.dll,extension=php_pdo_mysql.dll,extension=php_xmlrpc.dll前面 的分號。查找short_open_tag = Off把它修改成short_open_tag = On,讓其支持短標籤(我看註釋這個默認是打開的)。

15.查找字符串DocumentRoot,可以設置Apache虛擬根目錄

16.查找字符串ServerAdmin,並修改成自己的郵箱

17.在apache根文件中增加一個test.php文件,<?php phpinfo(); ?>,然後訪問127.0.0.1/test.php,查看結果。


附錄:網上找的php各個版本的編譯參數如下。

Fast-CGI:
./configure --prefix=/usr/local/php --enable-fastcgi --enable-force-cgi-redirect --with-config-file-path=/etc --with-zlib --with-mysql --with-xml --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-mbstring

PHP4-Server:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-config-file-path=/etc --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-mbstring

PHP4-Max:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --with-openssl=/usr/local/openssl-0.9.7e --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-bz2 --with-inifile --with-hyperwave --enable-xml --enable-track-vars --enable-dba --enable-dbase --enable-filepro --enable-ftp --enable-versioning --enable-memory-limit --enable-calendar --enable-session --enable-sockets --enable-sysmsg --enable-sysvsem --enable-sysvshm --enable-tokenizer --enable-overload --enable-ctype --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-dio --enable-shmop --enable-mbstring

PHP5-Server:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-bz2 --with-tiff-dir --with-libxml-dir --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --enable-mbstring --with-mysql=/usr/lib/mysql --with-config-file-path=/etc --disable-ipv6 --enable-gd-native-ttf

PHP5-Standard:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf

PHP5-Max:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --mandir=/usr/share/man --with-openssl=/usr/local/openssl-0.9.7e --with-zlib --with-bz2 --with-tiff-dir --with-libxml-dir --enable-dio --enable-ftp --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-bz2-dir --with-ttf --with-inifile --enable-dba --enable-dbase --enable-filepro --enable-versioning --enable-memory-limit --enable-calendar --enable-sockets --enable-sysvsem --enable-sigchild --enable-magic-quotes --enable-roxen-zts --enable-fastcgi --enable-dbx --enable-shmop --enable-mbstring --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --disable-ipv6 --enable-gd-native-ttf


參考網址:

http://blog.163.com/lcnetwork@126/blog/static/1170868762011593131831/

http://www.cnblogs.com/amboyna/archive/2008/07/13/1241961.html

http://www.cnblogs.com/neve/articles/1989352.html

http://blog.chinaunix.net/uid-23095063-id-163167.html

http://www.habadog.com/2012/02/07/install-curl-ext-with-php-source-code-in-linux/

http://www.oschina.net/question/17_10674

http://www.cnblogs.com/1110111abc/archive/2012/09/22/2698259.html

http://blog.163.com/lcnetwork@126/blog/static/117086876201159355861/

http://blog.sina.com.cn/s/blog_61aed0450100sr5k.html

http://www.jb51.net/article/24691.htm


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