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中文網其他相關文章!

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

解決 PHP 7.0 中插件未顯示已安裝問題的方法:檢查插件配置並啟用插件。重新啟動 PHP 以套用配置變更。檢查插件檔案權限,確保其正確。安裝遺失的依賴項,以確保插件正常運作。如果其他步驟都失敗,則重建 PHP。其他可能原因包括外掛程式版本不相容、載入錯誤版本或 PHP 配置問題。

在php5中,我們可以使用fsockopen()函數來偵測TCP埠。這個函數可以用來開啟一個網路連接和進行一些網路通訊。但是在php7中,fsockopen()函數可能會遇到一些問題,例如無法開啟連接埠、無法連接到伺服器等。為了解決這個問題,我們可以使用socket_create()函數和socket_connect()函數來偵測TCP埠。

php7.0安裝mongo擴充的方法:1、建立mongodb使用者群組和使用者;2、下載mongodb原始碼包,並將原始碼包放到“/usr/local/src/”目錄下;3、進入“src/”目錄;4、解壓縮原始碼包;5、建立mongodb檔案目錄;6、將檔案複製到「mongodb/」目錄;7、建立mongodb設定檔並修改設定即可。

PHP伺服器環境常見的解決方法包括:確保已安裝正確的PHP版本和已複製相關檔案到模組目錄。暫時或永久停用SELinux。檢查並配置PHP.ini,確保已新增必要的擴充功能和進行正確設定。啟動或重新啟動PHP-FPM服務。檢查DNS設定是否有解析問題。

php7.0安裝部署的方法:1、到PHP官網下載與本機系統對應的安裝版本;2、將下載的zip檔案解壓縮到指定目錄;3、開啟命令列窗口,在「E:\php7」目錄下運行“php -v”命令即可。

如何在系統重啟後自動設置unixsocket的權限每次系統重啟後,我們都需要執行以下命令來修改unixsocket的權限:sudo...

PHP8相較於PHP7在效能、新特性和語法改進、型別系統、錯誤處理和擴充等方面都有一些優勢和改進。然而,選擇使用哪個版本要根據特定的需求和專案情況來決定。詳細介紹:1、效能提升,PHP8引進了Just-in-Time(JIT)編譯器,可以提高程式碼的執行速度;2、新特性和語法改進,PHP8支援命名參數和可選參數的聲明,使得函數呼叫更加靈活;引入了匿名類別、屬性的類型聲明等等。

在Docker環境中使用PECL安裝擴展時報錯的原因及解決方法在使用Docker環境時,我們常常會遇到一些令人頭疼的問�...
