1.安裝php5
①下載解壓源碼包
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-5.6.30.tar.gz
②編譯安裝php
./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
部分內容說明:
--prefix=/usr/local/php:安裝目錄
--with-apxs2=/usr/local/apache2.4/bin/apxs :自動將擴展模塊放入modules目錄內
--with-config-file-path=/usr/local/php/etc :指定配置文件路徑
--with-pdo-mysql=/usr/local/mysql:支付in個mysql相關的函數及驅動
③編譯問題解決
configure過程中會中斷數次,出現多次錯誤,原因基本上是庫文件未安裝,
因此需要不斷安裝文件再重新開始編譯。
常見問題參考鏈接:
http://blog.sina.com.cn/s/blog_75a07c3b0101kcwb.html
2.安裝php7
安裝編譯php7的過程與php5大同小異
①下載php7的源碼包
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar zxf php-7.1.6.tar.bz2
②編譯安裝php7
./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
make && make install
上述編譯過程相較於php5安裝過程會順利很多,因爲php5安裝過程中已經解決了很多包的安裝問題。
在php7的編譯選項中已經取消了--with-mysql=/usr/local/mysql這一部分,取而代之的是上述的加粗部分。
③拷貝配置文件
cp php.ini-production /usr/local/php7/etc/php.ini