• PHP官網www.php.netphp
• 當前主流版本爲5.6/7.1mysql
cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
tar jxvf php-5.6.32.tar.bz2
cd /usr/local/src/php-5.6.32/ ./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 自動在httpd上配置PHP模塊 //--with-config-file-path=/usr/local/php/etc 指定PHP配置文件所在路徑(PHP配置文件後綴爲.ini) // --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with- mysqli=/usr/local/mysql/bin/mysql_config 三種鏈接MySQL的驅動
在初始化時出現一個錯誤linux
經過報錯信息判斷是缺乏libxml2-devel(庫)類型的安裝包,也可經過命令作進一步確認(安裝PHP時通常都會缺乏各類各樣的庫文件)sql
yum list |grep xml2
第二個錯誤apache
第三個錯誤(yum安裝的包應爲小寫)php7
第四個錯誤架構
[root@linux-5 php-5.6.32]# yum install -y libjpeg-turbo-devel.x86_64
第五個錯誤dom
第六個錯誤socket
第七個錯誤(這是基於epel擴展源的包,須要先安裝epel擴展源)測試
看到此標識,說明已經初始化成功(以防萬一可用echo $?進行檢查)
cp php.ini-production(development)/usr/local/php/etc/php.ini //production爲生產環境,development爲測試開發環境
libxml2-devel openssl-devel bzip2-devel libjpeg-turbo-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libmcrypt-devel.x86_64(須要先安裝epel擴展源)
make make install
在LAMP架構中,Apache所須要PHP中的模塊文件是/usr/local/apache2.4/modules/libphp5.so,PHP的做用是將php5_module模塊安裝在Apache上幫助Apache進行一些通訊,所以LAMP中的PHP無需啓動也可正常工做
[root@linux-5 php-5.6.32]# /usr/local/apache2.4/bin/httpd -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::531b:14ea:3a75:f113. Set the 'ServerName' directive globally to suppress this message Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) alias_module (shared) php5_module (shared)
Apache的配置文件/usr/local/apache2.4/conf/httpd.conf
配置文件可隨用隨取,被註釋掉的模塊都不會顯示,也不會加載該模塊。
cd /usr/local/src/ wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar jxvf php-7.1.6.tar.bz2
./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
注:一個機器中能夠同時安裝兩個PHP,可是要配置好Apache調用哪個PHP,避免混亂,可去Apache的配置文件/usr/local/apache2.4/conf/httpd.conf中進行修改