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

源碼包安裝PHP5.5.4

LAMP平臺構成組件:LinuxApacheMySQLPHP

構建PHP運行環境

安裝前工作:

確保沒有rpmPHP,且以源碼包安裝ApacheMySQL程序(詳見搭建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

(還有gccgcc-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的配置文件放置目錄

make&&makeinstall

PHP不作爲系統程序而存在,就相當於一個插件,協同ApacheMySQL工作。配置文件默認沒有,可以把源碼包目錄下的模板拷過來就可以了(配置文件所在目錄在源碼包配置時--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網頁中內容爲

<?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!!

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