LAMP環境配置之安裝PHP

安裝最新版的PHP模塊 php

ps:服務器:CentOS6.5html

PHP:php-5.6.1.tar.gzmysql

進入php-5.4.11源碼包編譯 
[root@localhost  php-5.4.11]# ./configure \ 
sql

> --prefix=/usr/local/php \ 
> --with-config-file-path=/usr/local/php/etc \ 
apache

> --with-apxs2=/usr/local/apache/bin/apxs \ (編譯libphp5.so 是解析php的重要步驟,注意)瀏覽器

> --with-mysql=/usr/local/mysql/ \ 安全

> --with-libxml-dir=/usr/local/libxml2/  \
> --with-png-dir=/usr/local/libpng/ \ 
服務器

> --with-jpeg-dir=/usr/local/jpeg8/ \ app

> --with-freetype-dir=/usr/local/freetype/ \ socket

> --with-gd=/usr/local/gd/ \ 
> --with-zlib-dir=/usr/local/zlib/ \

 > --with-mcrypt=/usr/local/libmcrypt/ \ 
> --with-mysqli=/usr/local/mysql/bin/mysql_config \ 

> --enable-soap \ 
> --enable-mbstring=all \ 

> --enable-sockets  
make(配置) 提示信息: Build complete. 
Don't forget to run 'make test'. 解決方案: 
不要make test 直接make install 配置時可能會出現下面的錯誤: checking for MySQL support... yes  
checking for specified location of the MySQL UNIX socket... no  checking for MySQL UNIX socket location... no  
configure: error: Cannot find libmysqlclient_r under /usr/local/mysql. Note that the MySQL client library is not bundled anymore! 
其實這跟PHP沒有關係,那是由於在編譯APACHE的時候,使用--with-mpm模塊,因此就必須在編譯MYSQL的時候加上 --enable-thread-safe-client.參數 
這是PHP5.2的一個改進,在PHP5.2.0以前的版本都不須要MYSQL啓用安全線程。關於--enable-thread-safe-client項的官方介紹以下:如何生成線程式客戶端庫老是線程安全的。最大的問題在於從套接字讀取的net.c中的子程序並非中斷安全的。或許你可能但願用本身的告警中斷對服務器的長時間讀取,以此來解決問題。若是爲SIGPIPE中斷安裝了中斷處理程序,套接字處理功能應是線程安全的。SupeSite/X-爲了不鏈接中斷時放棄程序,MySQL將在首次調用mysql_server_init()、mysql_init()或mysql_connect()時屏蔽SIGPIPE。若是你打算使用本身的SIGPIPE處理程序,首先應調用mysql_server_init(),而後安裝你的處理程序.
還有第二種解決方法比較方便 :編譯以前,先處理一下mysql的庫,默認查找libmysqlclient_r.so,但是mysql默認爲libmysqlclient.so,內容徹底同樣,作個連接便可 
# cd /usr/local/mysql/lib/mysql/  
# ln -s libmysqlclient.so.15.0.0 libmysqlclient_r.so (以上解決方法來自互聯網!) 還會報make: *** [ext/gd/gd.lo] error 解決方法以下: 
好像說這個錯誤算是php5.4的bug,下面對應的兩篇文章有對應的說明: https://bugs.php.net/bug.php?id=55224 https://bugs.php.net/bug.php?id=60108 解決方法: 
vi <gd_dir>/include/gd_io.h gdIOCtx結構中增長void *data; 格式以下 
typedef struct gdIOCtx { 
  int (*getC) (struct gdIOCtx *); 
  int (*getBuf) (struct gdIOCtx *, void *, int);   
  void (*putC) (struct gdIOCtx *, int); 
  int (*putBuf) (struct gdIOCtx *, const void *, int);   
  /* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */   int (*seek) (struct gdIOCtx *, const int);   
  long (*tell) (struct gdIOCtx *);   
  void (*gd_free) (struct gdIOCtx *);   void (*data); } 
