linux下編譯安裝php7(兼容現有的php5.6版本)


1.首先去php官網下載一個php7版本源碼包 http://php.net/downloads.php,我這下載的是php7.2.13版本. 

2.使用ftp或者linux的rz命令將包上傳到linux下,開始進行編譯安裝.

3.解壓安裝包

# tar -zxvf   php-7.2.13.tar.gz

# cd php-7.2.13

#./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache

執行以上編譯會出現報錯

1.configure: error: jpeglib.h not found.

解決:yum -y install libjpeg-devel .

2.configure: error: png.h not found.

解決:#yum install libpng 

 # yum install libpng-devel

3.configure: error: freetype-config not found.

解決:# yum install freetype-devel

然后再次執行上面命令會出現:

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+

Thank you for using PHP.

表示配置文件檢測成功,下面開始執行編譯且安裝

# make && make install  

至此php7.2.13就安裝完成 .

安裝完成在/usr/local下會出現php7目錄

# cd /usr/local/php7/etc下

首先復制出一份php-fpm.conf

#cp php-fpm.conf.default php-fpm.conf

切換到/usr/local/php7/etc/php-fpm.d復制配置文件

#cp www.conf.default www.conf

為了兼容php5.6所以需要配置php7的監聽端口為9001 (我的php5.6監聽端口為9000)

# vim  /usr/local/php7/etc/php-fpm.d/www.conf  找到:

listen = 127.0.0.1:9000

將其端口修改為 

listen = 127.0.0.1:9001

:wq 保存編輯退出. 

然后配置nginx或apache支持php7即可.

-----------------  Nginx 支持php7配置文件如下 ----------------------

server {
listen 8888;  配置項目訪問端口 (如果無其他項目也可使用默認的80端口)

location / {
root /data/laravel/public;  #項目路徑
index index.html index.htm index.php;

# 項目配置重寫
if (!-e $request_filename) {
rewrite ./index.php last;
}
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
root /data/laravel/public;   #項目路徑 
fastcgi_pass 127.0.0.1:9001;  #監聽端口為9001  
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

    }

}

1.重啟nginx

# /usr/local/nginx/sbin/nginx -s reload

2.重啟php7

# /usr/local/php7/sbin/php-fpm

完成以上步驟后:

---->訪問:http://你的域名:8888 出現配置項目顯示頁面或者可使用phpinfo()測試信息頁則表示配置nginx+php7成功。

至此可以開啟你的php7之旅。

以上僅為個人安裝參考,如有問題可留言交流。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM