安裝 PHP5

安裝 PHP5

安裝方法大同小異,首先下載5.6的安裝包,使用到的命令如下:
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.36.tar.gz
tar -zxvf php-5.6.36.tar.gz
cd php-5.6.36/
./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

安裝 PHP5
安裝包 php-5.6.36.tar.gz 下載完畢,然後進行解壓,輸入命令 tar -zxvf php-5.6.36.tar.gz,回車,內容較多,不截圖。然後進行編譯,見下圖,
安裝 PHP5
回車,內容較多,截取最後一屏,見下圖,
安裝 PHP5
出現報錯,configure: error: xml2-config not found. Please check your libxml2 installation. 顯示需要安裝 libxml2,具體操作見下圖,
安裝 PHP5
安裝 PHP5
安裝完成之後,繼續輸入剛纔的命令 ./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 ,回車,
安裝 PHP5
又出現報錯,configure: error: Cannot find OpenSSL's <evp.h>,顯示需要安裝 openssl-devel,輸入命令 yum install -y openssl-devel,回車。內容較多,不截圖了。安裝完成之後,繼續執行命令 ./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 ,回車,
安裝 PHP5
又出現報錯,configure: error: Please reinstall the BZip2 distribution,顯示需要安裝 bzip2-devel 這個包,輸入命令 yum install -y bzip2-devel,回車,
安裝 PHP5
安裝完成之後,再次執行命令,見下圖,
安裝 PHP5
又出現報錯,configure: error: jpeglib.h not found. 顯示需要安裝 libjpeg-devel 這個包,輸入命令 yum install -y libjpeg-devel,回車,
安裝 PHP5
安裝完成之後,再次執行命令,見下圖,
安裝 PHP5
又出現報錯,configure: error: png.h not found. 顯示需要安裝 libpng-devel 這個包,輸入命令 yum install -y libpng-devel,回車,
安裝 PHP5
安裝完成之後,再次執行命令,見下圖,
安裝 PHP5
又出現報錯,configure: error: freetype-config not found. 顯示需要安裝 freetype-devel 這個包,輸入命令 yum install -y freetype-devel,回車,
安裝 PHP5
安裝 PHP5
安裝完成之後,再次執行命令,見下圖,
安裝 PHP5
又出現報錯,configure: error: mcrypt.h not found. Please reinstall libmcrypt. 顯示需要安裝 libmcrypt-devel 這個包,安裝這個包之前,需要先安裝一個擴展源,輸入命令 yum install -y epel-release,回車,顯示已安裝,接着輸入命令 yum install -y libmcrypt-devel,回車,
安裝 PHP5
安裝 PHP5
安裝完成之後,再次執行命令,見下圖,
安裝 PHP5
可以看到,這次就成功了,沒有出現報錯。使用命令 echo $? 查看,是對的。接着使用 make 命令,見下圖,
安裝 PHP5
make 這個命令需要執行的時間比較長,沒有出現錯誤,就執行命令 make install ,回車,
安裝 PHP5
安裝 PHP5
接着來看一下 PHP 的目錄,見下圖,
安裝 PHP5
核心的二進制文件在目錄 /usr/local/php/bin/ 下面,裏面的 php 文件大小是36M,很大。再查看文件 /usr/local/apache2.4/modules/libphp5.so 的大小也是36M,這個就是我們想要的擴展模塊。接着來查看一下php所加載的模塊有哪些,見下圖,
安裝 PHP5
查看所加載的模塊的命令,全部都是靜態的,也能夠擴展模塊安裝。
安裝 PHP5
回車,進入文件httpd.conf,可以看到很多#註釋的模塊,
安裝 PHP5
這邊比較方便的地方是,想啓用模塊,就把前面的#去掉並保存。想停掉模塊,就在前面加上#保存。輸入 :q!,回車強行退出。
接着可以輸入命令 /usr/local/php/bin/php -i |less,回車查看,
安裝 PHP5
可以看到一些 php 的信息。
因爲目錄 /usr/local/php/etc 下面沒有 php.ini 文件,所以需要在php源碼包的根目錄下拷貝,見下圖,
安裝 PHP5
回車,
安裝 PHP5
這時候就能看到,/usr/local/php/etc/php.ini 加載上去了,可以對前面沒有加載的圖片,顯示的是 none 。

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