如何将nginx服务器上的php5.5.7版本升级至php7?

更新于
2026-09-27 20:03:40
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1443个文字,预计阅读时间需要6分钟。

如何将nginx服务器上的php5.5.7版本升级至php7?

本篇文章将简要介绍如何将Nginx服务器从PHP 5.5.7升级到PHP 7。以下是一些建议和步骤,希望能对您有所帮助。

1. 备份环境:在开始升级之前,请确保备份好您的网站数据、配置文件等,以防万一升级过程中出现问题。

2. 更新Nginx: - 使用包管理器更新Nginx,例如在Ubuntu上使用`sudo apt-get update`和`sudo apt-get install nginx`。 - 如果使用源码安装,请下载最新版本的Nginx源码,编译安装。

3. 升级PHP: - 同样使用包管理器更新PHP,例如在Ubuntu上使用`sudo apt-get install php7.0`。 - 如果使用源码安装,请下载PHP 7源码,编译安装。

4. 配置Nginx: - 编辑Nginx配置文件,确保PHP模块已加载。 - 例如,在`/etc/nginx/nginx.conf`中添加或修改以下行: location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } - 重启Nginx服务以应用更改。

如何将nginx服务器上的php5.5.7版本升级至php7?

5. 配置PHP: - 编辑PHP配置文件(如`/etc/php/7.0/cli/conf.d/20-handlers.ini`),确保正确配置了扩展和参数。 - 例如,启用OPcache: opcache.enable=1 opcache.enable_cli=1

6. 测试和调试: - 测试您的网站以确保所有功能正常。 - 如果出现错误,检查日志文件(如`/var/log/nginx/error.log`和`/var/log/php-fpm/error.log`)以获取错误信息。

7. 性能优化: - 考虑使用OPcache等工具优化PHP性能。 - 优化Nginx和PHP配置以提高响应速度。

希望这些建议能对您有所帮助!如果您有其他问题或需要进一步的帮助,请随时提问。

本篇文章给大家介绍一下nginx服务器从php5.5.7升级到php7?的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

①、服务器nginx 、php 、mysql都是安装好的,于是想直接升级php7.

②按照文章:typecodes.com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral 进行操作,中途出现一些不一样的地方。

③问题解决参考: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 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官网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/),

本文共计1443个文字,预计阅读时间需要6分钟。

如何将nginx服务器上的php5.5.7版本升级至php7?

本篇文章将简要介绍如何将Nginx服务器从PHP 5.5.7升级到PHP 7。以下是一些建议和步骤,希望能对您有所帮助。

1. 备份环境:在开始升级之前,请确保备份好您的网站数据、配置文件等,以防万一升级过程中出现问题。

2. 更新Nginx: - 使用包管理器更新Nginx,例如在Ubuntu上使用`sudo apt-get update`和`sudo apt-get install nginx`。 - 如果使用源码安装,请下载最新版本的Nginx源码,编译安装。

3. 升级PHP: - 同样使用包管理器更新PHP,例如在Ubuntu上使用`sudo apt-get install php7.0`。 - 如果使用源码安装,请下载PHP 7源码,编译安装。

4. 配置Nginx: - 编辑Nginx配置文件,确保PHP模块已加载。 - 例如,在`/etc/nginx/nginx.conf`中添加或修改以下行: location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } - 重启Nginx服务以应用更改。

如何将nginx服务器上的php5.5.7版本升级至php7?

5. 配置PHP: - 编辑PHP配置文件(如`/etc/php/7.0/cli/conf.d/20-handlers.ini`),确保正确配置了扩展和参数。 - 例如,启用OPcache: opcache.enable=1 opcache.enable_cli=1

6. 测试和调试: - 测试您的网站以确保所有功能正常。 - 如果出现错误,检查日志文件(如`/var/log/nginx/error.log`和`/var/log/php-fpm/error.log`)以获取错误信息。

7. 性能优化: - 考虑使用OPcache等工具优化PHP性能。 - 优化Nginx和PHP配置以提高响应速度。

希望这些建议能对您有所帮助!如果您有其他问题或需要进一步的帮助,请随时提问。

本篇文章给大家介绍一下nginx服务器从php5.5.7升级到php7?的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

①、服务器nginx 、php 、mysql都是安装好的,于是想直接升级php7.

②按照文章:typecodes.com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral 进行操作,中途出现一些不一样的地方。

③问题解决参考: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 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官网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/),