nginx服務器怎么從php5.5.7升級到php7

小編給大家分享一下nginx服務器怎么從php5.5.7升級到php7,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)公司主要從事網(wǎng)頁設計、PC網(wǎng)站建設(電腦版網(wǎng)站建設)、wap網(wǎng)站建設(手機版網(wǎng)站建設)、自適應網(wǎng)站建設、程序開發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、小程序定制開發(fā)等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設行業(yè)積累了豐富的成都網(wǎng)站設計、網(wǎng)站建設、外貿(mào)網(wǎng)站建設、網(wǎng)站設計、網(wǎng)絡營銷經(jīng)驗,集策劃、開發(fā)、設計、營銷、管理等多方位專業(yè)化運作于一體。

①、服務器nginx 、php 、MySQL都是安裝好的,于是想直接升級php7.

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

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

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

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

1 創(chuàng)建php用戶和用戶組,并在github下載php7源碼

首先創(chuàng)建一個名為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編譯參數(shù)的配置(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和內(nèi)存消耗,PHP7的編譯安裝輕松多了,整個過程大約1個小時左右。

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

看到下圖就代表已經(jīng)編譯安裝好了PHP7?。╬s:編譯過程中出現(xiàn)錯誤。 undefined reference to `libiconv_open 無法編譯PHP;

解決方法詳情見上面鏈接:編輯 Makefile 大約 77 行左右的地方:

EXTRA_LIBS = ..... -lcrypt

在最後加上 -liconv,例如:

EXTRA_LIBS = ..... -lcrypt -liconv

再運行make就可以了。)

4 選做步驟:執(zhí)行make test命令進行測試

這是一個非必需的操作步驟,執(zhí)行make test命令。有趣的一件事就是:在test期間,會和一個IP地址72.52.91.14建立tcp連接,它對應著php官網(wǎng)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這兩個動態(tài)庫文件,如下圖所示。

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服務控制腳本。

#######方法一:直接使用編譯后未經(jīng)優(yōu)化處理的配置
[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的環(huán)境變量

將php編譯生成的bin目錄添加到當前Linux系統(tǒng)的環(huán)境變量中

[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,并創(chuàng)建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進程數(shù)和進程用戶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的時候出現(xiàn)如下錯誤:

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

解決方法:

yum install libxslt-devel* -y

以上是“nginx服務器怎么從php5.5.7升級到php7”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

新聞名稱:nginx服務器怎么從php5.5.7升級到php7
當前URL:http://muchs.cn/article22/ihjccc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、Google網(wǎng)站排名、外貿(mào)建站企業(yè)建站、面包屑導航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管