PHP5 Coexistence PHP7

Source: Internet
Author: User

Tags: adb product system Redis mcrypt CGI error resolution Tips

PHP7 and PHP5 coexist in CentOS7

Original reference

Principle

The idea is simple: PHP5 is installed through Yum in/usr/, sockets in/VAR/RUN/PHP-FPM.SOCKET,PHP7 themselves compiled in/USR/LOCAL/PHP7, sockets in/var/run/ PHP7-FPM.SOCKET,NIGNX Specifies fastcgi_pass according to the environment in which the application needs to run.
or two different ports, one using the default 9000, one using 9002

Compiling and installing PHP7

Yum installs various dependency packages required for compilation

    yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel -y

Then to the official website to download the latest PHP source code, unzip

    cd ~    wget http://am1.php.net/distributions/php-7.1.8.tar.gz    tar xvf  php-7.1.8.tar.gz    cd php-7.1.8

Then set the compilation parameters, here are a few things to mention:

    1. In order to reduce the subsequent problems due to permissions, it is recommended to use Nginx and php-fpm with the same user and user group (--with-fpm-user=nginx--with-fpm-group=nginx)
    2. To reduce the problems caused by complex network environments such as multiple NICs, turn off IPv6 support (--disable-ipv6) without using the IPv6 network. Choose according to your own situation
    3. Open the MySQL database API extension (--WITH-MYSQLI=MYSQLND--WITH-PDO-MYSQL=MYSQLND)
    4. Open Opcache Extension (--enable-opcache)

Full compilation parameters:

    ./configure--PREFIX=/USR/LOCAL/PHP7--with-config-file-path=/usr/local/php7/etc--with-config-file-scan-d     ir=/usr/local/php7/etc/php.d/--disable-ipv6--enable-fpm--with-fpm-user=nginx--with-fpm-group=nginx --enable-inline-optimization--disable-debug--disable-rpath--enable-shared--enable-soap--with- Libxml-dir--with-xmlrpc--with-openssl--with-mcrypt--with-mhash--with-pcre-regex--with-sqlite      3--with-zlib--enable-bcmath--with-iconv--with-bz2--enable-calendar--with-curl--with-cdb --enable-dom--enable-exif--enable-fileinfo--enable-filter--with-pcre-dir--enable-ftp--w ITH-GD--with-openssl-dir--with-jpeg-dir--with-png-dir--with-zlib-dir--with-freetype-dir--en Able-gd-native-ttf--enable-gd-jis-conv--with-gettext--with-gmp--with-mhash--enable-json--ena Ble-mbstring--ENABLE-mbregex--enable-mbregex-backtrack--WITH-LIBMBFL--with-onig--enable-pdo--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd--with-zlib-dir--with-pdo-sqlite--with-readline--enable-session--enable- Shmop--enable-simplexml--enable-sockets--enable-sysvmsg--enable-sysvsem--enable-sysvshm--en     ABLE-WDDX--with-libxml-dir--with-xsl--enable-zip--enable-mysqlnd-compression-support--with-pear --enable-opcache

After the setup check is passed, the make and make install is loved, and you are interested in doing test before you install.

Ps:make test is time-consuming, but it's almost like make install, and after make test, direct make install quickly

Configure PHP7

    cp php.ini-production /usr/local/php7/etc/php.ini    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

Modify the appropriate configuration file (as required), the following is the configuration time zone

date.timezone ="Asia/Shanghai"

A.CENTOS7 Version Startup file modification

Make install error-free installation begins configuration, first copy the default configuration to the specified location

    cp -R ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/php7-fpm.service
/usr/lib/systemd/system/php7-fpm.service

Modify the corresponding path just fine ... I didn't test it either.

B.CENTOS6 Version Startup file modification

    cp -R ./sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm  # 这样启动的时候名字不会冲突    chmod +x /etc/init.d/php7-fpm

Modify the startup item name VI/ETC/INIT.D/PHP7-FPM

    prefix=/usr/local/php7    exec_prefix=${prefix}        php_fpm_BIN=${exec_prefix}/sbin/php7-fpm    php_fpm_CONF=${prefix}/etc/php7-fpm.conf    php_fpm_PID=${prefix}/var/run/php7-fpm.pid

Add power-on start, build soft Connect

