編譯安裝 php 5.4.11


第一步 先下載 tzr.gz 的php源碼包
然后 tar zxvf  php-5.4.11.tar.gz
然后 cd php-5.4.11

然后復制如下編譯代碼 
./configure \
--prefix=/usr/local/php \
--enable-zip \
--with-xsl \
--enable-zend-multibyte \
--enable-sockets \
--enable-soap \
--with-pdo-mysql=mysqlnd \
--with-mysql=mysqlnd \
--enable-pcntl \
--with-mcrypt \
--enable-fpm \
--enable-shmop \
--with-readline \
--enable-mbstring \
--with-mhash \
--enable-gd-native-ttf \
--with-freetype-dir \
--with-t1lib=/usr/local/share/t1lib \
--with-png-dir \
--with-jpeg-dir \
--with-gd \
--with-openssl-dir \
--enable-ftp \
--enable-exif \
--enable-dba \
--with-bz2 \
--enable-bcmath \
--with-curl

!!!

編譯PHP5缺t1lib包解決方案

遇到這個報錯:
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
以下是解決步驟:
1. 下載
t1lib-5.1.2.tar.gz
2. 解決依賴關系:apt-get build-dep t1lib
3. 安裝:./configure & make without_doc & make install
4. 編譯php5 時在./configure后加上 --with-t1lib=/usr/local/share/t1lib。再次編譯就能通過了。 


解決地址:http://lepingbeta.com/archives/255


如果提示 configure: error: Please reinstall readline - I cannot find readline.h 錯誤!

安裝 sudo apt-get install  libreadline-dev

然后再編譯一下 就沒錯誤了!

‘./configure’ ‘–prefix=/usr/local/php’ ‘–with-config-file-path=/etc’ ‘–with-mysql=/usr/local/mysql’ ‘–with-mysqli=/usr/local/mysql/bin/mysql_config’ ‘–with-iconv-dir=/usr/local’ ‘–with-freetype-dir’ ‘–with-jpeg-dir’ ‘–with-png-dir’ ‘–with-zlib’ ‘–with-libxml-dir=/usr’ ‘–enable-xml’ ‘–disable-rpath’ ‘–enable-safe-mode’ ‘–enable-bcmath’ ‘–enable-shmop’ ‘–enable-sysvsem’ ‘–enable-inline-optimization’ ‘–with-curl’ ‘–with-curlwrappers’ ‘–enable-mbregex’ ‘–enable-fpm’ ‘–enable-mbstring’ ‘–with-mcrypt’ ‘–with-gd’ ‘–enable-gd-native-ttf’ ‘–with-openssl’ ‘–with-mhash’ ‘–enable-pcntl’ ‘–enable-sockets’ ‘–with-xmlrpc’ ‘–enable-zip’ ‘–enable-soap’
出現得錯誤如下:

報錯:configure: error: png.h not found.
解決辦法:
apt-get -y install libpng12-dev

錯誤一:
configure: error: xml2-config not found. Please check your libxml2 installation.
而我已經安裝過了libxml2,但是還是有這個提示:
解決辦法:
# sudo apt-get install libxml2-dev

錯誤二:
configure: error: Please reinstall the BZip2 distribution
而我也已經安裝了bzip2,網上找到得解決方案都是需要安裝bzip2-dev,可是11.10里面沒有這個庫。
解決辦法:在網上找到bzip2-1.0.5.tar.gz,解壓,直接make ,sudo make install.(我使用的該源來自於http://ishare.iask.sina.com.cn/f/9769001.html)

錯誤三:
configure: error: Please reinstall the libcurl distribution -easy.h should be in /include/curl/
解決辦法:
# sudo apt-get install libcurl4-gnutls-dev

錯誤四:
configure: error: jpeglib.h not found.
解決辦法:
# sudo apt-get install libjpeg-dev

錯誤五:
configure: error: png.h not found.
解決辦法:
# sudo apt-get install libpng-dev

錯誤六:
configure: error: libXpm.(a|so) not found.
解決辦法:
# sudo apt-get install libxpm-dev

錯誤七:
configure: error: freetype.h not found.
解決辦法:
# sudo apt-get install libfreetype6-dev

錯誤八:
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
解決辦法:
# sudo apt-get install libt1-dev

錯誤九:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決辦法:
# sudo apt-get install libmcrypt-dev

錯誤十:
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
解決辦法:
# sudo apt-get install libmysql++-dev

錯誤十一:
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解決辦法:
# sudo apt-get install libxslt1-dev
可見PHP源碼安裝之前需要先安裝這些依賴,詳細可見http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=231159
如上錯誤都解決之后,再次./config….沒有錯誤之后,
# make
# sudo make install















將編譯安裝的PHP輸入到環境變量中
編譯后 將其PHP路徑 輸入到環境變量中,要不然系統執行PHP的文件時 不知道PHP安裝了沒有 所以要指定一個目錄 讓系統知道去那里能找到編譯安裝的PHP

Linux CentOS系統上安裝完php和MySQL后,為了使用方便,需要將php和mysql命令加到系統命令中,如果在沒有添加到環境變量之前,執行 “php -v”命令查看當前php版本信息時時,則會提示命令不存在的錯誤,下面我們詳細介紹一下在linux下將php和mysql加入到環境變量中的方法(假 設php和mysql分別安裝在/usr/local/webserver/php/和/usr/local/webserver/mysql/中)。

方法一:直接運行命令export PATH=$PATH:/usr/local/webserver/php/bin 和 export PATH=$PATH:/usr/local/webserver/mysql/bin

使用這種方法,只會對當前會話有效,也就是說每當登出或注銷系統以后,PATH 設置就會失效,只是臨時生效。

方法二:執行vi ~/.bash_profile修改文件中PATH一行,將/usr/local/webserver/php/bin 和 /usr/local/webserver/mysql/bin 加入到PATH=$PATH:$HOME/bin一行之后

這種方法只對當前登錄用戶生效

方法三:修改/etc/profile文件使其永久性生效,並對所有系統用戶生效,在文件末尾加上如下兩行代碼
PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH

或者   export PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin

最后:執行 命令source /etc/profile或 執行點命令 ./profile使其修改生效,執行完可通過echo $PATH命令查看是否添加成功。



啟動 php 服務的時候 

sudo /usr/local/php/sbin/php-fpm  

會出現

錯誤:

[10-Apr-2013 18:12:02] NOTICE: PHP message: PHP Deprecated:  Comments starting with '#' are deprecated in /usr/local/php/lib/php.ini on line 1874 in Unknown on line 0
[10-Apr-2013 18:12:02] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[10-Apr-2013 18:12:02] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[10-Apr-2013 18:12:02] ERROR: FPM initialization failed

這時候 是 php 找不到 配置文件php-fpm.conf

解決辦法: 
cd /usr/local/php/etc/ 


sudo cp php-fpm.conf.default php-fpm.conf

再啟動
sudo /usr/local/php/sbin/php-fpm

出現錯誤:

[10-Apr-2013 18:14:09] NOTICE: PHP message: PHP Deprecated:  Comments starting with '#' are deprecated in /usr/local/php/lib/php.ini on line 1874 in Unknown on line 0
[10-Apr-2013 18:14:09] ERROR: [pool www] cannot get gid for group 'nobody'
[10-Apr-2013 18:14:09] ERROR: FPM initialization failed

原因是  [pool www] cannot get gid for group 'nobody'  沒有這個用戶  我之前編譯的時候 指定用戶 是 www   所以進入 vi  /usr/local/php/etc/php-fpm.conf    
修改 

user = www
group = www
 


然后 測試PHP是否安裝成功

在網站跟目錄下 寫入 一個測試 PHP是否安裝成功的 
我的nginx 根目錄是 /usr/local/nginx/html/

sudo vi   index.php

  <?php phpinfo(); ?>

保存

然后測試下即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM