大致步驟:下載–解壓–編譯–安裝–配置
php官網:
https://www.php.net/releases/php5.6連接地址
http://hk1.php.net/get/php-5.6.36.tar.gz/from/this/mirror
http://hk2.php.net/get/php-5.6.36.tar.gz/from/this/mirror
1.安裝php 所依賴的軟件
yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcur
其中livxml2為讓php支持xml格式的輸出,libmcrypt讓php支持加密功能,bzip2讓php支持壓縮功能,freetype讓php支持多種字體
報錯:Centos安裝PHP時,安裝php依賴包時yum install libmcrypt libmcrypt-devel,報錯如下:
No package libmcrypt available. No package libmcrypt-devel available. Error: Nothing to do
然后編譯的時候,又報錯:
checking for mcrypt support... yes configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決方法:
yum? install epel-release? //擴展包更新包,然后重新執行命令即可
yum install libmcrypt libmcrypt-devel mcrypt mhash //就ok了
2.下載php源碼包解壓進入
下載解壓
wget http://hk1.php.net/get/php-7.3.3.tar.gz/from/this/mirror # 下載
tar -zxvf mirror # 解壓
cd mirror # 進入
然后配置?
./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-mbstring --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d --with-bz2##### 參數說明
--prefix 指明安裝路徑
--with-mysql 指明依賴的mysql的路徑,5.3后可不安裝mysql,使用參數mysqlnd
--with-openssl 指明依賴的openssl,用于支持ssl通信
--with-mysqli 指明依賴的mysqli,mysqli是mysql的另外一個訪問接口
--with-freetype-dir 用于支持顯示的字體,可能會要安裝freetype-devel
--with-png-dir 用于顯示支持png格式的圖片
--with-jpeg-dir 用于顯示支持jpeg格式的圖片
--enable-mbstring 用于讓mysql支持中文
--with-zlib 用于支持壓縮功能
--with-libxml 用于分析xml格式
--enable-xml 表示支持xml
--enable-sockets 表示支持以sockets方式進行通信
--with-apxs2 指明apxs文件的路徑,apxs文件作用是第三方模塊可以借助該文件與httpd建立關聯關系相當于一個銜接器的作用,如果使用fpm模式,需要去掉
--enable-fpm 如果httpd與php結合的方式為php-fpm,則需要將--with-apxs2=/usr/local/apache24/bin/apxs去掉,然后啟用--enable-fpm選項
--with-mcrypt 表示支持加密庫
--with-config-file-path=/etc 表示配置文件的存放路徑
--with-config-file-scan-dir=/etc/php.d 表示還要掃描哪個目錄下的.ini結尾的文件作為配置文件的組成部分
--with-bz2 表示支持bz2壓縮
--enable-maintainer-zts 當啟用的MPM為worker或event時,需要啟動該選項,因為此處我們是以prefork的MPM,所以不用此項
--with 之類的選項,會到對應依賴的文件的默認安裝路徑下去尋找,如果程序不是安裝在默認路徑下,則需要用=等號指定位置,如果沒有安裝對應程序,則需要手動安裝,一般編譯時用到的程序是程序的devel包
最后編譯安裝
make && make install
3.添加相關配置文件
#配置文件
# cp php.ini-development /etc/php.ini#php-fpm 服務,并設為開機啟動
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php//etc/php-fpm.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm# chkconfig --add php-fpm
# chkconfig on php-fpm
# service php-fpm start
1、php
(1)命令位置:/usr/local/php/bin/php
(2)配置文件位置:/etc/php.ini2、php-fpm
(1)命令位置:/usr/local/php/sbin/php-fpm
(2)配置文件位置:/usr/local/php/etc/php-fpm.conf
修改環境變量
# vim /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
# source /etc/profile
修改nginx配置文件
#php腳本請求全部轉發給FastCGI處理location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
?
?