Home >Backend Development >PHP Tutorial >How to upgrade PHP5 to PHP7 under Centos

How to upgrade PHP5 to PHP7 under Centos

尚
forward
2020-03-06 09:46:423397browse

How to upgrade 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 visit the download directly, and then Ftp to linux server

Recommended: "php training"

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 dependent 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

The main purpose here is to upgrade, which is usually installed in php5, so this step can be omitted

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

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

**Note: –enable -gd-native-ttf does not need to be installed. It is used for graphics processing. If necessary, it can be installed in an extended form later

–with-apxs2=/usr/bin/apxs. Change the subsequent path to step 4 to obtain The path

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

6. Compile

make

This step is easy There are many problems,

If you encounter, for example: undefine. . . .

/ext/cli./php …
Openssl

and other errors, and make sure that the relevant modules are installed, generally clearing the previous compilation, deleting the relevant files and recompiling

make clean
rm –rf /usr/local/php7

can generally solve the problem.

7. Installation

Make install

8. Prepare the 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 the apache configuration file

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

Comment out LoadModule php5_module modules/libphp5.so

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

Change it to the following: (will involve Comment out 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 programming related content, please pay attention to the php Chinese websiteProgramming TutorialColumn!

The above is the detailed content of How to upgrade 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