Home  >  Article  >  Backend Development  >  Upgrading PHP5 to PHP7 under Centos

Upgrading PHP5 to PHP7 under Centos

angryTom
angryTomforward
2019-10-16 11:49:172977browse

Upgrading PHP5 to PHP7 under Centos

1. First download the PHP7 installation package

Use wget http://am1.php. net/distributions/php-7.2.0.tar.bz2, or access the download directly, and then ftp to the linux server

2. Unzip the compressed package

tar –xjf php-7.0.2.tar.bz2

3. Enter the folder, cd php-7.0.2, and install the necessary dependency tools,

yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel这里主要是升级,一般在php5都安装了,所以这一步可以省略

4. Install several dependencies (must be installed, otherwise it cannot be generated later libphp7.so file used by apache)

yum -y install perl
yum –y install perl-devel
yum -y install httpd-devel
find /usr  -name apxs 取得所用路径,后面编译时用到。

5. Prepare for compilation

./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath -enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-pcntl --with-curl --with-fpm-user=nginx --enable-ftp --enable-session --enable-xml --with-apxs2=/usr/bin/apxs
**注意:其中的 –enable-gd-native-ttf 可以不安装,处理图形用的,如果有需求可以以后以扩展形式装

–with-apxs2=/usr/bin/apxs Change the following path to the path obtained in step 4

–prefix=/usr/local/php7 Install it separately in the php7 folder to avoid conflicts with php5**

6. Compile

make

This step is prone to many problems,

If Encountered for example: undefine. . . .

/ext/cli./php …

Openssl

and other errors, and make sure that the relevant modules are installed, generally clear the previous compilation and delete the relevant files. Recompiling

make clean
rm –rf /usr/local/php7

usually solves the problem.

For other errors, please refer to this blog:

http://www.cnblogs.com/sweetXiaoma/p/5855732.html

http://www.linuxidc.com/Linux/2017-08/146220.htm

The key is to solve it yourself. There are too many Linux distributions and the environment configuration of each server is different. Different, so you will encounter many strange problems.

7. Installation

Make install

8. Prepare configuration file

cp php.ini-developement /etc/php.ini   //根据实际情况,可以使用production或者development默认配置
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

9. Need to modify apache configuration File

Vi /etc/httpd/conf/httpd.conf Find LoadModule php7_module modules/libphp7.so. If it is not added manually,

Change LoadModule php5_module modules/libphp5.so Comment out

cp /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf_5

Vi /etc/httpd/conf.d/php .conf

Change to the following: (Comment out the ones related to php5 and change to php7 related modules)

<IfModule prefork.c>
  LoadModule php7_module modules/libphp7.so
</IfModule>
<Files ".user.ini">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
</IfModule>
</Files>
DirectoryIndex index.php
# mod_php options
<IfModule  mod_php7.c>
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
</FilesMatch>
    php_value session.save_handler "files"
    php_value session.save_path    "/var/lib/php/session"
    php_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"
</IfModule>

10. Restart the apache server

service httpd restart

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of Upgrading PHP5 to PHP7 under Centos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete