LAMP+LNMP(四)PHP安裝實踐

一、PHP簡介

PHP是一種PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預處理器”)是一種通用開源腳本語言。語法吸收了C語言、Java和Perl的特點,利於學習,使用廣泛,主要適用於Web開發領域。PHP的官網是www.PHP.com 。當前主流的版本是5.6與7.1,企業常用的是5版本的PHP,最新的是PHP7,在性能上比PHP5有很大提升,具體選擇哪個主要是看業務程序的兼容性。

二、安裝PHP5

1、下載php程序包

cd /usr/local/src
wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2

LAMP+LNMP(四)PHP安裝實踐

2、解壓程序包

tar jxvf php-5.6.30.tar.bz2

3、生成編譯文件

cd php-5.6.30
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

這一步時你會遇到無數的問題,比如下面這樣,編譯停下來了,這是你就需要根據紅框中的關鍵字,找相應的庫
LAMP+LNMP(四)PHP安裝實踐

yum list |grep xml2
LAMP+LNMP(四)PHP安裝實踐
這時我們安裝libxml2-devel這個包就行了。

相同的問題還會出現很多次,每次出現時最好都去搜索下,能夠增長排錯經驗。
這裏我們把需要安裝的庫列在下面,一併安裝上就可以正常編譯了。

yum install -y libxml2-devel openssl-devel bzip2-devel libpng freetype-devel epel-release libmcrypt-devel
libjpeg-turbo-devel libpng-devel

看到這個就完成了:
LAMP+LNMP(四)PHP安裝實踐

4、make & make install

make && make install

這一步要花費很長時間,大概五分鐘左右,隨機器信能不同,性能越好越快。

LAMP+LNMP(四)PHP安裝實踐

看到這個就ok了

5、複製配置文件

cp -v php.ini-production /usr/local/php/etc/php.ini #如果是測試環境可以用php.ini-development

LAMP+LNMP(四)PHP安裝實踐

補充一些php操作命令

/usr/local/php/bin/php -m

LAMP+LNMP(四)PHP安裝實踐

php5不需要像myaql、apache一樣需要啓動,他本身作爲apache的一個模塊工作。模塊的路徑是/usr/local/apache2.4/modules/libphp5.so,apache通過這個模塊與mysql交換數據,如果刪掉該模塊會使網站,比如論壇無法工作。
LAMP+LNMP(四)PHP安裝實踐

二、安裝PHP7

1、下載源碼包

cd /usr/local/src
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

LAMP+LNMP(四)PHP安裝實踐

2、解壓源碼包

tar xvf php-7.1.6.tar.bz2

3、編譯php7

cd php-7.1.6/
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif

LAMP+LNMP(四)PHP安裝實踐

4、安裝php7

make
make install

LAMP+LNMP(四)PHP安裝實踐
建議每一步後都用echo $?查看一下執行是否正確

LAMP+LNMP(四)PHP安裝實踐

5、查看apache目錄中的php7模塊

ls /usr/local/apache2.4/modules/libphp7.so

6、拷貝php7的配置文件

cp -v php.ini-production /usr/local/php7/etc/php.ini

兩種php可以共存,在httpd中要進行相關配置

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