Home > Backend Development > PHP7 > body text

How to upgrade nginx server from php5.5.7 to php7?

醉折花枝作酒筹
Release: 2023-02-18 06:24:01
forward
2396 people have browsed it

This article will introduce to you how to upgrade the nginx server from php5.5.7 to php7? Methods. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to upgrade nginx server from php5.5.7 to php7?

① The server nginx, php, and mysql are all installed, so I want to upgrade php7 directly.

②Follow the article: https://typecodes .com/web/centos7compilephp7.html?utm_source=tuicool&utm_medium=referral During the operation, something different appeared in the middle.

③Problem solving reference: http://blog.chinaunix.net/uid-25266990-id-2915395.html

Separating line------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------

I will repost step 2 below for my own use.

1 Create a php user and user group, and download the php7 source code from github

First create a user named php without login permissions and a user group named php, and then go to GitHub Download the php7 source code package.

#######新建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
Copy after login
2 Configuration of PHP7 compilation parameters (ps: I will post the slashes below, you can copy them directly)

After the preparations are completed, start to formally configure the installation details of php7 . Note that when operating, be sure to remove the comment text added after the backslash "\" below! ! !

######开始生成配置文件
[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
Copy after login
./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
Copy after login
3 Start compiling and installing PHP7

Compared with compiling and installing MySQL, which consumes a lot of CPU and memory, compiling and installing PHP7 is much easier, and the whole process takes about an hour.

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

Seeing the picture below means that PHP7 has been compiled and installed! (ps: An error occurred during compilation. Undefined reference to `libiconv_open cannot compile PHP;

For details of the solution, see the link above: Edit the Makefile at about line 77:

EXTRA_LIBS = .. ... -lcrypt

Add -liconv at the end, for example:

EXTRA_LIBS = ..... -lcrypt -liconv

and then run make. )

4 Optional step: execute the make test command to test

This is an optional step, execute the make test command. An interesting thing is: During the test, a TCP connection will be established with an IP address 72.52.91.14, which corresponds to the official PHP website http://www.php.net.

5 Check the PHP7 installation directory after successful compilation

Since you need to communicate with MySQL, you need to specifically check the lib extension library directory after PHP7 is installed (/usr/local/php7/lib/ php/extensions/no-debug-non-zts-20141001/). You need to ensure that at least two dynamic library files mysqli.so and pdo_mysql.so exist, as shown in the figure below.

6 Start setting up the PHP7 configuration files php.ini, php-fpm.conf, www.conf and php-fpm scripts

You can copy the compiled configuration file to the PHP7 configuration directory (/usr/local/php7/etc/), it is recommended to use the three PHP7 configuration files and the php-fpm service control script compiled in the article "Configuration of php.ini, php-fpm and www.conf in PHP7".

#######方法一:直接使用编译后未经优化处理的配置
[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
Copy after login
7 Add the environment variable of php

Add the bin directory generated by php compilation to the environment variable of the current Linux system

[root@typecodes ~]# echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
Copy after login
8 Set the PHP log directory and php- fpm process file (php-fpm.sock) directory

Among them, set the user and user group of the php-fpm process directory to nginx, and create a php session session directory.

#######设置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
Copy after login
9 Set up PHP startup and test whether the configuration file is correct
######配置开机自启动,增加到主机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
Copy after login
10 Start the php service

After completing the above operations, you can officially use the php service. The command to start the php process service is as follows:

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

Then you can check whether it is successful through the command ps -aux|grep php (the number of php-fpm processes and the process user nginx in the picture are both determined by pm in www.conf. The values ​​of start_servers and user are determined respectively):

11 View PHP7 version information

Finally, you can view the current PHP version information through the command php -v. You can see in the figure that the current PHP7 version information is also used The Zend OPcache cache is disabled because the zend_extension=opcache.so configuration is added to the php.ini file.

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

The following error occurs when compiling and installing PHP

./configure :

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

Solution:

yum install libxslt-devel* - y

Recommended learning: php video tutorial

The above is the detailed content of How to upgrade nginx server from php5.5.7 to php7?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template