溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

nginx服務(wù)器怎么從php5.5.7升級(jí)到php7

發(fā)布時(shí)間:2021-06-15 09:39:34 來(lái)源:億速云 閱讀:146 作者:小新 欄目:編程語(yǔ)言

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

①、服務(wù)器nginx 、php 、mysql都是安裝好的,于是想直接升級(jí)php7.

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

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

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

下面會(huì)將步驟2,自己使用的重新貼出來(lái)。

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

首先創(chuàng)建一個(gè)名為php且沒(méi)有登錄權(quán)限的用戶和一個(gè)名為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時(shí)需要的依賴包
[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:下面我會(huì)貼出去掉斜杠的,可以直接復(fù)制)

準(zhǔn)備工作做好后,就開始正式配置php7的安裝明細(xì)了。注意,操作時(shí)一定要先把下面反斜杠“\”后面添加的注釋文字去掉?。?!

######開始生成配置文件
[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安裝的根目錄](méi)
--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的配置目錄](méi)
--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庫(kù)]              
--with-mysqli=shared,mysqlnd \                          [PHP7依賴mysql庫(kù)]
--with-pdo-mysql=shared,mysqlnd \                       [PHP7依賴mysql庫(kù)]
--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會(huì)話session]
--with-curl \                                           [允許curl擴(kuò)展]
--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

相對(duì)編譯安裝MySQL的大量CPU和內(nèi)存消耗,PHP7的編譯安裝輕松多了,整個(gè)過(guò)程大約1個(gè)小時(shí)左右。

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

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

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

EXTRA_LIBS = ..... -lcrypt

在最後加上 -liconv,例如:

EXTRA_LIBS = ..... -lcrypt -liconv

再運(yùn)行make就可以了。)

4 選做步驟:執(zhí)行make test命令進(jìn)行測(cè)試

這是一個(gè)非必需的操作步驟,執(zhí)行make test命令。有趣的一件事就是:在test期間,會(huì)和一個(gè)IP地址72.52.91.14建立tcp連接,它對(duì)應(yīng)著php官網(wǎng)http://www.php.net。

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

由于需要和MySQL進(jìn)行通信,所以需要特別查看PHP7安裝后的lib擴(kuò)展庫(kù)目錄(/usr/local/php7/lib/php/extensions/no-debug-non-zts-20141001/)。需要確保至少存在mysqli.so、pdo_mysql.so這兩個(gè)動(dòng)態(tài)庫(kù)文件,如下圖所示。

6 開始設(shè)置PHP7的配置文件php.ini、php-fpm.conf、www.conf和php-fpm腳本

可以用編譯后的配置文件復(fù)制到PHP7的配置目錄(/usr/local/php7/etc/),推薦使用《PHP7中php.ini、php-fpm和www.conf的配置》文中整理的3個(gè)PHP7配置文件和php-fpm服務(wù)控制腳本。

#######方法一:直接使用編譯后未經(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目錄添加到當(dāng)前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 設(shè)置PHP日志目錄和php-fpm進(jìn)程文件(php-fpm.sock)目錄

其中,設(shè)置php-fpm進(jìn)程目錄的用戶和用戶組為nginx,并創(chuàng)建php會(huì)話session目錄。

#######設(shè)置PHP日志目錄和php-fpm的運(yùn)行進(jìn)程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 設(shè)置PHP開機(jī)啟動(dòng)以及測(cè)試配置文件是否正確
######配置開機(jī)自啟動(dòng),增加到主機(jī)sysV服務(wù)
[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
######測(cè)試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 啟動(dòng)php服務(wù)

在完成上面的操作后,就可以正式使用php服務(wù)了。啟動(dòng)php進(jìn)程服務(wù)的命令如下:

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

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

11 查看PHP7版本信息

最后,可以通過(guò)命令php -v查看當(dāng)前PHP版本信息,圖中可以看到當(dāng)前PHP7還使用了Zend OPcache緩存,是因?yàn)樵趐hp.ini文件中添加了zend_extension=opcache.so配置。

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

PHP編譯安裝

./configure的時(shí)候出現(xiàn)如下錯(cuò)誤:

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

解決方法:

yum install libxslt-devel* -y

以上是“nginx服務(wù)器怎么從php5.5.7升級(jí)到php7”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI