搜尋
首頁後端開發PHP7nginx伺服器如何從php5.5.7升級到php7?

這篇文章要跟大家介紹nginx伺服器從php5.5.7升級到php7?的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有幫助。

nginx伺服器如何從php5.5.7升級到php7?

①、伺服器nginx 、php 、mysql都是安裝好的,所以我想直接升級php7.

②依照文章:https://typecodes .com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral 進行操作,中途出現一些不一樣的地方。

③問題解決參考:http://blog.chinaunix.net/uid-25266990-id-2915395.html  

#分割線------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------

下面會將步驟2,自己使用的重新貼出來。

1 建立php使用者和使用者群組,並在github下載php7原始碼

#先建立一個名為php且沒有登入權限的使用者和一個名為php的使用者群組,然後去GitHub下載php7原始碼包。

#######新建php用户和php组
[root@typecodes ~]# groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
######从GitHub下载php7安装包
[root@typecodes ~]# wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zip
######开始解压php7包
[root@typecodes ~]# unzip -q php7-src-master.zip && cd php-src-master
#####安装编译php7时需要的依赖包
[root@typecodes php-src-master]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
2 PHP7編譯參數的設定(ps:下面我會貼出去掉斜線的,可以直接複製)

準備工作做好後,就開始正式設定php7的安裝明細了。注意,操作時一定要先把下面反斜線「\」後面加上的註解文字去掉! ! !

######开始生成配置文件
[root@typecodes php-src-master]# ./buildconf
buildconf: checking installation...
buildconf: autoconf version 2.69 (ok)
rebuilding aclocal.m4
rebuilding configure
rebuilding main/php_config.h.in
######开始配置
[root@typecodes php-src-master]# ./configure \
--prefix=/usr/local/php7 \                              [PHP7安装的根目录]
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \           [PHP7的配置目录]
--with-mysql-sock=/var/run/mysql/mysql.sock \           [PHP7的Unix socket通信文件]
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysql=shared,mysqlnd \                           [PHP7依赖mysql库]              
--with-mysqli=shared,mysqlnd \                          [PHP7依赖mysql库]
--with-pdo-mysql=shared,mysqlnd \                       [PHP7依赖mysql库]
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \                                      [允许php会话session]
--with-curl \                                           [允许curl扩展]
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \                                      [使用opcache缓存]
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=nginx \                                 [php-fpm的用户]
--with-fpm-group=nginx \                                [php-fpm的用户组]
--without-gdbm \
--disable-fileinfo
./configure
--prefix=/usr/local/php7 
--exec-prefix=/usr/local/php7
--bindir=/usr/local/php7/bin 
--sbindir=/usr/local/php7/sbin 
--includedir=/usr/local/php7/include 
--libdir=/usr/local/php7/lib/php 
--mandir=/usr/local/php7/php/man 
--with-config-file-path=/usr/local/php7/etc         
--with-mysql-sock=/var/run/mysql/mysql.sock 
--with-mcrypt=/usr/include 
--with-mhash 
--with-openssl 
--with-mysql=shared,mysqlnd   
--with-mysqli=shared,mysqlnd 
--with-pdo-mysql=shared,mysqlnd 
--with-gd 
--with-iconv 
--with-zlib 
--enable-zip 
--enable-inline-optimization 
--disable-debug 
--disable-rpath 
--enable-shared 
--enable-xml 
--enable-bcmath 
--enable-shmop 
--enable-sysvsem 
--enable-mbregex 
--enable-mbstring 
--enable-ftp 
--enable-gd-native-ttf 
--enable-pcntl 
--enable-sockets 
--with-xmlrpc 
--enable-soap 
--without-pear 
--with-gettext 
--enable-session 
--with-curl                                        
--with-jpeg-dir 
--with-freetype-dir 
--enable-opcache                                  
--enable-fpm 
--enable-fastcgi 
--with-fpm-user=nginx                                
--with-fpm-group=nginx                                 
--without-gdbm 
--disable-fileinfo
3 開始編譯和安裝PHP7

相對編譯安裝MySQL的大量CPU和記憶體消耗,PHP7的編譯安裝輕鬆多了,整個過程大約1個小時左右。

