天天看點

搭建LAMP架構之安裝最新版PHP5.5.4

源碼包安裝PHP5.5.4

LAMP平台構成元件:Linux、Apache、MySQL、PHP

建構PHP運作環境

安裝前工作:

確定沒有rpm包PHP,且以源碼包安裝Apache、MySQL程式(詳見搭建LAMP架構之Apache和MySQL)

安裝GD庫和GD庫關聯程式(gd庫要是2.1版本以上)

(使之支援加載.jpeg、.png等圖檔)

yum-yinstall\

libjpeg-devel\

libpng-devel\

freetype-devel\

zlib-devel\

gettext-devel\

libXpm-devel\

libxml2-devel\

fontconfig-devel\

openssl-devel\

bzip2-devel

(還有gcc、gcc-c++、make等開發工具系統中要已安裝)

解壓縮gd-2.1.0.tar.gz

tarzxvfgd-2.1.0.tar.gz/usr/src

到gd源碼包目錄配置編譯并安裝

./configure--prefix=/usr/local/gd

make&&makeinstall

安裝PHP

解壓PHP-5.5.4源碼包

tarzxvfphp-5.5.4.tar.gz2/usr/src

進入php源碼包目錄配置編譯并安裝

./configure\

--prefix=/usr/local/php\

--with-apxs2=/usr/local/apache/bin/apxs\

--with-gd=/usr/local/gd\

--with-gd\

--with-mysql=/usr/local/mysql\

--with-config-file-path=/etc\

--enable-sqlite-utf8\

--with-zlib-dir\

--with-libxml-dir\

--with-freetype-dir\

--with-jpeg-dir\

--with-png-dir\

--with-ttf\

--with-iconv\

--with-openssl\

--with-gettext\

--enable-mbstring\

--enable-gd-native-ttf\

--enable-gd-jis-conv\

--enable-static\

--enable-zend-multibyte\

--enable-inline-optimization\

--enable-sockets\

--enable-soap\

--enable-ftp\

--disable-ipv6

配置中需注意:

--with-apxs2=:指向Apache安裝目錄下的/bin/apxs

--with-gd=:指向GD的安裝目錄

--with-gd:不能省略,不然編譯時會出錯

--with-mysql=:指向MySQL安裝目錄

--with-config-file-path=:指定PHP的配置檔案放置目錄

PHP不作為系統程式而存在,就相當于一個插件,協同Apache和MySQL工作。配置檔案預設沒有,可以把源碼包目錄下的模闆拷過來就可以了(配置檔案所在目錄在源碼包配置時--with-config-file-path=指定的目錄,一般指向/etc)

cp/usr/src/php-5.5.4/php.ini-production/etc/php.ini

重新配置Apache配置檔案httpd.conf,使之支援PHP

vi/usr/local/apache/conf/httpd.conf

添加

AddTypeapplication/x-httpd-php.php

AddTypeapplication/x-httpd-php-source.phps

為了友善管理,一般把這兩行插在AddType配置項一起

檢視配置項中有沒有下面一行配置項,如果沒有則添加

LoadModulephp5_modulemodules/libphp5.so

配置DirectoryIndex首頁配置,使Apache支援.php動态首頁

DirectoryIndexindex.phpindex.html

重新開機Apache服務

servicehttpdrestart

測試PHP網頁是否能正确顯示

在Apache網站根目錄添加Index.php動态首頁,

viindex.php

編輯内容

<?php

phpinfo();

?>

登入網站首頁測試

測試PHP網頁是否能通路MySQl資料庫

編輯Index.php網頁中内容為

$link=mysql_connect('192.168.1.1','tom','123');

if(!$link)echo"Fail!!";

elseecho"Success!!";

mysql_close();

(192.168.1.1為伺服器的IP位址,在MySQL資料庫中添加授權使用者tom,密碼為123)

如果能通路,顯示為Success!!,反之則為Fail!!