gdIOCtx; 
個人GD安裝在/usr/local/gd2目錄下,因此是#vi vi /usr/local/gd/include/gd_io.h libltdl.so.3: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127 解決方法: 
ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3 [root@localhost  ~]# cd /usr/local/libpng/lib/ [root@localhost  lib]# ls 
libpng15.a   libpng15.so     libpng15.so.15.10.0  libpng.la  pkgconfig libpng15.la  libpng15.so.15  libpng.a             libpng.so 能夠看到libpng15.so.15 
而後修改/etc/ld.so.conf 文件:vi /etc/ld.so.conf 
在第一行下面追加/usr/local/libpng/lib這個路徑。 而後從新編譯安裝便可。 提示信息: 
=====================================================================  
===================================================================== WARNED TEST SUMMARY 
--------------------------------------------------------------------- Bug 
#52062 
(large 
timestamps 
with 
DateTime::getTimestamp 
and 
DateTime::setTimestamp) (32 bit) [ext/date/tests/bug52062.phpt] (warn: XFAIL section but test passes) 
=====================================================================  
You may have found a problem in PHP. 
This report can be automatically sent to the PHP QA team at http://qa.php.net/reports and http://news.php.net/php.qa.reports This gives us a better understanding of PHP's behavior. 
If you don't want to send the report immediately you can choose 
option "s" to save it.  You can then email it to qa-reports@lists.php.net later. Do you want to send this report now? [Yns]: 解決方案: 
不要make test 直接make install   
安裝完成後,須要創建PHP配置文件。在使用configure命令安裝配置時使用
「--with-config-file-path=/usr/local/php/etc/」選項,指定了配置文件的位置。將源碼包下面的php.ini-development 文件複製到/usr/local/php/etc/中,並更名爲php.ini便可,以下示: 
[root@localhost  php-5.4.11]# cp php.ini-development /usr/local/php/etc/php.ini  修改php.ini 把;date.timezone 前面的分號去掉,改爲date.timezone ="PRC" 
整合Apache與PHP,上面編譯以前,咱們使用configure命令安裝配置時,使用--with-apxs2=/usr/local/apache242/bin/apxs選項以使Apache 2將PHP做爲功能模塊使用。但咱們還要修改Apahce配置文件,添加PHP的支持,告訴Apache將哪些後綴做爲PHP解析。例如,讓Apache把.php或.phtml後綴名解析爲PHP.使用vi打開Apache的配置文件/etc/httpd/httpd.conf,找到AddType application/x-gzip .gz .tgz指令選項,並在其下方添加一條指令AddType application/x-httpd-php .php .phtml。也能夠將任何後綴的文件解析爲PHP,只要在添加的語句中加入並用空格分開,這裏以多添加一個.phtml來示例,以下示: 
 # If the AddEncoding directives above are commented-out, then you     # probably should define those extensions to indicate media types:     # 
    AddType application/x-compress .Z     AddType application/x-gzip .gz .tgz 
    AddType application/x-httpd-php .php .phtml 
修改完成後必須重啓Apache服務器,才能從新加載配置文件使修改生效。 [root@localhost php-5.4.11]#/usr/local/apache243/bin/apachectl stop [root@localhost php-5.4.11]#/usr/local/apache243/bin/apachectl start   
測試PHP環境是否能夠正常運行,在/usr/local/apache243/htdocs目錄下建一個test.php或test.phtml的文件,內容以下示: <?php 
          phpinfo(); ?> 
打開瀏覽器,在地址欄輸入http://192.168.146.129/test.php來運行該文件,若是出現下圖內容,說明LAMP環境安裝成功。

上例中使用phpinfo()函數,做用是輸出有關PHP當前狀態的大部分信息內容,這包括關於PHP的編譯和擴展信息、PHP版本、服務器信息和環境、PHP的環境、操做系統信息、路徑、主要的和本地配置選項的值、HTTP頭信息和PHP許可等。由於每一個系統的安裝不一樣,phpinfo()函數能夠用於檢查某一特定系統配置設置和可用的預約義變量等。它也是一個寶貴的調試工具,由於它包含了全部EGPCS(Environment,GET,POST,Cookie,Server)數據。

相關文章
相關標籤/搜索