[root@typecodes php-src-master]# make clean && make && make install

看到下圖就代表已經編譯安裝好了PHP7! (ps:編譯過程中出現錯誤。 undefined reference to `libiconv_open 無法編譯PHP;

解決方法詳情請參閱上方連結:編輯Makefile 大約77 行左右的地方:

EXTRA_LIBS = .. ... -lcrypt

在最後加上-liconv,例如:

EXTRA_LIBS = ..... -lcrypt -liconv

再執行make就可以了。 )

4 選做步驟:執行make test指令進行測試

這是一個非必要的操作步驟,執行make test指令。有趣的一件事是:在test期間,會和一個IP位址72.52.91.14建立tcp連接,它對應著php官網http://www.php.net。

5 查看編譯成功後的PHP7安裝目錄

由於需要和MySQL進行通信,所以需要特別查看PHP7安裝後的lib擴充庫目錄(/usr/local/php7/lib/ php/extensions/no-debug-non-zts-20141001/)。需要確保至少存在mysqli.so、pdo_mysql.so這兩個動態庫文件,如下圖所示。

6 開始設定PHP7的設定檔php.ini、php-fpm.conf、www.conf和php-fpm腳本

可以用編譯後的設定檔複製到PHP7的設定目錄(/usr/local/php7/etc/),建議使用《PHP7中php.ini、php-fpm和www.conf的設定》文中整理的3個PHP7設定檔和php-fpm服務控制腳本。

#######方法一:直接使用编译后未经优化处理的配置
[root@typecodes php-src-master]# cp php.ini-production /usr/local/php7/etc/php.ini
[root@typecodes php-src-master]# cp /root/php-src-master/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@typecodes php-src-master]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#######方法二:使用https://typecodes.com/web/php7configure.html文中的配置 
[root@typecodes php-src-master]# mv ~/php.ini /usr/local/php7/etc/php.ini && mv ~/php-fpm /etc/init.d/php-fpm
[root@typecodes php-src-master]# mv ~/php-fpm.conf /usr/local/php7/etc/php-fpm.conf && mv ~/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
7 新增php的環境變數

將php編譯產生的bin目錄加入到目前Linux系統的環境變數

[root@typecodes ~]# echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
8 設定PHP日誌目錄和php- fpm進程檔案(php-fpm.sock)目錄

其中,設定php-fpm進程目錄的使用者和使用者群組為nginx,並建立php會話session目錄。

#######设置PHP日志目录和php-fpm的运行进程ID文件(php-fpm.sock)目录
[root@typecodes ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
#######修改session的目录配置
[root@typecodes etc]# mkdir -p /var/lib/php/session
[root@typecodes etc]# chown -R nginx:nginx /var/lib/php
9 設定PHP開機啟動以及測試設定檔是否正確
######配置开机自启动,增加到主机sysV服务
[root@typecodes php-src-master]# chmod +x /etc/init.d/php-fpm
[root@typecodes php-src-master]# chkconfig --add php-fpm
[root@typecodes php-src-master]# chkconfig php-fpm on
######测试PHP的配置文件是否正确合法
[root@typecodes sbin]# php-fpm -t
[03-May-2015 17:50:04] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful
10 啟動php服務

在完成上面的操作後,就可以正式使用php服務了。啟動php進程服務的命令如下:

[root@typecodes sbin]# service php-fpm start
Starting php-fpm  done

然後可以透過命令ps -aux|grep php查看是否成功(圖中的php-fpm進程數和進程用戶nginx都是由www.conf中pm. start_servers和user的值分別決定的):

11 查看PHP7版本資訊

最後,可以透過指令php -v查看目前PHP版本信息,圖中可以看到目前PHP7也使用了Zend OPcache緩存,是因為在php.ini檔案中加入了zend_extension=opcache.so配置。

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

PHP編譯安裝

./configure的時候出現如下錯誤:

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

# 解決方法:

yum install libxslt-devel* -

解決方法:

yum install libxslt-devel* - y

推薦學習:###php影片教學#######

以上是nginx伺服器如何從php5.5.7升級到php7?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:CSDN。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用