chkconfig --add php7-fpmchkconfig php7-fpm  on  # 这两步根据需要选择ln -s  /usr/local/php7/bin/php  /usr/bin/php

Start PHP7-FPM

Centos7

    systemctl enable php7-fpm.service    systemctl start  php7-fpm.service

Centos6

    sudo /etc/init.d/php7-fpm restart
Compile error handling
# to find a similar error libiconv_open, because the content can not find the PHP7 compile installation encountered undefined reference to ' libiconv_open ' problem resolution system environment Centos6.7make install the time encountered To error: ext/gd/libgd/.libs/gdkanji.o:in function ' Do_convert ':/root/src/php-7.1.3/ext/gd/libgd/gdkanji.c:349: Undefined reference to ' Libiconv_open '/root/src/php-7.1.3/ext/gd/libgd/gdkanji.c:364:undefined reference to ' Libiconv '/root/src/php-7.1.3/ext/gd/libgd/gdkanji.c:380:undefined reference to ' Libiconv_close ' ext/iconv/.libs/ iconv.o:in function ' php_iconv_stream_filter_dtor ':/root/src/php-7.1.3/ext/iconv/iconv.c:2565:undefined reference To ' libiconv_close ' ext/iconv/.libs/iconv.o:in function ' php_iconv_stream_filter_ctor ':/root/src/php-7.1.3/ext/ iconv/iconv.c:2591:undefined reference to ' Libiconv_open ' ext/iconv/.libs/iconv.o:in function ' _php_iconv_strlen ':/ root/src/php-7.1.3/ext/iconv/iconv.c:754:undefined reference to ' Libiconv_open '/root/src/php-7.1.3/ext/iconv/ iconv.c:778:undefined reference to ' Libiconv '/root/src/php-7.1.3/ext/iconv/iconv.c:812:undefineD reference to ' Libiconv_close ' Workaround: Vim Makefile, adding "-liconv": The results are as follows: Extra_libs =-lcrypt-lresolv-lcrypt-lrt-lpng-lz- Lcurl-lz-lrt-lm-ldl-lnsl-lxml2-lz-lm-ldl-lcurl-lxml2-lz-lm-ldl-lxml2-lz-lm-ldl-lcrypt-lxml2-lz-lm-l Dl-lxml2-lz-lm-ldl-lxml2-lz-lm-ldl-lcrypt-liconv make install again
Installing the Extension Module MySQL module

Since PHP starting from 5.x, PHP connection to MySQL regardless of which method is used Mysqlnd driver, and PHP7 has officially removed the MySQL extension, due to the new features, PHP7 for the database host address is localhost and 127.0.0.1, respectively, will use Unix Domain sockets and TCP/IP two different ways to connect to the MySQL service.

With UNIX domain sockets, PHP7 uses the default/tmp/mysql.sock as the socket, but CentOS7 the default MySQL service mariadb socket location is/var/lib/mysql/ Mysql.sock, so that even if all the database connection information is correct, such as "Mysqli::real_connect (): (hy000/2002): No such file or directory" and "error Establishing a database Connection "error message.

However, our company is using--WITH-PDO-MYSQL=MYSQLND so there is no MySQL connection problem, here to meet the classmate a link Php7_mysql expansion module installation

Redis Module

1.git Clone:

git clone  https://github.com/phpredis/phpredis.git

Official website: Https://github.com/phpredis/phpredis

To switch branches:

git checkout -b php7 origin/php7

2. Check the PHP extension

/usr/local/php7/bin/phpize  # 根据个人路径来,如果是php5的扩展模块就不是这个结果了

3. Establish a compilation connection, install

./configure --with-php-config=/usr/local/php7/bin/php-configmakemake testmake install

4. Check the so file

cd /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303  # 这里的家目录不一样,主要是还是最后一级目录名称ls

5. Modify PHP.ini

vi /usr/local/php7/etc/php.ini添加:extension="redis.so"

6. Check the module

php7 -m |grep redis# php -m是检查扩展模块的

If there is a redis, it means normal.

7. Restart PHP-FPM

sudo /etc/init.d/php7-fpm restart
Nginx Configuration

The corresponding PHP boot different ports, or socket mode,

# fastcgi_pass  unix:/var/run/php7-fpm.socket;fastcgi_pass fastcgi_pass   127.0.0.1:9002;

PHP5 Coexistence PHP7

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.